Skip to content

Commit

Permalink
Merge pull request #1141: Apply php8.1 in Rector preset
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Sep 10, 2024
2 parents c1ff081 + 1ecebd9 commit 0c45119
Show file tree
Hide file tree
Showing 62 changed files with 103 additions and 92 deletions.
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@
<referencedClass name="Psr\Container\ContainerExceptionInterface"/>
</errorLevel>
</InvalidThrow>
<RedundantCast>
<errorLevel type="suppress">
<file name="src/Core/src/Internal/Proxy/ProxyClassRenderer.php"/>
</errorLevel>
</RedundantCast>
</issueHandlers>
</psalm>
11 changes: 10 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;

return RectorConfig::configure()
->withPaths([
Expand Down Expand Up @@ -79,6 +81,7 @@
RemoveUnusedPublicMethodParameterRector::class,
RemoveEmptyClassMethodRector::class,
RemoveUnusedPromotedPropertyRector::class,
NewInInitializerRector::class,

// start with short open tag
__DIR__ . '/src/Views/tests/fixtures/other/var.php',
Expand All @@ -87,6 +90,7 @@
// example code for test
'*/Fixture/*',
'*/Fixtures/*',
'*/fixtures/*',
'*/Stub/*',
'*/Stubs/*',
'*/tests/Classes/*',
Expand All @@ -95,8 +99,13 @@

// cache
'*/runtime/cache/*',

ReadOnlyPropertyRector::class => [
// used by Configurator
__DIR__ . '/src/Scaffolder/src/Command',
],
])
->withPhpSets(php80: true)
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true)
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false,
Expand Down
2 changes: 1 addition & 1 deletion src/AuthHttp/src/Transport/CookieTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class CookieTransport implements HttpTransportInterface
{
public function __construct(
private string $cookie,
private readonly string $cookie,
private readonly string $basePath = '/',
private readonly ?string $domain = null,
private readonly bool $secure = false,
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/src/BootloadManager/BootloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class BootloadManager extends AbstractBootloadManager
{
private InvokerStrategyInterface $invokerStrategy;
private readonly InvokerStrategyInterface $invokerStrategy;

public function __construct(
ScopeInterface $scope,
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/src/Bootloader/ConfigurationBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ConfigurationBootloader extends Bootloader
ConfigManager::class => [self::class, 'configManager'],
];

private ConfiguratorInterface $configurator;
private readonly ConfiguratorInterface $configurator;

/** @var FileLoaderInterface[] */
private array $loaders;
Expand Down
2 changes: 1 addition & 1 deletion src/Boot/src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Environment implements EnvironmentInterface

public function __construct(
array $values = [],
private bool $overwrite = false
private readonly bool $overwrite = false
) {
$this->values = $values + $_ENV + $_SERVER;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Config/src/Patch/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class Group implements PatchInterface
{
/** @var PatchInterface[] */
private array $patches;
private readonly array $patches;

public function __construct(PatchInterface ...$patch)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Config/tests/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Value
{
public function __construct(private string $value = 'value!')
public function __construct(private readonly string $value = 'value!')
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/src/Configurator/ConstantBasedConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public function configure(Command $command, \ReflectionClass $reflection): void
$command->setDescription((string) $reflection->getConstant('DESCRIPTION'));

foreach ($reflection->getMethod('defineOptions')->invoke($command) as $option) {
\call_user_func_array([$command, 'addOption'], $option);
$command->addOption(...$option);
}

foreach ($reflection->getMethod('defineArguments')->invoke($command) as $argument) {
\call_user_func_array([$command, 'addArgument'], $argument);
$command->addArgument(...$argument);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Console/src/Configurator/Signature/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function parseParameters(array $tokens): array
$options = [];

foreach ($tokens as $token) {
if (\preg_match('/-{2,}(.*)/', $token, $matches)) {
if (\preg_match('/-{2,}(.*)/', (string) $token, $matches)) {
$options[] = $this->parseOption($matches[1]);
} else {
$arguments[] = $this->parseArgument($token);
Expand Down
6 changes: 3 additions & 3 deletions src/Console/tests/PromptArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testPromptArgumentWithQuestionOnProperty(): void
new #[AsCommand(name: 'foo')] class extends Command
{
#[Question(question: 'This is question from the attribute on the property')]
private string $email;
private readonly string $email;

public function perform(): int
{
Expand All @@ -119,10 +119,10 @@ public function testPromptArgumentWithQuestionOnDifferentPropertyShouldBeSkipped
$promptArguments,
new #[AsCommand(name: 'foo')] class extends Command
{
private string $email;
private readonly string $email;

#[Question(question: 'This is question from the attribute on the property')]
private string $password;
private readonly string $password;

public function perform(): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cookies/src/Config/CookiesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function resolveDomain(UriInterface $uri): ?string

if ($host === 'localhost' || \filter_var($host, FILTER_VALIDATE_IP)) {
//We can't use sub-domains when website required by IP
$pattern = \ltrim($pattern, '.');
$pattern = \ltrim((string) $pattern, '.');
}

if (!str_contains((string) $pattern, '%s')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Config/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
final class Inflector extends Binding
{
private int $parametersCount;
private readonly int $parametersCount;

/**
* @param \Closure $inflector The first closure argument is the object to be manipulated.
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Internal/Common/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ final class Registry
* @param array<string, object> $objects
*/
public function __construct(
private Config $config,
private readonly Config $config,
private array $objects = [],
private Options $options = new Options(),
private readonly Options $options = new Options(),
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Internal/Proxy/ProxyClassRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static function renderMethod(\ReflectionMethod $m, string $body = ''): st
$m->isStatic() ? ' static' : '',
$m->returnsReference() ? '&' : '',
$m->getName(),
\implode(', ', \array_map([self::class, 'renderParameter'], $m->getParameters())),
\implode(', ', \array_map(self::renderParameter(...), $m->getParameters())),
$m->hasReturnType()
? ': ' . self::renderParameterTypes($m->getReturnType(), $m->getDeclaringClass())
: '',
Expand Down Expand Up @@ -181,7 +181,7 @@ public static function renderDefaultValue(\ReflectionParameter $param): string
if ($param->isDefaultValueConstant()) {
$result = $param->getDefaultValueConstantName();

return \explode('::', $result)[0] === 'self'
return \explode('::', (string) $result)[0] === 'self'
? $result
: '\\' . $result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/tests/AutowireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function testCallMethodWithNullValueOnScalarUnionNull(): void
$container = new Container();

$result = $container->invoke(
[UnionTypes::class, 'unionNull'],
UnionTypes::unionNull(...),
[
'nullable' => null,
]
Expand Down
2 changes: 1 addition & 1 deletion src/Distribution/src/Internal/DateTimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class DateTimeFactory implements DateTimeFactoryInterface
private const DEFAULT_TIMEZONE = 'UTC';
private const DATE_NOW = 'now';

private \DateTimeZone $timezone;
private readonly \DateTimeZone $timezone;

public function __construct(string $timezone = self::DEFAULT_TIMEZONE)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Distribution/src/Internal/DateTimeIntervalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class DateTimeIntervalFactory implements DateTimeIntervalFactoryInterface
private const ERROR_INVALID_INTERVAL_TYPE = 'The value of type `%s` is not a valid date interval type.';

public function __construct(
private DateTimeFactoryInterface $factory = new DateTimeFactory()
private readonly DateTimeFactoryInterface $factory = new DateTimeFactory()
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Distribution/src/Resolver/CloudFrontResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*/
class CloudFrontResolver extends ExpirationAwareResolver
{
private UrlSigner $signer;
private AmazonUriFactory $factory;
private readonly UrlSigner $signer;
private readonly AmazonUriFactory $factory;

public function __construct(
string $keyPairId,
string $privateKey,
private string $domain,
private ?string $prefix = null
private readonly string $domain,
private readonly ?string $prefix = null
) {
$this->assertCloudFrontAvailable();
$this->factory = new AmazonUriFactory();
Expand Down
6 changes: 3 additions & 3 deletions src/Distribution/src/Resolver/S3SignedResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class S3SignedResolver extends ExpirationAwareResolver
{
public function __construct(
private S3ClientInterface $client,
private string $bucket,
private ?string $prefix = null
private readonly S3ClientInterface $client,
private readonly string $bucket,
private readonly ?string $prefix = null
) {
parent::__construct();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Distribution/src/Resolver/StaticResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StaticResolver extends UriResolver
{
private const URI_PATH_DELIMITER = '/';

private UriInterface $host;
private readonly UriInterface $host;

public function __construct(UriInterface $host)
{
Expand Down
9 changes: 3 additions & 6 deletions src/Exceptions/src/Renderer/ConsoleRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,11 @@ private function renderTrace(\Throwable $e, Highlighter $h = null): string
$pad = \strlen((string)\count($stacktrace));

foreach ($stacktrace as $i => $trace) {
$file = null;
$file = isset($trace['file']) ? (string) $trace['file'] : null;
$classColor = 'while';

if (isset($trace['file'])) {
$file = \str_starts_with($trace['file'], $rootDir)
? \substr($trace['file'], \strlen($rootDir) + 1)
: $trace['file'];

if ($file !== null) {
\str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1);
$classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/src/Renderer/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Highlighter
{
public function __construct(
private StyleInterface $renderer
private readonly StyleInterface $renderer
) {
}

Expand Down
5 changes: 2 additions & 3 deletions src/Exceptions/src/Renderer/PlainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ private function renderTrace(\Throwable $e, Highlighter $h = null): string
}

if (isset($trace['file'])) {
$file = \str_starts_with($trace['file'], $rootDir)
? \substr($trace['file'], \strlen($rootDir) + 1)
: $trace['file'];
$file = (string) $trace['file'];
\str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1);

$line .= \sprintf(' at %s:%s', $file, $trace['line']);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/src/Reporter/LoggerReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class LoggerReporter implements ExceptionReporterInterface
{
public function __construct(
private LoggerInterface $logger = new NullLogger()
private readonly LoggerInterface $logger = new NullLogger()
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Filters/src/Model/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function makeSchema(string $name, array $schema): array

// [class, 'data:something.*'] vs [class, 'data:something']
$iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]);
$origin = \rtrim($origin, '.*');
$origin = \rtrim((string) $origin, '.*');
} else {
$origin = $field;
$iterate = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/tests/Model/Schema/AttributeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testInputAttribute(): void
public int $page;

#[Attribute]
private string $wsPath;
private readonly string $wsPath;

#[BearerToken]
public string $token;
Expand Down
2 changes: 1 addition & 1 deletion src/Hmvc/src/InterceptableCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class InterceptableCore implements CoreInterface, HandlerInterface
{
private InterceptorPipeline $pipeline;
private readonly InterceptorPipeline $pipeline;

public function __construct(
private readonly CoreInterface $core,
Expand Down
2 changes: 1 addition & 1 deletion src/Http/src/Header/AcceptHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function addItem(AcceptHeaderItem|string $item): void
$item = AcceptHeaderItem::fromString($item);
}

$value = \strtolower($item->getValue());
$value = \strtolower((string) $item->getValue());
if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) {
$this->sorted = false;
$this->items[$value] = $item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class EnvSuppressErrors implements SuppressErrorsInterface
{
public function __construct(
private DebugMode $debugMode
private readonly DebugMode $debugMode
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/src/Request/InputManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function request(): Request
*/
public function bearerToken(): ?string
{
$header = $this->header('Authorization', '');
$header = (string) $this->header('Authorization', '');

$position = \strrpos($header, 'Bearer ');

Expand Down Expand Up @@ -279,7 +279,7 @@ public function isJsonExpected(bool $softMatch = false): bool

if ($softMatch) {
foreach ($acceptHeader->getAll() as $item) {
$itemValue = \strtolower($item->getValue());
$itemValue = \strtolower((string) $item->getValue());
if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/tests/Streamable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Streamable implements StreamableInterface
{
public function __construct(private StreamInterface $stream)
public function __construct(private readonly StreamInterface $stream)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Logger/src/LogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(

public function getLogger(string $channel): LoggerInterface
{
return new NullLogger([$this, 'log'], $channel);
return new NullLogger($this->log(...), $channel);
}

public function log(string $channel, mixed $level, string $message, array $context = []): void
Expand Down
Loading

0 comments on commit 0c45119

Please sign in to comment.