diff --git a/rector.php b/rector.php index 531e2f46e..0ae2a35e2 100644 --- a/rector.php +++ b/rector.php @@ -94,5 +94,5 @@ // cache '*/runtime/cache/*', ]) - ->withPhpSets(php74: true) + ->withPhpSets(php80: true) ->withPreparedSets(deadCode: true); diff --git a/src/AuthHttp/tests/Diactoros/ResponseFactory.php b/src/AuthHttp/tests/Diactoros/ResponseFactory.php index f4f1ae603..5bbe30d55 100644 --- a/src/AuthHttp/tests/Diactoros/ResponseFactory.php +++ b/src/AuthHttp/tests/Diactoros/ResponseFactory.php @@ -11,12 +11,8 @@ final class ResponseFactory implements ResponseFactoryInterface { - /** @var HttpConfig */ - protected $config; - - public function __construct(HttpConfig $config) + public function __construct(protected HttpConfig $config) { - $this->config = $config; } diff --git a/src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php b/src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php index efc22c800..4099a25f9 100644 --- a/src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php +++ b/src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php @@ -35,7 +35,7 @@ public function testAttributeRead(): void $http->setHandler( static function (ServerRequestInterface $request, ResponseInterface $response): void { $response->getBody()->write( - get_class($request->getAttribute('authContext')) + $request->getAttribute('authContext')::class ); } ); diff --git a/src/Boot/src/helpers.php b/src/Boot/src/helpers.php index 71b1aee49..d0157ebdd 100644 --- a/src/Boot/src/helpers.php +++ b/src/Boot/src/helpers.php @@ -54,10 +54,9 @@ function directory(string $alias): string * Gets the value of an environment variable. Uses application core from the current global scope. * * @param non-empty-string $key - * @param mixed $default * @return mixed */ - function env(string $key, $default = null) + function env(string $key, mixed $default = null) { return spiral(EnvironmentInterface::class)->get($key, $default); } diff --git a/src/Config/tests/Value.php b/src/Config/tests/Value.php index 36949ff58..19e3762c7 100644 --- a/src/Config/tests/Value.php +++ b/src/Config/tests/Value.php @@ -6,11 +6,8 @@ class Value { - private $value; - - public function __construct(string $value = 'value!') + public function __construct(private string $value = 'value!') { - $this->value = $value; } public function getValue() diff --git a/src/Console/tests/ShortException.php b/src/Console/tests/ShortException.php index c751d2f51..38632afc2 100644 --- a/src/Console/tests/ShortException.php +++ b/src/Console/tests/ShortException.php @@ -6,7 +6,7 @@ class ShortException extends \Exception { - public function __toString() + public function __toString(): string { return 'exception'; } diff --git a/src/Cookies/tests/TestResponseFactory.php b/src/Cookies/tests/TestResponseFactory.php index ed4844669..da1a2ae93 100644 --- a/src/Cookies/tests/TestResponseFactory.php +++ b/src/Cookies/tests/TestResponseFactory.php @@ -11,12 +11,8 @@ final class TestResponseFactory implements ResponseFactoryInterface { - /** @var HttpConfig */ - protected $config; - - public function __construct(HttpConfig $config) + public function __construct(protected HttpConfig $config) { - $this->config = $config; } diff --git a/src/Core/tests/ScopesTest.php b/src/Core/tests/ScopesTest.php index 1f61afaab..66b849177 100644 --- a/src/Core/tests/ScopesTest.php +++ b/src/Core/tests/ScopesTest.php @@ -90,7 +90,7 @@ public function testContainerScopeException(): void ], function () use ($c): void { throw new RuntimeException('exception'); })); - } catch (\Throwable $e) { + } catch (\Throwable) { } $this->assertSame('a', $c->get('bucket')->getName()); diff --git a/src/Csrf/tests/TestResponseFactory.php b/src/Csrf/tests/TestResponseFactory.php index 718dc9ff2..adb9e8466 100644 --- a/src/Csrf/tests/TestResponseFactory.php +++ b/src/Csrf/tests/TestResponseFactory.php @@ -11,11 +11,8 @@ final class TestResponseFactory implements ResponseFactoryInterface { - protected readonly HttpConfig $config; - - public function __construct(HttpConfig $config) + public function __construct(protected readonly HttpConfig $config) { - $this->config = $config; } diff --git a/src/Distribution/src/Manager.php b/src/Distribution/src/Manager.php index 251212740..3ba2b2f10 100644 --- a/src/Distribution/src/Manager.php +++ b/src/Distribution/src/Manager.php @@ -14,11 +14,9 @@ final class Manager implements MutableDistributionInterface * @var array */ private array $resolvers = []; - private string $default; - public function __construct(string $name = self::DEFAULT_RESOLVER) + public function __construct(private string $default = self::DEFAULT_RESOLVER) { - $this->default = $name; } /** diff --git a/src/Distribution/tests/Resolver/StaticResolverTest.php b/src/Distribution/tests/Resolver/StaticResolverTest.php index b9f6eea36..da7948a1b 100644 --- a/src/Distribution/tests/Resolver/StaticResolverTest.php +++ b/src/Distribution/tests/Resolver/StaticResolverTest.php @@ -20,7 +20,7 @@ public function testGuzzleResolve(): void // PHP 8.1 deprecation error fix self::assertTrue( ($error = error_get_last()) === null || - \strpos($error['message'], 'Spiral') === false + !str_contains($error['message'], 'Spiral') ); } @@ -35,7 +35,7 @@ public function testGuzzleResolveWithPrefix(): void // PHP 8.1 deprecation error fix self::assertTrue( ($error = error_get_last()) === null || - \strpos($error['message'], 'Spiral') === false + !str_contains($error['message'], 'Spiral') ); } } diff --git a/src/Http/src/Stream/GeneratorStream.php b/src/Http/src/Stream/GeneratorStream.php index 3334c4e34..a24667e47 100644 --- a/src/Http/src/Stream/GeneratorStream.php +++ b/src/Http/src/Stream/GeneratorStream.php @@ -10,8 +10,6 @@ final class GeneratorStream implements StreamInterface { - private ?Generator $stream; - private bool $readable = true; private ?int $size = null; @@ -20,16 +18,15 @@ final class GeneratorStream implements StreamInterface private bool $started = false; - public function __construct(Generator $body) + public function __construct(private ?Generator $stream) { - $this->stream = $body; } public function __toString(): string { try { return $this->getContents(); - } catch (\Exception $e) { + } catch (\Exception) { return ''; } } diff --git a/src/Http/tests/Diactoros/ResponseFactory.php b/src/Http/tests/Diactoros/ResponseFactory.php index 0ab6dedec..39f64492c 100644 --- a/src/Http/tests/Diactoros/ResponseFactory.php +++ b/src/Http/tests/Diactoros/ResponseFactory.php @@ -11,12 +11,8 @@ final class ResponseFactory implements ResponseFactoryInterface { - /** @var HttpConfig */ - protected $config; - - public function __construct(HttpConfig $config) + public function __construct(protected HttpConfig $config) { - $this->config = $config; } public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface diff --git a/src/Http/tests/Json.php b/src/Http/tests/Json.php index abe53d4fb..f574fa9bd 100644 --- a/src/Http/tests/Json.php +++ b/src/Http/tests/Json.php @@ -6,11 +6,8 @@ class Json implements \JsonSerializable { - private $data; - - public function __construct($data) + public function __construct(private $data) { - $this->data = $data; } #[\ReturnTypeWillChange] diff --git a/src/Http/tests/Streamable.php b/src/Http/tests/Streamable.php index 77e58dbb4..f38cb2338 100644 --- a/src/Http/tests/Streamable.php +++ b/src/Http/tests/Streamable.php @@ -9,11 +9,8 @@ class Streamable implements StreamableInterface { - private $stream; - - public function __construct(StreamInterface $stream) + public function __construct(private StreamInterface $stream) { - $this->stream = $stream; } public function getStream(): StreamInterface diff --git a/src/Models/tests/NameValue.php b/src/Models/tests/NameValue.php index b303e1bc4..be28b2c17 100644 --- a/src/Models/tests/NameValue.php +++ b/src/Models/tests/NameValue.php @@ -6,7 +6,7 @@ use Spiral\Models\ValueInterface; -class NameValue implements ValueInterface +class NameValue implements ValueInterface, \Stringable { private $value; @@ -17,7 +17,7 @@ public function __construct($value) public function __toString(): string { - return $this->value; + return (string) $this->value; } public function setValue(mixed $data): self diff --git a/src/Prototype/tests/Storage.php b/src/Prototype/tests/Storage.php index 8ff1a55a4..70901e07d 100644 --- a/src/Prototype/tests/Storage.php +++ b/src/Prototype/tests/Storage.php @@ -9,12 +9,8 @@ class Storage /** @var array */ protected $storage = []; - /** @var string */ - private $dir; - - public function __construct(string $dir) + public function __construct(private string $dir) { - $this->dir = $dir; } public function store(string $name): void diff --git a/src/Queue/src/Attribute/Queueable.php b/src/Queue/src/Attribute/Queueable.php index 7dd7e3c18..6d5f29bbe 100644 --- a/src/Queue/src/Attribute/Queueable.php +++ b/src/Queue/src/Attribute/Queueable.php @@ -20,10 +20,7 @@ #[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor] final class Queueable { - public ?string $queue = null; - - public function __construct(string $queue = null) + public function __construct(public ?string $queue = null) { - $this->queue = $queue; } } diff --git a/src/Queue/src/Interceptor/Push/Core.php b/src/Queue/src/Interceptor/Push/Core.php index dabab6bfe..23af45582 100644 --- a/src/Queue/src/Interceptor/Push/Core.php +++ b/src/Queue/src/Interceptor/Push/Core.php @@ -72,7 +72,7 @@ private function getTracer(): TracerInterface { try { return ContainerScope::getContainer()->get(TracerInterface::class); - } catch (\Throwable $e) { + } catch (\Throwable) { return new NullTracer(); } } diff --git a/src/Queue/src/JobHandler.php b/src/Queue/src/JobHandler.php index a89bced8a..6540a4f5d 100644 --- a/src/Queue/src/JobHandler.php +++ b/src/Queue/src/JobHandler.php @@ -34,7 +34,7 @@ public function handle(string $name, string $id, mixed $payload, array $headers $this->invoker->invoke([$this, $this->getHandlerMethod()], $params); } catch (\Throwable $e) { - $message = \sprintf('[%s] %s', $this::class, $e->getMessage()); + $message = \sprintf('[%s] %s', static::class, $e->getMessage()); throw new JobException($message, (int)$e->getCode(), $e); } } diff --git a/src/Queue/src/QueueableDetector.php b/src/Queue/src/QueueableDetector.php index 52a3b60ae..a35cc5b32 100644 --- a/src/Queue/src/QueueableDetector.php +++ b/src/Queue/src/QueueableDetector.php @@ -9,11 +9,8 @@ final class QueueableDetector { - private ReaderInterface $reader; - - public function __construct(ReaderInterface $reader) + public function __construct(private ReaderInterface $reader) { - $this->reader = $reader; } /** diff --git a/src/Queue/tests/Job/ObjectJobTest.php b/src/Queue/tests/Job/ObjectJobTest.php index 956d092a5..5dbcc6f6a 100644 --- a/src/Queue/tests/Job/ObjectJobTest.php +++ b/src/Queue/tests/Job/ObjectJobTest.php @@ -42,11 +42,8 @@ public function testPayloadObjectValueShouldBeObject(): void public function testHandleWithHandleMethod(): void { $object = new class($this) { - private $testCase; - - public function __construct($testCase) + public function __construct(private $testCase) { - $this->testCase = $testCase; } public function handle(string $name, string $id, ContainerInterface $container): void @@ -65,11 +62,8 @@ public function handle(string $name, string $id, ContainerInterface $container): public function testHandleWithInvokeMethod(): void { $object = new class($this) { - private $testCase; - - public function __construct($testCase) + public function __construct(private $testCase) { - $this->testCase = $testCase; } public function __invoke(string $name, string $id, ContainerInterface $container): void diff --git a/src/Router/tests/Diactoros/ResponseFactory.php b/src/Router/tests/Diactoros/ResponseFactory.php index ae6d5c579..98cb8d0b2 100644 --- a/src/Router/tests/Diactoros/ResponseFactory.php +++ b/src/Router/tests/Diactoros/ResponseFactory.php @@ -11,12 +11,8 @@ final class ResponseFactory implements ResponseFactoryInterface { - /** @var HttpConfig */ - protected $config; - - public function __construct(HttpConfig $config) + public function __construct(protected HttpConfig $config) { - $this->config = $config; } public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface diff --git a/src/Router/tests/TestCore.php b/src/Router/tests/TestCore.php index d78e811a4..c6fa47a04 100644 --- a/src/Router/tests/TestCore.php +++ b/src/Router/tests/TestCore.php @@ -8,11 +8,8 @@ class TestCore implements CoreInterface { - private $core; - - public function __construct(CoreInterface $core) + public function __construct(private CoreInterface $core) { - $this->core = $core; } public function callAction(string $controller, string $action = null, array $parameters = []): string diff --git a/src/Scaffolder/src/Declaration/FilterDeclaration.php b/src/Scaffolder/src/Declaration/FilterDeclaration.php index acdd1da96..d9a29156d 100644 --- a/src/Scaffolder/src/Declaration/FilterDeclaration.php +++ b/src/Scaffolder/src/Declaration/FilterDeclaration.php @@ -33,7 +33,7 @@ public function __construct( try { $this->validationConfig = $container->get(ValidationConfig::class); - } catch (\Throwable $e) { + } catch (\Throwable) { // Validation is not configured $this->validationConfig = null; } diff --git a/src/Security/src/Rule.php b/src/Security/src/Rule.php index f55f89b6d..fe15e9bec 100644 --- a/src/Security/src/Rule.php +++ b/src/Security/src/Rule.php @@ -61,7 +61,7 @@ public function allows(ActorInterface $actor, string $permission, array $context try { return $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); } catch (\Throwable $e) { - throw new RuleException(\sprintf('[%s] %s', $this::class, $e->getMessage()), (int) $e->getCode(), $e); + throw new RuleException(\sprintf('[%s] %s', static::class, $e->getMessage()), (int) $e->getCode(), $e); } } } diff --git a/src/Security/tests/RuleManagerTest.php b/src/Security/tests/RuleManagerTest.php index cbe16b1cc..f7e0cf818 100644 --- a/src/Security/tests/RuleManagerTest.php +++ b/src/Security/tests/RuleManagerTest.php @@ -35,7 +35,7 @@ public function setUp(): void public function testFlow(): void { - $ruleClass = get_class($this->rule); + $ruleClass = $this->rule::class; $this->container->shouldReceive('get') ->once() @@ -60,7 +60,7 @@ public function testFlow(): void public function testHasWithNotRegisteredClass(): void { - $ruleClass = get_class($this->rule); + $ruleClass = $this->rule::class; $manager = new RuleManager($this->container); $this->assertTrue($manager->has($ruleClass)); diff --git a/src/SendIt/tests/JobTest.php b/src/SendIt/tests/JobTest.php index 6a1497a2d..18e0e4002 100644 --- a/src/SendIt/tests/JobTest.php +++ b/src/SendIt/tests/JobTest.php @@ -63,7 +63,7 @@ public function testHandlerError(): void 'id', json_encode(MessageSerializer::pack($this->getMail())) ); - } catch (TransportException $e) { + } catch (TransportException) { } } diff --git a/src/Serializer/tests/Fixture/SomeClass.php b/src/Serializer/tests/Fixture/SomeClass.php index fa321d1ea..a38baaca4 100644 --- a/src/Serializer/tests/Fixture/SomeClass.php +++ b/src/Serializer/tests/Fixture/SomeClass.php @@ -6,14 +6,7 @@ class SomeClass implements SomeInterface { - public function __construct(int $id, string $text, bool $active) + public function __construct(public int $id, public string $text, public bool $active) { - $this->id = $id; - $this->text = $text; - $this->active = $active; } - - public int $id; - public string $text; - public bool $active; } diff --git a/src/Storage/src/Storage.php b/src/Storage/src/Storage.php index e719641bb..9a0cdcb61 100644 --- a/src/Storage/src/Storage.php +++ b/src/Storage/src/Storage.php @@ -36,11 +36,9 @@ final class Storage implements MutableStorageInterface * @var array */ private array $buckets = []; - private string $default; - public function __construct(string $name = self::DEFAULT_STORAGE) + public function __construct(private string $default = self::DEFAULT_STORAGE) { - $this->default = $name; } public function withDefault(string $name): StorageInterface diff --git a/src/Translator/src/Matcher.php b/src/Translator/src/Matcher.php index 3b1972c47..d4b203f7f 100644 --- a/src/Translator/src/Matcher.php +++ b/src/Translator/src/Matcher.php @@ -13,7 +13,7 @@ final class Matcher { public function isPattern(string $string): bool { - return \strpos($string, '*') !== false || \strpos($string, '|') !== false; + return str_contains($string, '*') || str_contains($string, '|'); } /** diff --git a/tests/app/src/Controller/AuthController.php b/tests/app/src/Controller/AuthController.php index 98922741f..ee2c38af2 100644 --- a/tests/app/src/Controller/AuthController.php +++ b/tests/app/src/Controller/AuthController.php @@ -12,11 +12,8 @@ class AuthController { - private $auth; - - public function __construct(AuthScope $auth) + public function __construct(private AuthScope $auth) { - $this->auth = $auth; } public function do(GuardInterface $guard) diff --git a/tests/app/src/Controller/TestController.php b/tests/app/src/Controller/TestController.php index 27af8e6dd..0ced0c4d9 100644 --- a/tests/app/src/Controller/TestController.php +++ b/tests/app/src/Controller/TestController.php @@ -62,7 +62,7 @@ public function payload(ServerRequestInterface $request) public function required(int $id) { //no index - $this->say(get_class($this)); + $this->say(static::class); $this->say('Hello world'); $this->say('Hello world', [], 'external'); diff --git a/tests/app/src/Interceptor/Append.php b/tests/app/src/Interceptor/Append.php index 18cff888d..22266e8ff 100644 --- a/tests/app/src/Interceptor/Append.php +++ b/tests/app/src/Interceptor/Append.php @@ -9,11 +9,8 @@ class Append implements CoreInterceptorInterface { - private $string; - - public function __construct(string $string) + public function __construct(private string $string) { - $this->string = $string; } public function process(string $controller, string $action, array $parameters, CoreInterface $core): array diff --git a/tests/app/src/ViewEngine/View.php b/tests/app/src/ViewEngine/View.php index 6dfb075df..e9ef1e9ca 100644 --- a/tests/app/src/ViewEngine/View.php +++ b/tests/app/src/ViewEngine/View.php @@ -9,11 +9,8 @@ class View implements ViewInterface { - private $source; - - public function __construct(ViewSource $source) + public function __construct(private ViewSource $source) { - $this->source = $source; } public function render(array $data = []): string