Skip to content

Commit

Permalink
Fixed a lot of Psalm issues (#82)
Browse files Browse the repository at this point in the history
* Updated some complex PHPDoc, suppressed some PHPUnit test case errors

* Fixed a bunch of issues

* Fixed all InvalidReturnType and InvalidNullableReturnType errors

* Fixed typo that caused a bug

* Fixed various bugs found by Psalm, added annotations for bugs in Psalm itself

* Fixed a bunch of Psalm errors

* Fixed some more Psalm errors

* Trying to fix Psalm config

* WIP - fixed more Psalm issues, added "class-string" as PHPDoc param type where appropriate, used Psalm "templates" to give better intellisense, and cleaning up issues as a result of these changes

* Fixed more Psalm issues, added better null handling

* More Psalm fixes

* Fixed a bunch of Psalm issues

* Fixed up Closure/callable types to specify param and return types

* Fixed broke test, updated some Composer dependencies to the versions that were actually being used, switched to using Psalm 4.1@dev

* Removed Psalm from CI until issues are fixed with it
  • Loading branch information
davidbyoung committed Oct 31, 2020
1 parent 8a06e4d commit 9c8748b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/ITypeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ITypeFinder
* @param string|string[] $directories The path or list of paths of directories to search
* @param bool $recursive Whether or not we want to recurse through all directories
* @param bool $includeAbstractClasses Whether or not to include abstract classes
* @return string[] The list of all class names
* @return array<class-string> The list of all class names
* @throws InvalidArgumentException Thrown if the paths are not a string or array of strings
*/
public function findAllClasses(string|array $directories, bool $recursive = false, bool $includeAbstractClasses = false): array;
Expand All @@ -36,18 +36,18 @@ public function findAllClasses(string|array $directories, bool $recursive = fals
*
* @param string|string[] $directories The path or list of paths of directories to search
* @param bool $recursive Whether or not we want to recurse through all directories
* @return string[] The list of all interface names
* @return array<class-string> The list of all interface names
* @throws InvalidArgumentException Thrown if the paths are not a string or array of strings
*/
public function findAllInterfaces(string|array $directories, bool $recursive = false): array;

/**
* Recursively finds all sub-types of a particular type in a path
*
* @param string $parentType The type whose sub-types we're searching for
* @param class-string $parentType The type whose sub-types we're searching for
* @param string|string[] $directories The path or list of paths of directories to search
* @param bool $recursive Whether or not we want to recurse through all directories
* @return string[] The list of all types that are sub-types of the input class/interface
* @return array<class-string> The list of all types that are sub-types of the input class/interface
* @throws InvalidArgumentException Thrown if the paths are not a string or array of strings
* @throws ReflectionException Thrown if any types could not be reflected in the input directories
*/
Expand All @@ -58,7 +58,7 @@ public function findAllSubtypesOfType(string $parentType, string|array $director
*
* @param string|string[] $directories The path or list of paths of directories to search
* @param bool $recursive Whether or not we want to recurse through all directories
* @return string[] The list of all types
* @return array<class-string> The list of all types
* @throws InvalidArgumentException Thrown if the paths are not a string or array of strings
*/
public function findAllTypes(string|array $directories, bool $recursive = false): array;
Expand Down
9 changes: 6 additions & 3 deletions src/TypeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public function findAllSubtypesOfType(string $parentType, string|array $director
{
$subTypes = [];

/** @var class-string $type Need this because of a Psalm bug */
foreach ($this->findAllTypes($directories, $recursive) as $type) {
$reflectionType = new ReflectionClass($type);

/** @var class-string $parentType Need this because of a Psalm bug */
if ($reflectionType->isSubclassOf($parentType)) {
$subTypes[] = $type;
}
Expand All @@ -83,7 +85,7 @@ public function findAllTypes(string|array $directories, bool $recursive = false)
* @param string|string[] $directories The directory or directories to search through
* @param bool $recursive Whether or not we should recursively find types
* @param int $typeFilter The filter to apply (bitwise value of types defined in this class)
* @return string[] The list of types
* @return array<class-string> The list of types
*/
private function findAllTypesWithFilter(string|array $directories, bool $recursive, int $typeFilter): array
{
Expand Down Expand Up @@ -121,9 +123,9 @@ private function findAllTypesWithFilter(string|array $directories, bool $recursi
* Gets the class names from a list of tokens
* This will work even if multiple classes are defined in each file
*
* @param string[] $tokens The array of tokens
* @param array<array{0: int, 1: string, 2: int}|string> $tokens The array of tokens
* @param int $typeFilter The filter to apply (bitwise value of types defined in this class)
* @return string[] The names of the classes
* @return array<class-string> The names of the classes
*/
private function getTypeFromTokens(array $tokens, int $typeFilter): array
{
Expand Down Expand Up @@ -208,6 +210,7 @@ private function getTypeFromTokens(array $tokens, int $typeFilter): array
}
}

/** @var array<class-string> $types */
return $types;
}
}

0 comments on commit 9c8748b

Please sign in to comment.