Skip to content

Upgrade code to php 7.4 level #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/extension-installer": "^1.1",
"vimeo/psalm": "^4.25"
"vimeo/psalm": "^4.25",
"rector/rector": "^0.13.9"
},
"autoload": {
"psr-4": {
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Set the minimum PHP version for PHPCompatibility.
This should be kept in sync with the requirements in the composer.json file. -->
<config name="testVersion" value="7.2-"/>
<config name="testVersion" value="7.4-"/>

<rule ref="phpDocumentor">
<!-- Property type declarations are a PHP 7.4 feature. -->
Expand Down
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests/unit'
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->rule(Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector::class);
$rectorConfig->rule(Rector\PHPUnit\Rector\Class_\AddProphecyTraitRector::class);
$rectorConfig->importNames();

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74
]);
};
2 changes: 1 addition & 1 deletion src/PseudoTypes/False_.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function __toString(): string
}
}

class_alias('\phpDocumentor\Reflection\PseudoTypes\False_', 'phpDocumentor\Reflection\Types\False_', false);
class_alias(False_::class, 'phpDocumentor\Reflection\Types\False_', false);
6 changes: 2 additions & 4 deletions src/PseudoTypes/IntegerRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
*/
final class IntegerRange extends Integer implements PseudoType
{
/** @var string */
private $minValue;
private string $minValue;

/** @var string */
private $maxValue;
private string $maxValue;

public function __construct(string $minValue, string $maxValue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PseudoTypes/True_.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function __toString(): string
}
}

class_alias('\phpDocumentor\Reflection\PseudoTypes\True_', 'phpDocumentor\Reflection\Types\True_', false);
class_alias(True_::class, 'phpDocumentor\Reflection\Types\True_', false);
121 changes: 71 additions & 50 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,60 @@

use ArrayIterator;
use InvalidArgumentException;
use phpDocumentor\Reflection\PseudoTypes\CallableString;
use phpDocumentor\Reflection\PseudoTypes\False_;
use phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString;
use phpDocumentor\Reflection\PseudoTypes\IntegerRange;
use phpDocumentor\Reflection\PseudoTypes\List_;
use phpDocumentor\Reflection\PseudoTypes\LiteralString;
use phpDocumentor\Reflection\PseudoTypes\LowercaseString;
use phpDocumentor\Reflection\PseudoTypes\NegativeInteger;
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
use phpDocumentor\Reflection\PseudoTypes\NonEmptyString;
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
use phpDocumentor\Reflection\PseudoTypes\NumericString;
use phpDocumentor\Reflection\PseudoTypes\PositiveInteger;
use phpDocumentor\Reflection\PseudoTypes\TraitString;
use phpDocumentor\Reflection\PseudoTypes\True_;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\ArrayKey;
use phpDocumentor\Reflection\Types\Boolean;
use phpDocumentor\Reflection\Types\Callable_;
use phpDocumentor\Reflection\Types\ClassString;
use phpDocumentor\Reflection\Types\Collection;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Expression;
use phpDocumentor\Reflection\Types\Float_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\InterfaceString;
use phpDocumentor\Reflection\Types\Intersection;
use phpDocumentor\Reflection\Types\Iterable_;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Never_;
use phpDocumentor\Reflection\Types\Null_;
use phpDocumentor\Reflection\Types\Nullable;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\Parent_;
use phpDocumentor\Reflection\Types\Resource_;
use phpDocumentor\Reflection\Types\Scalar;
use phpDocumentor\Reflection\Types\Self_;
use phpDocumentor\Reflection\Types\Static_;
use phpDocumentor\Reflection\Types\String_;
use phpDocumentor\Reflection\Types\This;
use phpDocumentor\Reflection\Types\Void_;
use RuntimeException;

