diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 816f93d..a50e2c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php_version: [8.1, 8.2, 8.3, 8.4] + php_version: [8.3, 8.4, 8.5] composer_flags: ['', '--prefer-lowest'] steps: diff --git a/composer.json b/composer.json index 6e44d49..f887aa4 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,9 @@ "description": "A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code", "license": "MIT", "require": { - "php": ">=8.1", + "php": ">=8.3", "php-di/php-di": "^7.1.1", - "rareloop/router": "^6.0.3", + "rareloop/router": "^6.1.0", "psr/container": "^2.0.2", "psr/http-message": "^2", "psr/http-server-middleware": "^1.0.2", @@ -13,9 +13,9 @@ "monolog/monolog": "^3.9", "illuminate/collections": "^10.49", "statamic/stringy": "^3.1.3", - "laminas/laminas-diactoros": "^3.6.0", + "laminas/laminas-diactoros": "^3.8.0", "rareloop/psr7-server-request-extension": "^2.2.0", - "spatie/macroable": "^1.0.1", + "spatie/macroable": "^2.1.0", "mindplay/middleman": "^4.0.4", "psr/log": "^2.0.0", "symfony/var-dumper": "^6.4.26", diff --git a/phpunit.xml b/phpunit.xml index 62992c9..7157380 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,13 @@ - - - - tests - - - - - src/ - - + + + + src/ + + + + + tests + + diff --git a/src/Application.php b/src/Application.php index 599f9fd..901bf41 100644 --- a/src/Application.php +++ b/src/Application.php @@ -180,10 +180,10 @@ public function register($provider) public function getProvider($provider) { - $providerClass = is_string($provider) ? $provider : get_class($provider); + $providerClass = is_string($provider) ? $provider : $provider::class; return (new Collection($this->loadedProviders))->first(function ($provider) use ($providerClass) { - return get_class($provider) === $providerClass; + return $provider::class === $providerClass; }); } diff --git a/src/Dcrypt/Hash.php b/src/Dcrypt/Hash.php index 1177d46..6c97799 100644 --- a/src/Dcrypt/Hash.php +++ b/src/Dcrypt/Hash.php @@ -70,7 +70,7 @@ private static function build(string $input, string $password, int $cost, ?strin */ private static function cost(int $cost): int { - return $cost % \pow(2, 32); + return $cost % 2 ** 32; } /** diff --git a/src/Dcrypt/OpensslBridge.php b/src/Dcrypt/OpensslBridge.php index ebe329b..ff76727 100644 --- a/src/Dcrypt/OpensslBridge.php +++ b/src/Dcrypt/OpensslBridge.php @@ -162,11 +162,7 @@ private static function mode(): string $cipher = \strtolower(static::CIPHER); - if (isset($legacy[$cipher])) { - return $legacy[$cipher]; - } - - return $cipher; + return $legacy[$cipher] ?? $cipher; } /** diff --git a/src/Dcrypt/Spritz.php b/src/Dcrypt/Spritz.php index 78d6726..983cd19 100644 --- a/src/Dcrypt/Spritz.php +++ b/src/Dcrypt/Spritz.php @@ -36,6 +36,7 @@ class Spritz extends Rc4 * @param string $key Key to use for encryption * @return string */ + #[\Override] public static function crypt(string $str, string $key): string { $s = self::initializeState($key); diff --git a/src/Encrypter.php b/src/Encrypter.php index 034da2a..4f063a8 100644 --- a/src/Encrypter.php +++ b/src/Encrypter.php @@ -7,11 +7,8 @@ class Encrypter implements EncrypterContract { - protected $key; - - public function __construct($key) + public function __construct(protected $key) { - $this->key = $key; } public function encrypt($data) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index cc5409b..99c794e 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -53,6 +53,6 @@ public function render(ServerRequestInterface $request, Exception $e): ResponseI protected function shouldNotReport(Exception $e) { - return in_array(get_class($e), $this->dontReport); + return in_array($e::class, $this->dontReport); } } diff --git a/src/Http/Lumberjack.php b/src/Http/Lumberjack.php index df31f57..46e1ae6 100644 --- a/src/Http/Lumberjack.php +++ b/src/Http/Lumberjack.php @@ -13,8 +13,6 @@ class Lumberjack { - private $app; - protected $bootstrappers = [ LoadConfiguration::class, RegisterExceptionHandler::class, @@ -25,9 +23,8 @@ class Lumberjack RegisterRequestHandler::class, ]; - public function __construct(Application $app) + public function __construct(private Application $app) { - $this->app = $app; } public function bootstrap() diff --git a/src/Http/Router.php b/src/Http/Router.php index 7753b07..2a6ce6e 100644 --- a/src/Http/Router.php +++ b/src/Http/Router.php @@ -17,6 +17,7 @@ class Router extends RareRouter * @param callable|string $callback * @return \Rareloop\Router\Route */ + #[\Override] public function map(array $verbs, string $uri, $callback): Route { if ($this->isControllerString($callback)) { @@ -34,7 +35,7 @@ public function map(array $verbs, string $uri, $callback): Route */ private function isControllerString($callback) : bool { - return is_string($callback) && strpos($callback, '@') !== false; + return is_string($callback) && str_contains($callback, '@'); } /** diff --git a/src/Page.php b/src/Page.php index 8398eea..edaee2b 100644 --- a/src/Page.php +++ b/src/Page.php @@ -11,6 +11,7 @@ class Page extends Post * * @return string */ + #[\Override] public static function getPostType() { return 'page'; diff --git a/src/Post.php b/src/Post.php index be2d3ad..376699b 100644 --- a/src/Post.php +++ b/src/Post.php @@ -26,6 +26,7 @@ public function __construct(mixed $wpPost = null, $preventTimberInit = false) } } + #[\Override] public function __call($name, $arguments) { if (static::hasMacro($name)) { @@ -46,7 +47,7 @@ public static function __callStatic($name, $arguments) return call_user_func_array([$builder, $name], $arguments); } - trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR); + trigger_error('Call to undefined method ' . self::class . '::' . $name . '()', E_USER_ERROR); } /** diff --git a/src/Providers/SessionServiceProvider.php b/src/Providers/SessionServiceProvider.php index 8ca5715..2bedef1 100644 --- a/src/Providers/SessionServiceProvider.php +++ b/src/Providers/SessionServiceProvider.php @@ -44,11 +44,13 @@ public function boot() setcookie( $this->session->getName(), $this->session->getId(), - time() + ($cookieOptions['lifetime'] * 60), - $cookieOptions['path'], - $cookieOptions['domain'], - $cookieOptions['secure'], - $cookieOptions['httpOnly'] + [ + 'expires' => time() + ($cookieOptions['lifetime'] * 60), + 'path' => $cookieOptions['path'], + 'domain' => $cookieOptions['domain'], + 'secure' => $cookieOptions['secure'], + 'httponly' => $cookieOptions['httpOnly'] + ] ); $cookieSet = true; diff --git a/src/ScopedQueryBuilder.php b/src/ScopedQueryBuilder.php index f6089c1..75a119c 100644 --- a/src/ScopedQueryBuilder.php +++ b/src/ScopedQueryBuilder.php @@ -12,14 +12,10 @@ class ScopedQueryBuilder { - protected $postClass; - protected $queryBuilder; - public function __construct($postClass) + public function __construct(protected $postClass) { - $this->postClass = $postClass; - $this->queryBuilder = Helpers::app(QueryBuilderContract::class); $this->queryBuilder diff --git a/src/Session/EncryptedStore.php b/src/Session/EncryptedStore.php index d6388f0..07057a3 100644 --- a/src/Session/EncryptedStore.php +++ b/src/Session/EncryptedStore.php @@ -25,11 +25,13 @@ public function __construct( parent::__construct($name, $handler, $id); } + #[\Override] protected function prepareForStorage($data) { return $this->encrypter->encrypt($data); } + #[\Override] protected function prepareForUnserialize($data) { if ($data === '') { diff --git a/src/Session/FileSessionHandler.php b/src/Session/FileSessionHandler.php index 56f3b5e..9efa24b 100644 --- a/src/Session/FileSessionHandler.php +++ b/src/Session/FileSessionHandler.php @@ -8,13 +8,8 @@ class FileSessionHandler implements SessionHandlerInterface { - protected $path; - protected $prefix; - - public function __construct($path, $prefix = 'lumberjack_session_') + public function __construct(protected $path, protected $prefix = 'lumberjack_session_') { - $this->path = $path; - $this->prefix = $prefix; } #[\ReturnTypeWillChange] diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index cc5f13c..7175ed5 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -552,21 +552,15 @@ public function calling_detectWhenRequestHasNotBeenHandled_adds_actions() class BootstrapperBootstrapTester { - public $callback; - - public function __construct($callback) + public function __construct(public $callback) { - $this->callback = $callback; } } abstract class TestBootstrapperBase { - private BootstrapperBootstrapTester $tester; - - public function __construct(BootstrapperBootstrapTester $tester) + public function __construct(private BootstrapperBootstrapTester $tester) { - $this->tester = $tester; } public function bootstrap(Application $app) @@ -654,13 +648,9 @@ public function __construct(TestInterface $test) class RequiresAdditionalConstructorParams { public $param; - public $param1; - public $param2; - public function __construct(TestInterface $test, $param1, $param2) + public function __construct(TestInterface $test, public $param1, public $param2) { $this->param = $test; - $this->param1 = $param1; - $this->param2 = $param2; } } diff --git a/tests/Unit/Dcrypt/HashTest.php b/tests/Unit/Dcrypt/HashTest.php index 3e1ba86..ad703fb 100644 --- a/tests/Unit/Dcrypt/HashTest.php +++ b/tests/Unit/Dcrypt/HashTest.php @@ -41,8 +41,8 @@ public function testHmacAlgoFailure() public function testFail() { - $input = str_repeat('A', rand(0, 10000)); - $key = str_repeat('A', rand(10, 100)); + $input = str_repeat('A', random_int(0, 10000)); + $key = str_repeat('A', random_int(10, 100)); $cost = 1; $output = Hash::make($input, $key, $cost); diff --git a/tests/Unit/Dcrypt/StrTest.php b/tests/Unit/Dcrypt/StrTest.php index 19022e0..ff331c2 100644 --- a/tests/Unit/Dcrypt/StrTest.php +++ b/tests/Unit/Dcrypt/StrTest.php @@ -9,11 +9,11 @@ class StrTest extends \PHPUnit\Framework\TestCase public function testEquals() { // Test with hash_equals - $this->assertTrue(Str::equal('2222', '2222', true)); - $this->assertFalse(Str::equal('2222', '3333', true)); + $this->assertTrue(Str::equal('2222', '2222')); + $this->assertFalse(Str::equal('2222', '3333')); // Test without hash_equals - $this->assertTrue(Str::equal('2222', '2222', false)); - $this->assertFalse(Str::equal('2222', '3333', false)); + $this->assertTrue(Str::equal('2222', '2222')); + $this->assertFalse(Str::equal('2222', '3333')); } } diff --git a/tests/Unit/Dcrypt/TestSupport.php b/tests/Unit/Dcrypt/TestSupport.php index dcf1c8f..b8198b2 100644 --- a/tests/Unit/Dcrypt/TestSupport.php +++ b/tests/Unit/Dcrypt/TestSupport.php @@ -16,7 +16,7 @@ public static function swaprandbyte($inp) // @codeCoverageIgnoreStart $len = strlen($inp); $inp = str_split($inp); - $off = rand(0, $len - 1); + $off = random_int(0, $len - 1); $byte = $inp[$off]; $rbyte = \random_bytes(1); if ($byte === $rbyte) { diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.php index 870ee98..7e39d1e 100644 --- a/tests/Unit/HelpersTest.php +++ b/tests/Unit/HelpersTest.php @@ -375,12 +375,7 @@ class TestExceptionHandler extends Handler class RequiresConstructorParams { - public $param1; - public $param2; - - public function __construct($param1, $param2) + public function __construct(public $param1, public $param2) { - $this->param1 = $param1; - $this->param2 = $param2; } } diff --git a/tests/Unit/Http/MiddlewareAliasStoreTest.php b/tests/Unit/Http/MiddlewareAliasStoreTest.php index 6d97f28..7c94946 100644 --- a/tests/Unit/Http/MiddlewareAliasStoreTest.php +++ b/tests/Unit/Http/MiddlewareAliasStoreTest.php @@ -108,12 +108,7 @@ class MASTestClass class MASTestClassWithConstructorParams { - public $param1; - public $param2; - - public function __construct($param1, $param2) + public function __construct(public $param1, public $param2) { - $this->param1 = $param1; - $this->param2 = $param2; } } diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 7ea2c3d..46b9fe8 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -83,6 +83,7 @@ public static function setCreateBuilderResponse($builder) static::$injectedBuilder = $builder; } + #[\Override] public static function builder(): ScopedQueryBuilder { return static::$injectedBuilder; diff --git a/tests/Unit/PostTest.php b/tests/Unit/PostTest.php index c50eaf5..e1fbc5c 100644 --- a/tests/Unit/PostTest.php +++ b/tests/Unit/PostTest.php @@ -19,6 +19,7 @@ */ class PostTest extends TestCase { + public $dummyData; use BrainMonkeyPHPUnitIntegration; /** @test */ @@ -239,6 +240,7 @@ class PostWithPrivateData extends Post class RegisterablePostType extends Post { + #[\Override] public static function getPostType(): string { return 'registerable_post_type'; @@ -289,6 +291,7 @@ protected static function getPostTypeConfig(): array class UnregisterablePostTypeWithoutConfig extends Post { + #[\Override] public static function getPostType(): string { return 'post_type'; diff --git a/tests/Unit/Providers/CustomPostTypesServiceProviderTest.php b/tests/Unit/Providers/CustomPostTypesServiceProviderTest.php index ae58e05..ac2aa05 100644 --- a/tests/Unit/Providers/CustomPostTypesServiceProviderTest.php +++ b/tests/Unit/Providers/CustomPostTypesServiceProviderTest.php @@ -37,6 +37,7 @@ public function should_call_register_post_type_for_each_configured_post_type() class CustomPost1 extends Post { + #[\Override] public static function getPostType() { return 'custom_post_1'; @@ -52,6 +53,7 @@ protected static function getPostTypeConfig() class CustomPost2 extends Post { + #[\Override] public static function getPostType() { return 'custom_post_1'; diff --git a/tests/Unit/Providers/RouterServiceProviderTest.php b/tests/Unit/Providers/RouterServiceProviderTest.php index 5f7b813..25d4203 100644 --- a/tests/Unit/Providers/RouterServiceProviderTest.php +++ b/tests/Unit/Providers/RouterServiceProviderTest.php @@ -286,13 +286,8 @@ private function setSiteUrl($url) class RSPAddHeaderMiddleware implements MiddlewareInterface { - private $key; - private $value; - - public function __construct($key, $value) + public function __construct(private $key, private $value) { - $this->key = $key; - $this->value = $value; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/tests/Unit/Providers/WordPressControllersServiceProviderTest.php b/tests/Unit/Providers/WordPressControllersServiceProviderTest.php index 713c84d..d3e89c9 100644 --- a/tests/Unit/Providers/WordPressControllersServiceProviderTest.php +++ b/tests/Unit/Providers/WordPressControllersServiceProviderTest.php @@ -195,7 +195,7 @@ public function handle_request_returns_response_when_controller_does_exist() $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestController::class, 'handle'); @@ -212,7 +212,7 @@ public function handle_request_returns_response_when_controller_returns_a_respon $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerReturningAResponsable::class, 'handle'); @@ -230,7 +230,7 @@ public function handle_request_resolves_constructor_params_from_container() $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithConstructorParams::class, 'handle'); @@ -247,7 +247,7 @@ public function handle_request_resolves_controller_method_params_from_container( $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithHandleParams::class, 'handle'); @@ -267,7 +267,7 @@ public function handle_request_supports_middleware() $app->bind(TestControllerWithMiddleware::class, $controller); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithMiddleware::class, 'handle'); @@ -288,7 +288,7 @@ public function handle_request_adds_password_protect_middleware() $app->bind(TestControllerWithMiddleware::class, $controller); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithMiddleware::class, 'handle'); @@ -308,7 +308,7 @@ public function handle_request_supports_middleware_applied_to_a_specific_method_ $app->bind(TestControllerWithMiddleware::class, $controller); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithMiddleware::class, 'handle'); @@ -328,7 +328,7 @@ public function handle_request_supports_middleware_applied_to_a_specific_method_ $app->bind(TestControllerWithMiddleware::class, $controller); $provider = new WordPressControllersServiceProvider($app); - $provider->boot($app); + $provider->boot(); $response = $provider->handleRequest(new ServerRequest, TestControllerWithMiddleware::class, 'handle'); @@ -358,7 +358,7 @@ public function handle_request_supports_middleware_aliases() $provider = new WordPressControllersServiceProvider($app); $routerProvider->register(); $routerProvider->boot(); - $provider->boot($app); + $provider->boot(); $store = $app->get(MiddlewareAliases::class); $store->set('middleware-key', new AddHeaderMiddleware('X-Header', 'testing123')); @@ -447,13 +447,8 @@ public function handle() class AddHeaderMiddleware implements MiddlewareInterface { - private $key; - private $value; - - public function __construct($key, $value) + public function __construct(private $key, private $value) { - $this->key = $key; - $this->value = $value; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/tests/Unit/QueryBuilderTest.php b/tests/Unit/QueryBuilderTest.php index 20a1426..a1c3a74 100644 --- a/tests/Unit/QueryBuilderTest.php +++ b/tests/Unit/QueryBuilderTest.php @@ -14,6 +14,10 @@ class QueryBuilderTest extends TestCase { + /** + * @var array + */ + public $params; use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration, \DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; @@ -514,6 +518,10 @@ public function can_extend_querybuilder_behaviour_with_mixin() class QueryBuilderMixin { + /** + * @var array + */ + public $params; function testFunctionAddedByMixin() { return function () { @@ -526,6 +534,7 @@ function testFunctionAddedByMixin() class PostWithCustomPostType extends Post { + #[\Override] public static function getPostType() { return 'post_with_query_scope'; diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 592e8da..c0bf9a4 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -16,6 +16,10 @@ class ScopedQueryBuilderTest extends TestCase { + /** + * @var array + */ + public $params; use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration, \DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; @@ -160,6 +164,7 @@ public function nonStandardMethod() class PostWithQueryScope extends Post { + #[\Override] public static function getPostType() { return 'post_with_query_scope'; diff --git a/tests/Unit/Session/FileSessionHandlerTest.php b/tests/Unit/Session/FileSessionHandlerTest.php index c2801e9..2a6ac05 100644 --- a/tests/Unit/Session/FileSessionHandlerTest.php +++ b/tests/Unit/Session/FileSessionHandlerTest.php @@ -32,7 +32,7 @@ public function close_returns_true() { $handler = new FileSessionHandler(vfsStream::url('exampleDir')); - $this->assertTrue($handler->close('save-path', 'session-name')); + $this->assertTrue($handler->close()); } /** @test */ diff --git a/tests/Unit/Session/SessionManagerTest.php b/tests/Unit/Session/SessionManagerTest.php index f1e34aa..67db3e1 100644 --- a/tests/Unit/Session/SessionManagerTest.php +++ b/tests/Unit/Session/SessionManagerTest.php @@ -18,6 +18,10 @@ use Rareloop\Lumberjack\Test\Unit\Session\NullSessionHandler; use Rareloop\Lumberjack\Contracts\Encrypter as EncrypterContract; +/** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ class SessionManagerTest extends TestCase { use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; @@ -109,7 +113,6 @@ public function can_create_an_encrypted_store() $reflection = new ReflectionClass($driver); $property = $reflection->getProperty('exceptionHandler'); - $property->setAccessible(true); $this->assertInstanceOf(HandlerInterface::class, $property->getValue($driver)); }