Skip to content

Commit

Permalink
Apply php8.0 in Rector preset
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 5, 2024
1 parent 4baf322 commit e5afbd5
Show file tree
Hide file tree
Showing 35 changed files with 40 additions and 111 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@
// cache
'*/runtime/cache/*',
])
->withPhpSets(php74: true)
->withPhpSets(php80: true)
->withPreparedSets(deadCode: true);
6 changes: 1 addition & 5 deletions src/AuthHttp/tests/Diactoros/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion src/AuthHttp/tests/Middleware/AuthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
);
Expand Down
3 changes: 1 addition & 2 deletions src/Boot/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Config/tests/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Console/tests/ShortException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ShortException extends \Exception
{
public function __toString()
public function __toString(): string
{
return 'exception';
}
Expand Down
6 changes: 1 addition & 5 deletions src/Cookies/tests/TestResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Core/tests/ScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions src/Csrf/tests/TestResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
4 changes: 1 addition & 3 deletions src/Distribution/src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ final class Manager implements MutableDistributionInterface
* @var array<string, UriResolverInterface>
*/
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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Distribution/tests/Resolver/StaticResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}

Expand All @@ -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')
);
}
}
7 changes: 2 additions & 5 deletions src/Http/src/Stream/GeneratorStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

final class GeneratorStream implements StreamInterface
{
private ?Generator $stream;

private bool $readable = true;

private ?int $size = null;
Expand All @@ -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 '';
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Http/tests/Diactoros/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Http/tests/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

class Json implements \JsonSerializable
{
private $data;

public function __construct($data)
public function __construct(private $data)
{
$this->data = $data;
}

#[\ReturnTypeWillChange]
Expand Down
5 changes: 1 addition & 4 deletions src/Http/tests/Streamable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Models/tests/NameValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Spiral\Models\ValueInterface;

class NameValue implements ValueInterface
class NameValue implements ValueInterface, \Stringable
{
private $value;

Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Prototype/tests/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Queue/src/Attribute/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Queue/src/Interceptor/Push/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function getTracer(): TracerInterface
{
try {
return ContainerScope::getContainer()->get(TracerInterface::class);
} catch (\Throwable $e) {
} catch (\Throwable) {
return new NullTracer();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Queue/src/JobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Queue/src/QueueableDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

final class QueueableDetector
{
private ReaderInterface $reader;

public function __construct(ReaderInterface $reader)
public function __construct(private ReaderInterface $reader)
{
$this->reader = $reader;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/Queue/tests/Job/ObjectJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Router/tests/Diactoros/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Router/tests/TestCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolder/src/Declaration/FilterDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Security/src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/Security/tests/RuleManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/SendIt/tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testHandlerError(): void
'id',
json_encode(MessageSerializer::pack($this->getMail()))
);
} catch (TransportException $e) {
} catch (TransportException) {
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/Serializer/tests/Fixture/SomeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit e5afbd5

Please sign in to comment.