use function array_key_exists;
use function array_key_last;
use function array_pop;
use function array_values;
use function class_exists;
use function class_implements;
use function count;
use function current;
use function end;
use function in_array;
use function is_numeric;
use function key;
use function preg_split;
use function strpos;
use function strtolower;
Expand Down Expand Up @@ -76,54 +101,51 @@ final class TypeResolver
* @var array<string, string> List of recognized keywords and unto which Value Object they map
* @psalm-var array<string, class-string<Type>>
*/
private $keywords = [
'string' => Types\String_::class,
'class-string' => Types\ClassString::class,
'interface-string' => Types\InterfaceString::class,
'html-escaped-string' => PseudoTypes\HtmlEscapedString::class,
'lowercase-string' => PseudoTypes\LowercaseString::class,
'non-empty-lowercase-string' => PseudoTypes\NonEmptyLowercaseString::class,
'non-empty-string' => PseudoTypes\NonEmptyString::class,
'numeric-string' => PseudoTypes\NumericString::class,
'numeric' => PseudoTypes\Numeric_::class,
'trait-string' => PseudoTypes\TraitString::class,
'int' => Types\Integer::class,
'integer' => Types\Integer::class,
'positive-int' => PseudoTypes\PositiveInteger::class,
'negative-int' => PseudoTypes\NegativeInteger::class,
'bool' => Types\Boolean::class,
'boolean' => Types\Boolean::class,
'real' => Types\Float_::class,
'float' => Types\Float_::class,
'double' => Types\Float_::class,
'object' => Types\Object_::class,
'mixed' => Types\Mixed_::class,
'array' => Types\Array_::class,
'array-key' => Types\ArrayKey::class,
'resource' => Types\Resource_::class,
'void' => Types\Void_::class,
'null' => Types\Null_::class,
'scalar' => Types\Scalar::class,
'callback' => Types\Callable_::class,
'callable' => Types\Callable_::class,
'callable-string' => PseudoTypes\CallableString::class,
'false' => PseudoTypes\False_::class,
'true' => PseudoTypes\True_::class,
'literal-string' => PseudoTypes\LiteralString::class,
'self' => Types\Self_::class,
'$this' => Types\This::class,
'static' => Types\Static_::class,
'parent' => Types\Parent_::class,
'iterable' => Types\Iterable_::class,
'never' => Types\Never_::class,
'list' => PseudoTypes\List_::class,
private array $keywords = [
'string' => String_::class,
'class-string' => ClassString::class,
'interface-string' => InterfaceString::class,
'html-escaped-string' => HtmlEscapedString::class,
'lowercase-string' => LowercaseString::class,
'non-empty-lowercase-string' => NonEmptyLowercaseString::class,
'non-empty-string' => NonEmptyString::class,
'numeric-string' => NumericString::class,
'numeric' => Numeric_::class,
'trait-string' => TraitString::class,
'int' => Integer::class,
'integer' => Integer::class,
'positive-int' => PositiveInteger::class,
'negative-int' => NegativeInteger::class,
'bool' => Boolean::class,
'boolean' => Boolean::class,
'real' => Float_::class,
'float' => Float_::class,
'double' => Float_::class,
'object' => Object_::class,
'mixed' => Mixed_::class,
'array' => Array_::class,
'array-key' => ArrayKey::class,
'resource' => Resource_::class,
'void' => Void_::class,
'null' => Null_::class,
'scalar' => Scalar::class,
'callback' => Callable_::class,
'callable' => Callable_::class,
'callable-string' => CallableString::class,
'false' => False_::class,
'true' => True_::class,
'literal-string' => LiteralString::class,
'self' => Self_::class,
'$this' => This::class,
'static' => Static_::class,
'parent' => Parent_::class,
'iterable' => Iterable_::class,
'never' => Never_::class,
'list' => List_::class,
];

/**
* @var FqsenResolver
* @psalm-readonly
*/
private $fqsenResolver;
/** @psalm-readonly */
private FqsenResolver $fqsenResolver;

/**
* Initializes this TypeResolver with the means to create and resolve Fqsen objects.
Expand Down Expand Up @@ -280,8 +302,7 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser
) {
break;
} elseif ($token === self::OPERATOR_ARRAY) {
end($types);
$last = key($types);
$last = array_key_last($types);
if ($last === null) {
throw new InvalidArgumentException('Unexpected array operator');
}
Expand Down
5 changes: 2 additions & 3 deletions src/Types/AggregatedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ abstract class AggregatedType implements Type, IteratorAggregate
* @psalm-allow-private-mutation
* @var array<int, Type>
*/
private $types = [];
private array $types = [];

/** @var string */
private $token;
private string $token;

/**
* @param array<Type> $types
Expand Down
3 changes: 1 addition & 2 deletions src/Types/ClassString.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*/
final class ClassString extends String_ implements PseudoType
{
/** @var Fqsen|null */
private $fqsen;
private ?Fqsen $fqsen;

/**
* Initializes this representation of a class string with the given Fqsen.
Expand Down
3 changes: 1 addition & 2 deletions src/Types/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
*/
final class Collection extends AbstractList
{
/** @var Fqsen|null */
private $fqsen;
private ?Fqsen $fqsen;

/**
* Initializes this representation of an array with the given Type or Fqsen.
Expand Down
4 changes: 2 additions & 2 deletions src/Types/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
final class Context
{
/** @var string The current namespace. */
private $namespace;
private string $namespace;

/**
* @var string[] List of namespace aliases => Fully Qualified Namespace.
* @psalm-var array<string, string>
*/
private $namespaceAliases;
private array $namespaceAliases;

/**
* Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN)
Expand Down
3 changes: 1 addition & 2 deletions src/Types/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
*/
final class Expression implements Type
{
/** @var Type */
protected $valueType;
protected Type $valueType;

/**
* Initializes this representation of an array with the given Type.
Expand Down
3 changes: 1 addition & 2 deletions src/Types/InterfaceString.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
final class InterfaceString implements Type
{
/** @var Fqsen|null */
private $fqsen;
private ?Fqsen $fqsen;

/**
* Initializes this representation of a class string with the given Fqsen.
Expand Down
2 changes: 1 addition & 1 deletion src/Types/Nullable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
final class Nullable implements Type
{
/** @var Type The actual type that is wrapped */
private $realType;
private Type $realType;

/**
* Initialises this nullable type using the real type embedded
Expand Down
Loading