diff --git a/composer.json b/composer.json
index 510a5ff..a7ae10f 100644
--- a/composer.json
+++ b/composer.json
@@ -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": {
diff --git a/composer.lock b/composer.lock
index 732664b..adcb69d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "deb6a09787d5a7696cff3ea71b45b035",
+ "content-hash": "0995b56862f68800c3c014da7cd2503f",
"packages": [
{
"name": "phpdocumentor/reflection-common",
@@ -1854,6 +1854,66 @@
},
"time": "2021-05-03T11:20:27+00:00"
},
+ {
+ "name": "rector/rector",
+ "version": "0.13.9",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/rectorphp/rector.git",
+ "reference": "d6319ec783876579b608840cdfe1d8b566c72f74"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/rectorphp/rector/zipball/d6319ec783876579b608840cdfe1d8b566c72f74",
+ "reference": "d6319ec783876579b608840cdfe1d8b566c72f74",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.2|^8.0",
+ "phpstan/phpstan": "^1.8.2"
+ },
+ "conflict": {
+ "phpstan/phpdoc-parser": "<1.6.2",
+ "rector/rector-cakephp": "*",
+ "rector/rector-doctrine": "*",
+ "rector/rector-laravel": "*",
+ "rector/rector-nette": "*",
+ "rector/rector-phpoffice": "*",
+ "rector/rector-phpunit": "*",
+ "rector/rector-prefixed": "*",
+ "rector/rector-symfony": "*"
+ },
+ "bin": [
+ "bin/rector"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "0.13-dev"
+ }
+ },
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "Instant Upgrade and Automated Refactoring of any PHP code",
+ "support": {
+ "issues": "https://github.com/rectorphp/rector/issues",
+ "source": "https://github.com/rectorphp/rector/tree/0.13.9"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/tomasvotruba",
+ "type": "github"
+ }
+ ],
+ "time": "2022-07-23T10:55:44+00:00"
+ },
{
"name": "sebastian/cli-parser",
"version": "1.0.1",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index a688b6a..d26097a 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -9,7 +9,7 @@
-
+
diff --git a/rector.php b/rector.php
new file mode 100644
index 0000000..b285d6c
--- /dev/null
+++ b/rector.php
@@ -0,0 +1,26 @@
+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
+ ]);
+};
diff --git a/src/PseudoTypes/False_.php b/src/PseudoTypes/False_.php
index 4ec6885..871c172 100644
--- a/src/PseudoTypes/False_.php
+++ b/src/PseudoTypes/False_.php
@@ -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);
diff --git a/src/PseudoTypes/IntegerRange.php b/src/PseudoTypes/IntegerRange.php
index c5a3bc5..37f774d 100644
--- a/src/PseudoTypes/IntegerRange.php
+++ b/src/PseudoTypes/IntegerRange.php
@@ -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)
{
diff --git a/src/PseudoTypes/True_.php b/src/PseudoTypes/True_.php
index dc970b3..c9ad1cb 100644
--- a/src/PseudoTypes/True_.php
+++ b/src/PseudoTypes/True_.php
@@ -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);
diff --git a/src/TypeResolver.php b/src/TypeResolver.php
index f8bbae8..e5695b8 100644
--- a/src/TypeResolver.php
+++ b/src/TypeResolver.php
@@ -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;
@@ -76,54 +101,51 @@ final class TypeResolver
* @var array List of recognized keywords and unto which Value Object they map
* @psalm-var array>
*/
- 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.
@@ -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');
}
diff --git a/src/Types/AggregatedType.php b/src/Types/AggregatedType.php
index 472a1cd..257ed51 100644
--- a/src/Types/AggregatedType.php
+++ b/src/Types/AggregatedType.php
@@ -34,10 +34,9 @@ abstract class AggregatedType implements Type, IteratorAggregate
* @psalm-allow-private-mutation
* @var array
*/
- private $types = [];
+ private array $types = [];
- /** @var string */
- private $token;
+ private string $token;
/**
* @param array $types
diff --git a/src/Types/ClassString.php b/src/Types/ClassString.php
index fbdd879..b54c549 100644
--- a/src/Types/ClassString.php
+++ b/src/Types/ClassString.php
@@ -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.
diff --git a/src/Types/Collection.php b/src/Types/Collection.php
index 943cc22..dbf3f19 100644
--- a/src/Types/Collection.php
+++ b/src/Types/Collection.php
@@ -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.
diff --git a/src/Types/Context.php b/src/Types/Context.php
index 79aadaf..17aa506 100644
--- a/src/Types/Context.php
+++ b/src/Types/Context.php
@@ -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
*/
- private $namespaceAliases;
+ private array $namespaceAliases;
/**
* Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN)
diff --git a/src/Types/Expression.php b/src/Types/Expression.php
index da5f65d..2b6b095 100644
--- a/src/Types/Expression.php
+++ b/src/Types/Expression.php
@@ -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.
diff --git a/src/Types/InterfaceString.php b/src/Types/InterfaceString.php
index 9836961..0b7dbb8 100644
--- a/src/Types/InterfaceString.php
+++ b/src/Types/InterfaceString.php
@@ -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.
diff --git a/src/Types/Nullable.php b/src/Types/Nullable.php
index a946935..52c3d53 100644
--- a/src/Types/Nullable.php
+++ b/src/Types/Nullable.php
@@ -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
diff --git a/src/Types/Object_.php b/src/Types/Object_.php
index 90dee57..feb6ee3 100644
--- a/src/Types/Object_.php
+++ b/src/Types/Object_.php
@@ -30,8 +30,7 @@
*/
final class Object_ implements Type
{
- /** @var Fqsen|null */
- private $fqsen;
+ private ?Fqsen $fqsen;
/**
* Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'.
diff --git a/tests/unit/CollectionResolverTest.php b/tests/unit/CollectionResolverTest.php
index 0d39176..eb25b04 100644
--- a/tests/unit/CollectionResolverTest.php
+++ b/tests/unit/CollectionResolverTest.php
@@ -13,12 +13,19 @@
namespace phpDocumentor\Reflection;
+use InvalidArgumentException;
use phpDocumentor\Reflection\PseudoTypes\List_;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Collection;
+use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
+use phpDocumentor\Reflection\Types\Float_;
+use phpDocumentor\Reflection\Types\Integer;
+use phpDocumentor\Reflection\Types\Nullable;
use phpDocumentor\Reflection\Types\Object_;
+use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;
+use RuntimeException;
/**
* @covers ::
@@ -50,8 +57,8 @@ public function testResolvingCollection(): void
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\String_::class, $valueType);
- $this->assertInstanceOf(Types\Compound::class, $keyType);
+ $this->assertInstanceOf(String_::class, $valueType);
+ $this->assertInstanceOf(Compound::class, $keyType);
}
/**
@@ -78,10 +85,10 @@ public function testResolvingCollectionWithKeyType(): void
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\Object_::class, $valueType);
+ $this->assertInstanceOf(Object_::class, $valueType);
$this->assertEquals('\\Iterator', (string) $valueType->getFqsen());
- $this->assertInstanceOf(Types\Array_::class, $keyType);
- $this->assertInstanceOf(Types\String_::class, $keyType->getValueType());
+ $this->assertInstanceOf(Array_::class, $keyType);
+ $this->assertInstanceOf(String_::class, $keyType->getValueType());
}
/**
@@ -106,8 +113,8 @@ public function testResolvingArrayCollection(): void
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\String_::class, $valueType);
- $this->assertInstanceOf(Types\Compound::class, $keyType);
+ $this->assertInstanceOf(String_::class, $valueType);
+ $this->assertInstanceOf(Compound::class, $keyType);
}
/**
@@ -132,8 +139,8 @@ public function testResolvingArrayCollectionWithKey(): void
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\String_::class, $keyType);
- $this->assertInstanceOf(Types\Compound::class, $valueType);
+ $this->assertInstanceOf(String_::class, $keyType);
+ $this->assertInstanceOf(Compound::class, $valueType);
}
/**
@@ -158,8 +165,8 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace(): void
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\String_::class, $keyType);
- $this->assertInstanceOf(Types\Compound::class, $valueType);
+ $this->assertInstanceOf(String_::class, $keyType);
+ $this->assertInstanceOf(Compound::class, $valueType);
}
/**
@@ -173,7 +180,7 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace(): void
*/
public function testResolvingArrayCollectionWithKeyAndTooManyWhitespace(): void
{
- $this->expectException('InvalidArgumentException');
+ $this->expectException(InvalidArgumentException::class);
$fixture = new TypeResolver();
$fixture->resolve('array', new Context(''));
@@ -200,19 +207,19 @@ public function testResolvingCollectionOfCollection(): void
$this->assertEquals('\\ArrayObject', (string) $resolvedType->getFqsen());
$valueType = $resolvedType->getValueType();
- $this->assertInstanceOf(Types\Collection::class, $valueType);
+ $this->assertInstanceOf(Collection::class, $valueType);
$collectionValueType = $valueType->getValueType();
- $this->assertInstanceOf(Types\Object_::class, $valueType->getValueType());
+ $this->assertInstanceOf(Object_::class, $valueType->getValueType());
$this->assertEquals('\\ArrayObject', (string) $valueType->getFqsen());
$this->assertInstanceOf(Object_::class, $collectionValueType);
$this->assertEquals('\\DateTime', (string) $collectionValueType->getFqsen());
$keyType = $resolvedType->getKeyType();
- $this->assertInstanceOf(Types\Compound::class, $keyType);
- $this->assertInstanceOf(Types\String_::class, $keyType->get(0));
- $this->assertInstanceOf(Types\Integer::class, $keyType->get(1));
- $this->assertInstanceOf(Types\Float_::class, $keyType->get(2));
+ $this->assertInstanceOf(Compound::class, $keyType);
+ $this->assertInstanceOf(String_::class, $keyType->get(0));
+ $this->assertInstanceOf(Integer::class, $keyType->get(1));
+ $this->assertInstanceOf(Float_::class, $keyType->get(2));
}
/**
@@ -221,7 +228,7 @@ public function testResolvingCollectionOfCollection(): void
*/
public function testBadArrayCollectionKey(): void
{
- $this->expectException('RuntimeException');
+ $this->expectException(RuntimeException::class);
$this->expectExceptionMessage('An array can have only integers or strings as keys');
$fixture = new TypeResolver();
$fixture->resolve('array