Skip to content

Commit

Permalink
Add PHP 8.1 support (#41)
Browse files Browse the repository at this point in the history
* Add return type annotations

Tells PHP 8.1 not to raise the deprecation warning around mixed return types without breaking backwards compatibility with PHP 8.0 and below.

https://stackoverflow.com/a/71133750

* Specify the error level

`null` is no longer accepted in PHP 8.1

* Update dependencies for PHP 8.1 support

* Update CI PHP versions

Drop support for PHP 7.3 and add support for PHP 8.1

* Allow `composer/installers` to be installed

* Update minimum dependencies

* Update more minimum dev dependencies

* Increase minimum version of `statamic/stringy`

* Increase Timber version to release supporting 8.1

* Migrate `tightenco/collect` to `illuminate/collections` (#40)

* Ensure `dd()` and `dump()` are present

* Ensure Collections are present

1. Can use Tightenco namespace
2. Can use Illuminate namespace
3. Can use `collect()` helper

* Update to `illuminate/collections`

* Test legacy function signatures are happy

* Use a version of 8.x which supports PHP 8.1

Co-authored-by: Joe Lambert <joe@rareloop.com>

* Default the domain to ‘’ for PHP 8.1 support

This is the recommended approach to support PHP 8.1 and maintain backwards compatibility. It is also how WordPress have approached this.

* Allow custom error levels to be report only (#44)

Also added `E_DEPRECATED` to the list by default

Co-authored-by: Joe Lambert <joe@rareloop.com>

* Remove collection aliasing

---------

Co-authored-by: Joe Lambert <joe@rareloop.com>
  • Loading branch information
joelambert and Joe Lambert committed Apr 5, 2023
1 parent f0f074a commit 1f2c845
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [7.3, 7.4, 8.0]
php_version: [7.4, 8.0, 8.1]
composer_flags: ['', '--prefer-lowest']

steps:
Expand Down
30 changes: 18 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@
"license": "MIT",
"require": {
"php": ">=7.3||>=8.0",
"php-di/php-di": "^6.3.5",
"rareloop/router": "^6.0.1",
"php-di/php-di": "^6.4.0",
"rareloop/router": "^6.0.2",
"psr/container": "^1.0",
"psr/http-message": "^1.0",
"psr/http-server-middleware": "^1.0",
"blast/facades": "^1.0",
"timber/timber": "^1.19",
"timber/timber": "^1.21.0",
"monolog/monolog": "^2.0",
"http-interop/response-sender": "^1.0",
"symfony/debug": "^4.1",
"tightenco/collect": "^5.6.0",
"statamic/stringy": "~3.1.0",
"illuminate/collections": "^8.53.1||^9.0.0",
"statamic/stringy": "^3.1.3",
"laminas/laminas-diactoros": "^2.4",
"rareloop/psr7-server-request-extension": "^2.1.0",
"mmeyer2k/dcrypt": "^8.0.1",
"spatie/macroable": "^1.0",
"mindplay/middleman": "^3.0.3",
"psr/log": "^1.1",
"laminas/laminas-zendframework-bridge": "^1.4"
"laminas/laminas-zendframework-bridge": "^1.4",
"symfony/var-dumper": "^5.0||^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^9.5.21",
"php-coveralls/php-coveralls": "^2.0",
"mockery/mockery": "^1.4.4",
"brain/monkey": "~2.4.0",
"mockery/mockery": "^1.5.0",
"brain/monkey": "~2.4.2",
"squizlabs/php_codesniffer": "^3.6.0",
"php-mock/php-mock": "^2.0",
"mikey179/vfsstream": "1.6.9",
"antecedent/patchwork": "^2.1.8",
"php-mock/php-mock": "^2.3.1",
"mikey179/vfsstream": "1.6.11",
"antecedent/patchwork": "^2.1.21",
"dms/phpunit-arraysubset-asserts": "^0.3.0"
},
"autoload": {
Expand All @@ -44,5 +45,10 @@
"psr-4": {
"Rareloop\\Lumberjack\\Test\\": "tests"
}
},
"config": {
"allow-plugins": {
"composer/installers": true
}
}
}
14 changes: 10 additions & 4 deletions src/Bootstrappers/RegisterExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function bootstrap(Application $app)
public function handleException($e)
{
if ($e instanceof Error) {
$e = new ErrorException($e->getMessage(), 0, null, $e->getFile(), $e->getLine());
$e = new ErrorException($e->getMessage(), 0, E_ERROR, $e->getFile(), $e->getLine());
}

$handler = $this->getExceptionHandler();
Expand Down Expand Up @@ -73,7 +73,7 @@ public function send(ResponseInterface $response)
@send($response);
}

protected function getExceptionHandler() : HandlerInterface
protected function getExceptionHandler(): HandlerInterface
{
return $this->app->get(HandlerInterface::class);
}
Expand All @@ -94,7 +94,13 @@ public function handleError($level, $message, $file = '', $line = 0, $context =
{
$exception = new ErrorException($message, 0, $level, $file, $line);

if ($level === E_USER_NOTICE || $level === E_USER_DEPRECATED) {
$errorsToReportOnly = $this->app->get('config')->get('app.errors.reportOnly') ?: [
E_USER_NOTICE,
E_USER_DEPRECATED,
E_DEPRECATED
];

if (in_array($level, $errorsToReportOnly)) {
$this->getExceptionHandler()->report($exception);
return;
}
Expand All @@ -106,7 +112,7 @@ public function handleError($level, $message, $file = '', $line = 0, $context =

public function handleShutdown()
{
if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/Contracts/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

namespace Rareloop\Lumberjack\Contracts;

use Tightenco\Collect\Support\Collection;
use Illuminate\Support\Collection;

interface QueryBuilder
{
public function getParameters() : array;
public function getParameters(): array;

public function wherePostType($postType) : QueryBuilder;
public function wherePostType($postType): QueryBuilder;

public function limit($limit) : QueryBuilder;
public function limit($limit): QueryBuilder;

public function offset($offset) : QueryBuilder;
public function offset($offset): QueryBuilder;

public function orderBy($orderBy, string $order = QueryBuilder::ASC) : QueryBuilder;
public function orderBy($orderBy, string $order = QueryBuilder::ASC): QueryBuilder;

public function orderByMeta($metaKey, string $order = QueryBuilder::ASC, string $type = null) : QueryBuilder;
public function orderByMeta($metaKey, string $order = QueryBuilder::ASC, string $type = null): QueryBuilder;

public function whereIdIn(array $ids) : QueryBuilder;
public function whereIdIn(array $ids): QueryBuilder;

public function whereIdNotIn(array $ids) : QueryBuilder;
public function whereIdNotIn(array $ids): QueryBuilder;

public function whereStatus() : QueryBuilder;
public function whereStatus(): QueryBuilder;

public function whereMeta($key, $value, $compare = '=', $type = null) : QueryBuilder;
public function whereMeta($key, $value, $compare = '=', $type = null): QueryBuilder;

public function whereMetaRelationshipIs(string $relation) : QueryBuilder;
public function whereMetaRelationshipIs(string $relation): QueryBuilder;

public function get() : Collection;
public function get(): Collection;

public function clone() : QueryBuilder;
public function clone(): QueryBuilder;
}
2 changes: 1 addition & 1 deletion src/Providers/SessionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function boot()
$cookieOptions = [
'lifetime' => Config::get('session.lifetime', 120),
'path' => Config::get('session.path', '/'),
'domain' => Config::get('session.domain', null),
'domain' => Config::get('session.domain', null) ?: '',
'secure' => Config::get('session.secure', false),
'httpOnly' => Config::get('session.http_only', true),
];
Expand Down
10 changes: 5 additions & 5 deletions src/Providers/WordPressControllersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Rareloop\Lumberjack\Providers;

use Psr\Http\Message\RequestInterface;
use Stringy\Stringy;
use Rareloop\Router\Invoker;
use Rareloop\Router\ProvidesControllerMiddleware;
use Illuminate\Support\Collection;
use mindplay\middleman\Dispatcher;
use Rareloop\Router\ResponseFactory;
use Stringy\Stringy;
use Tightenco\Collect\Support\Collection;
use Psr\Http\Message\RequestInterface;
use Zend\Diactoros\ServerRequestFactory;
use mindplay\middleman\Dispatcher;
use Rareloop\Router\ProvidesControllerMiddleware;

class WordPressControllersServiceProvider extends ServiceProvider
{
Expand Down
38 changes: 19 additions & 19 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Rareloop\Lumberjack;

use Rareloop\Lumberjack\Contracts\QueryBuilder as QueryBuilderContract;
use Rareloop\Lumberjack\Exceptions\InvalidMetaRelationshipException;
use Timber\Timber;
use Rareloop\Lumberjack\Post;
use Spatie\Macroable\Macroable;
use Tightenco\Collect\Support\Collection;
use Timber\Timber;
use Illuminate\Support\Collection;
use Rareloop\Lumberjack\Exceptions\InvalidMetaRelationshipException;
use Rareloop\Lumberjack\Contracts\QueryBuilder as QueryBuilderContract;

class QueryBuilder implements QueryBuilderContract
{
Expand Down Expand Up @@ -46,33 +46,33 @@ class QueryBuilder implements QueryBuilderContract
const OR = 'OR';
const AND = 'AND';

public function getParameters() : array
public function getParameters(): array
{
return $this->params;
}

public function wherePostType($postType) : QueryBuilderContract
public function wherePostType($postType): QueryBuilderContract
{
$this->params['post_type'] = $postType;

return $this;
}

public function limit($limit) : QueryBuilderContract
public function limit($limit): QueryBuilderContract
{
$this->params['posts_per_page'] = $limit;

return $this;
}

public function offset($offset) : QueryBuilderContract
public function offset($offset): QueryBuilderContract
{
$this->params['offset'] = $offset;

return $this;
}

public function orderBy($orderBy, string $order = QueryBuilder::ASC) : QueryBuilderContract
public function orderBy($orderBy, string $order = QueryBuilder::ASC): QueryBuilderContract
{
$order = strtoupper($order);

Expand All @@ -82,7 +82,7 @@ public function orderBy($orderBy, string $order = QueryBuilder::ASC) : QueryBuil
return $this;
}

public function orderByMeta($metaKey, string $order = QueryBuilder::ASC, string $type = null) : QueryBuilderContract
public function orderByMeta($metaKey, string $order = QueryBuilder::ASC, string $type = null): QueryBuilderContract
{
$order = strtoupper($order);

Expand All @@ -93,21 +93,21 @@ public function orderByMeta($metaKey, string $order = QueryBuilder::ASC, string
return $this;
}

public function whereIdIn(array $ids) : QueryBuilderContract
public function whereIdIn(array $ids): QueryBuilderContract
{
$this->params['post__in'] = $ids;

return $this;
}

public function whereIdNotIn(array $ids) : QueryBuilderContract
public function whereIdNotIn(array $ids): QueryBuilderContract
{
$this->params['post__not_in'] = $ids;

return $this;
}

public function whereStatus() : QueryBuilderContract
public function whereStatus(): QueryBuilderContract
{
$args = func_get_args();

Expand All @@ -125,7 +125,7 @@ protected function initialiseMetaQuery()
$this->params['meta_query'] = $this->params['meta_query'] ?? [];
}

public function whereMeta($key, $value, $compare = '=', $type = null) : QueryBuilderContract
public function whereMeta($key, $value, $compare = '=', $type = null): QueryBuilderContract
{
$meta = [
'key' => $key,
Expand All @@ -143,7 +143,7 @@ public function whereMeta($key, $value, $compare = '=', $type = null) : QueryBui
return $this;
}

public function whereMetaRelationshipIs(string $relation) : QueryBuilderContract
public function whereMetaRelationshipIs(string $relation): QueryBuilderContract
{
$relation = strtoupper($relation);

Expand All @@ -159,14 +159,14 @@ public function whereMetaRelationshipIs(string $relation) : QueryBuilderContract
return $this;
}

public function as($postClass) : QueryBuilderContract
public function as($postClass): QueryBuilderContract
{
$this->postClass = $postClass;

return $this;
}

public function get() : Collection
public function get(): Collection
{
$posts = Timber::get_posts($this->getParameters(), $this->postClass);

Expand All @@ -182,7 +182,7 @@ public function get() : Collection
*
* @return \Rareloop\Lumberjack\Post|null
*/
public function first() : ?Post
public function first(): ?Post
{
$params = array_merge($this->getParameters(), [
'limit' => 1,
Expand All @@ -197,7 +197,7 @@ public function first() : ?Post
return collect($posts)->first();
}

public function clone() : QueryBuilderContract
public function clone(): QueryBuilderContract
{
$clone = clone $this;

Expand Down
11 changes: 6 additions & 5 deletions src/Session/FileSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ public function __construct($path, $prefix = 'lumberjack_session_')
$this->prefix = $prefix;
}


#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
return true;
}


#[\ReturnTypeWillChange]
public function close()
{
return true;
}

#[\ReturnTypeWillChange]
public function read($sessionId)
{
$filepath = $this->getFilepath($sessionId);
Expand All @@ -40,7 +41,7 @@ public function read($sessionId)
return '';
}


#[\ReturnTypeWillChange]
public function write($sessionId, $data)
{
try {
Expand All @@ -52,7 +53,7 @@ public function write($sessionId, $data)
return true;
}


#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
$filepath = $this->getFilepath($sessionId);
Expand All @@ -64,7 +65,7 @@ public function destroy($sessionId)
return true;
}


#[\ReturnTypeWillChange]
public function gc($lifetime)
{
foreach (glob($this->path . '/' . $this->prefix . '*') as $file) {
Expand Down

0 comments on commit 1f2c845

Please sign in to comment.