Skip to content

Commit

Permalink
Merge pull request #621 from kukulich/annotations
Browse files Browse the repository at this point in the history
Annotations cleanup
  • Loading branch information
Ocramius committed May 28, 2020
2 parents 45da27f + c6767e0 commit aa017e6
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 144 deletions.
6 changes: 4 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<!-- @psalm-return annotations are used -->
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
Expand All @@ -40,4 +38,8 @@
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint">
<exclude-pattern>src/Reflection/Adapter/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification">
<!-- Useless for data providers -->
<exclude-pattern>test/unit/</exclude-pattern>
</rule>
</ruleset>
12 changes: 3 additions & 9 deletions src/NodeCompiler/CompileNodeToValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ class CompileNodeToValue
*
* @param Node\Stmt\Expression|Node\Expr $node Node has to be processed by the PhpParser\NodeVisitor\NameResolver
*
* @return bool|int|float|string|array|null
* @return scalar|array<scalar>|null
*
* @throws Exception\UnableToCompileNode
*
* @psalm-return scalar|array<scalar>|null
*/
public function __invoke(Node $node, CompilerContext $context)
{
Expand Down Expand Up @@ -62,11 +60,9 @@ public function __invoke(Node $node, CompilerContext $context)
/**
* Compile constant expressions
*
* @return bool|int|float|string|array|null
* @return scalar|array<scalar>|null
*
* @throws Exception\UnableToCompileNode
*
* @psalm-return scalar|array<scalar>|null
*/
private function compileConstFetch(Node\Expr\ConstFetch $constNode, CompilerContext $context)
{
Expand All @@ -90,12 +86,10 @@ private function compileConstFetch(Node\Expr\ConstFetch $constNode, CompilerCont
/**
* Compile class constants
*
* @return bool|int|float|string|array|null
* @return scalar|array<scalar>|null
*
* @throws IdentifierNotFound
* @throws Exception\UnableToCompileNode If a referenced constant could not be located on the expected referenced class.
*
* @psalm-return scalar|array<scalar>|null
*/
private function compileClassConstFetch(Node\Expr\ClassConstFetch $node, CompilerContext $context)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/Adapter/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function getTraits()
{
$traits = $this->betterReflectionClass->getTraits();

/** @psalm-var array<trait-string> $traitNames */
/** @var array<trait-string> $traitNames */
$traitNames = array_map(static function (BetterReflectionClass $trait) : string {
return $trait->getName();
}, $traits);
Expand Down
4 changes: 1 addition & 3 deletions src/Reflection/Adapter/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function getName() : string
/**
* Returns constant value
*
* @return bool|int|float|string|array|null
*
* @psalm-return scalar|array<scalar>|null
* @return scalar|array<scalar>|null
*/
public function getValue()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/Adapter/ReflectionObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function getTraits()
{
$traits = $this->betterReflectionObject->getTraits();

/** @psalm-var array<trait-string> $traitNames */
/** @var array<trait-string> $traitNames */
$traitNames = array_map(static function (BetterReflectionClass $trait) : string {
return $trait->getName();
}, $traits);
Expand Down
86 changes: 23 additions & 63 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,16 @@ class ReflectionClass implements Reflection
/** @var ClassLikeNode */
private $node;

/**
* @var ReflectionClassConstant[]|null indexed by name, when present
* @psalm-var ?array<string, ReflectionClassConstant>
*/
/** @var array<string, ReflectionClassConstant>|null indexed by name, when present */
private $cachedReflectionConstants;

/**
* @var ReflectionProperty[]|null
* @psalm-var ?array<string, ReflectionProperty>
*/
/** @var array<string, ReflectionProperty>|null */
private $cachedImmediateProperties;

/**
* @var ReflectionProperty[]|null
* @psalm-var ?array<string, ReflectionProperty>
*/
/** @var array<string, ReflectionProperty>|null */
private $cachedProperties;

/**
* @var ReflectionMethod[]|null
* @psalm-var ?array<lowercase-string, ReflectionMethod>
*/
/** @var array<lowercase-string, ReflectionMethod>|null */
private $cachedMethods;

/** @var array<string, string>|null */
Expand Down Expand Up @@ -194,7 +182,7 @@ public function getShortName() : string
* Get the "full" name of the class (e.g. for A\B\Foo, this will return
* "A\B\Foo").
*
* @psalm-return class-string
* @return class-string
*/
public function getName() : string
{
Expand Down Expand Up @@ -339,9 +327,7 @@ private function createMethodsFromTrait(ReflectionMethod $method) : array
* Methods are not merged via their name as array index, since internal PHP method
* sorting does not follow `\array_merge()` semantics.
*
* @return ReflectionMethod[] indexed by method name
*
* @psalm-return array<lowercase-string, ReflectionMethod>
* @return array<lowercase-string, ReflectionMethod> indexed by method name
*/
private function getMethodsIndexedByName() : array
{
Expand Down Expand Up @@ -380,9 +366,7 @@ private function getMethodsIndexedByName() : array
* For example if $filter = \ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_FINAL
* the only the final public methods will be returned
*
* @return ReflectionMethod[]
*
* @psalm-return list<ReflectionMethod>
* @return list<ReflectionMethod>
*/
public function getMethods(?int $filter = null) : array
{
Expand Down Expand Up @@ -472,7 +456,7 @@ public function hasMethod(string $methodName) : bool
* Get an associative array of only the constants for this specific class (i.e. do not search
* up parent classes etc.), with keys as constant names and values as constant values.
*
* @psalm-return array<string, scalar|array<scalar>|null>
* @return array<string, scalar|array<scalar>|null>
*/
public function getImmediateConstants() : array
{
Expand All @@ -485,7 +469,7 @@ public function getImmediateConstants() : array
* Get an associative array of the defined constants in this class,
* with keys as constant names and values as constant values.
*
* @psalm-return array<string, scalar|array<scalar>|null>
* @return array<string, scalar|array<scalar>|null>
*/
public function getConstants() : array
{
Expand All @@ -499,9 +483,7 @@ public function getConstants() : array
*
* Returns null if not specified.
*
* @return bool|int|float|string|array|null
*
* @psalm-return scalar|array<scalar>|null
* @return scalar|array<scalar>|null
*/
public function getConstant(string $name)
{
Expand Down Expand Up @@ -536,9 +518,7 @@ public function getReflectionConstant(string $name) : ?ReflectionClassConstant
* Get an associative array of only the constants for this specific class (i.e. do not search
* up parent classes etc.), with keys as constant names and values as {@see ReflectionClassConstant} objects.
*
* @return ReflectionClassConstant[] indexed by name
*
* @psalm-return array<string, ReflectionClassConstant>
* @return array<string, ReflectionClassConstant> indexed by name
*/
public function getImmediateReflectionConstants() : array
{
Expand Down Expand Up @@ -582,9 +562,7 @@ static function (ReflectionClassConstant $constant) : string {
* Get an associative array of the defined constants in this class,
* with keys as constant names and values as {@see ReflectionClassConstant} objects.
*
* @return ReflectionClassConstant[] indexed by name
*
* @psalm-return array<string, ReflectionClassConstant>
* @return array<string, ReflectionClassConstant> indexed by name
*/
public function getReflectionConstants() : array
{
Expand Down Expand Up @@ -651,9 +629,7 @@ public function getConstructor() : ReflectionMethod
*
* @see ReflectionClass::getProperties() for the usage of filter
*
* @return ReflectionProperty[]
*
* @psalm-return array<string, ReflectionProperty>
* @return array<string, ReflectionProperty>
*/
public function getImmediateProperties(?int $filter = null) : array
{
Expand Down Expand Up @@ -704,9 +680,7 @@ static function (ReflectionProperty $property) use ($filter) : bool {
* For example if $filter = \ReflectionProperty::IS_STATIC | \ReflectionProperty::IS_PUBLIC
* only the static public properties will be returned
*
* @return ReflectionProperty[]
*
* @psalm-return array<string, ReflectionProperty>
* @return array<string, ReflectionProperty>
*/
public function getProperties(?int $filter = null) : array
{
Expand Down Expand Up @@ -783,7 +757,7 @@ public function hasProperty(string $name) : bool
}

/**
* @psalm-return array<string, scalar|array<scalar>|null>
* @return array<string, scalar|array<scalar>|null>
*/
public function getDefaultProperties() : array
{
Expand Down Expand Up @@ -859,9 +833,7 @@ public function getParentClass() : ?ReflectionClass
/**
* Gets the parent class names.
*
* @return string[] A numerical array with parent class names as the values.
*
* @psalm-return list<class-string>
* @return list<class-string> A numerical array with parent class names as the values.
*/
public function getParentClassNames() : array
{
Expand Down Expand Up @@ -945,9 +917,7 @@ public function isInterface() : bool
* Get the traits used, if any are defined. If this class does not have any
* defined traits, this will return an empty array.
*
* @return ReflectionClass[]
*
* @psalm-return list<ReflectionClass>
* @return list<ReflectionClass>
*/
public function getTraits() : array
{
Expand Down Expand Up @@ -1116,10 +1086,8 @@ private function methodHash(string $className, string $methodName) : string
*
* @link https://php.net/manual/en/reflectionclass.getinterfaces.php
*
* @return ReflectionClass[] An associative array of interfaces, with keys as interface names and the array
* values as {@see ReflectionClass} objects.
*
* @psalm-return array<string, ReflectionClass>
* @return array<string, ReflectionClass> An associative array of interfaces, with keys as interface names and the array
* values as {@see ReflectionClass} objects.
*/
public function getInterfaces() : array
{
Expand All @@ -1135,9 +1103,7 @@ static function (self $reflectionClass) : array {
* Get only the interfaces that this class implements (i.e. do not search
* up parent classes etc.)
*
* @return ReflectionClass[]
*
* @psalm-return array<string, ReflectionClass>
* @return array<string, ReflectionClass>
*/
public function getImmediateInterfaces() : array
{
Expand All @@ -1149,9 +1115,7 @@ public function getImmediateInterfaces() : array
*
* @link https://php.net/manual/en/reflectionclass.getinterfacenames.php
*
* @return string[] A numerical array with interface names as the values.
*
* @psalm-return list<string>
* @return list<string> A numerical array with interface names as the values.
*/
public function getInterfaceNames() : array
{
Expand Down Expand Up @@ -1273,9 +1237,7 @@ public function isIterateable() : bool
}

/**
* @return ReflectionClass[] indexed by interface name
*
* @psalm-return array<string, ReflectionClass>
* @return array<string, ReflectionClass>
*/
private function getCurrentClassImplementedInterfacesIndexedByName() : array
{
Expand Down Expand Up @@ -1316,11 +1278,9 @@ private function getInheritanceClassHierarchy() : array
/**
* This method allows us to retrieve all interfaces parent of the this interface. Do not use on class nodes!
*
* @return ReflectionClass[] parent interfaces of this interface
* @return array<string, ReflectionClass> parent interfaces of this interface
*
* @throws NotAnInterfaceReflection
*
* @psalm-return array<string, ReflectionClass>
*/
private function getInterfacesHierarchy() : array
{
Expand Down
9 changes: 2 additions & 7 deletions src/Reflection/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class ReflectionClassConstant
/** @var bool */
private $valueWasCached = false;

/**
* @var bool|int|float|string|array<bool|int|float|string>|null const value
* @psalm-var scalar|array<scalar>|null
*/
/** @var scalar|array<scalar>|null const value */
private $value;

/** @var Reflector */
Expand Down Expand Up @@ -74,9 +71,7 @@ public function getName() : string
/**
* Returns constant value
*
* @return bool|int|float|string|array|null
*
* @psalm-return scalar|array<scalar>|null
* @return scalar|array<scalar>|null
*/
public function getValue()
{
Expand Down
9 changes: 2 additions & 7 deletions src/Reflection/ReflectionConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ class ReflectionConstant implements Reflection
/** @var int|null */
private $positionInNode;

/**
* @var bool|int|float|string|array<bool|int|float|string>|null const value
* @psalm-var scalar|array<scalar>|null
*/
/** @var scalar|array<scalar>|null const value */
private $value;

/** @var bool */
Expand Down Expand Up @@ -213,9 +210,7 @@ public function isUserDefined() : bool
/**
* Returns constant value
*
* @return bool|int|float|string|array|null
*
* @psalm-return scalar|array<scalar>|null
* @return scalar|array<scalar>|null
*/
public function getValue()
{
Expand Down
4 changes: 1 addition & 3 deletions src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ static function (ReflectionParameter $p) : bool {
* Get an array list of the parameters for this method signature, as an
* array of ReflectionParameter instances.
*
* @return ReflectionParameter[]
*
* @psalm-return list<ReflectionParameter>
* @return list<ReflectionParameter>
*/
public function getParameters() : array
{
Expand Down
4 changes: 1 addition & 3 deletions src/Reflection/ReflectionObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public static function createFromInstance($object) : ReflectionClass
*
* @see ReflectionClass::getProperties() for the usage of $filter
*
* @return ReflectionProperty[]
*
* @psalm-return array<string, ReflectionProperty>
* @return array<string, ReflectionProperty>
*/
private function getRuntimeProperties(?int $filter = null) : array
{
Expand Down
Loading

0 comments on commit aa017e6

Please sign in to comment.