diff --git a/phpstan.neon b/phpstan.neon index d7f8277..eab1b77 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 6 + level: 7 paths: - src diff --git a/src/Main.php b/src/Main.php index 305a2ad..6f9a96c 100644 --- a/src/Main.php +++ b/src/Main.php @@ -51,7 +51,7 @@ private function findEntries(Finder $finder): array foreach ($finder as $file) { try { $reflections = PhpReader::parseFile( - realpath($this->directory), + (string)realpath($this->directory), $file->getRealPath(), $this->options ); diff --git a/src/Php/PhpAccessModifier.php b/src/Php/PhpAccessModifier.php index 3e72f0b..7c8f8c6 100644 --- a/src/Php/PhpAccessModifier.php +++ b/src/Php/PhpAccessModifier.php @@ -24,15 +24,15 @@ final class PhpAccessModifier public function __construct(ClassConst|Property|ClassMethod|Param $stmt) { if ($stmt instanceof Param) { - $this->public = boolval($stmt->flags & Class_::MODIFIER_PUBLIC); - $this->protected = boolval($stmt->flags & Class_::MODIFIER_PROTECTED); - $this->private = boolval($stmt->flags & Class_::MODIFIER_PRIVATE); + $this->public = (bool)($stmt->flags & Class_::MODIFIER_PUBLIC); + $this->protected = (bool)($stmt->flags & Class_::MODIFIER_PROTECTED); + $this->private = (bool)($stmt->flags & Class_::MODIFIER_PRIVATE); } else { $this->public = $stmt->isPublic(); $this->protected = $stmt->isProtected(); $this->private = $stmt->isPrivate(); - $this->static = $stmt->isStatic(); if ($stmt instanceof ClassMethod) { + $this->static = $stmt->isStatic(); $this->abstract = $stmt->isAbstract(); } } diff --git a/src/Php/PhpClass.php b/src/Php/PhpClass.php index b7f0e6f..e9e2607 100644 --- a/src/Php/PhpClass.php +++ b/src/Php/PhpClass.php @@ -4,6 +4,7 @@ namespace Smeghead\PhpClassDiagram\Php; +use PhpParser\Node; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\{ Namespace_, @@ -21,14 +22,14 @@ final class PhpClass { - /** @var string[] directory parts */ + /** @var list directory parts */ private array $dirs; private ClassLike $syntax; - /** @var \PhpParser\Node[] */ + /** @var list */ private array $full; /** - * @param \PhpParser\Node[] $full + * @param list $full */ public function __construct(string $filename, ClassLike $syntax, array $full) { @@ -36,7 +37,8 @@ public function __construct(string $filename, ClassLike $syntax, array $full) if ($relativePath === '.') { $dirs = []; } else { - $dirs = preg_split('/[\\\\\/]/', $relativePath); + /** @var list $dirs */ + $dirs = (array)preg_split('/[\\\\\/]/', $relativePath); } $this->dirs = $dirs; $this->syntax = $syntax; @@ -124,7 +126,7 @@ public function getUses(): array } /** - * @param \PhpParser\Node[] $stmts Stmts + * @param list $stmts Stmts * @param PhpType[] $uses * @return PhpType[] */ @@ -180,7 +182,7 @@ public function getExtends(): array $extends[] = new PhpType( array_slice($extend->parts, 0, count($extend->parts) - 1), '', - end($extend->parts) + (string)end($extend->parts) ); } } @@ -191,7 +193,7 @@ public function getExtends(): array $extends[] = new PhpType( array_slice($implement->parts, 0, count($implement->parts) - 1), '', - end($implement->parts) + (string)end($implement->parts) ); } } @@ -218,16 +220,21 @@ public function getEnumCases(): array public function getDescription(): string { - $doc = new PhpDocComment($this->syntax); - return $doc->getDescription(); + return (new PhpDocComment($this->syntax)) + ->getDescription(); } /** - * @return PhpType[] using types. + * @return list */ public function getUsingTypes(): array { $finder = new FindUsePhpTypes($this->syntax); - return array_map(fn(FullyQualified $x) => new PhpType(array_slice($x->parts, 0, count($x->parts) - 1), '', end($x->parts)), $finder->collectTypes()); + return array_map( + fn(FullyQualified $x) => new PhpType( + array_slice($x->parts, 0, count($x->parts) - 1), '', (string)end($x->parts) + ), + $finder->collectTypes() + ); } } diff --git a/src/Php/PhpMethod.php b/src/Php/PhpMethod.php index 62f36f8..97547cc 100644 --- a/src/Php/PhpMethod.php +++ b/src/Php/PhpMethod.php @@ -22,8 +22,16 @@ final class PhpMethod public function __construct(ClassMethod $method, PhpClass $class) { $params = array_map(function (Param $x) use ($class, $method) { - $type = PhpTypeExpression::buildByMethodParam($x, $class->getNamespace(), $method, $x->var->name, $class->getUses()); - return new PhpMethodParameter($x->var->name, $type); + /** @var string $varName */ + $varName = $x->var->name; /** @phpstan-ignore-line */ + $type = PhpTypeExpression::buildByMethodParam( + $x, + $class->getNamespace(), + $method, + $varName, + $class->getUses() + ); + return new PhpMethodParameter($varName, $type); }, $method->getParams()); $this->name = $method->name->toString(); $this->type = $this->getTypeFromMethod($method, $class); diff --git a/src/Php/PhpProperty.php b/src/Php/PhpProperty.php index d1852f3..557afa2 100644 --- a/src/Php/PhpProperty.php +++ b/src/Php/PhpProperty.php @@ -32,8 +32,16 @@ public static function buildByProperty(Property $p, PhpClass $class): self public static function buildByParam(Param $param, ClassMethod $method, PhpClass $class): self { $instance = new self(); - $instance->name = $param->var->name; - $instance->type = PhpTypeExpression::buildByMethodParam($param, $class->getNamespace(), $method, $param->var->name, $class->getUses()); + /** @var string $varName */ + $varName = $param->var->name; // @phpstan-ignore-line + $instance->name = $varName; + $instance->type = PhpTypeExpression::buildByMethodParam( + $param, + $class->getNamespace(), + $method, + $varName, + $class->getUses() + ); $instance->accessModifier = new PhpAccessModifier($param); return $instance; } diff --git a/src/Php/PhpReader.php b/src/Php/PhpReader.php index cb57161..c6d8be3 100644 --- a/src/Php/PhpReader.php +++ b/src/Php/PhpReader.php @@ -31,7 +31,7 @@ public function getInfo(): PhpClass */ public static function parseFile(string $directory, string $filename, Options $options): array { - $code = file_get_contents($filename); + $code = (string)file_get_contents($filename); $targetVersion = match ($options->phpVersion()) { 'php5' => ParserFactory::PREFER_PHP5, diff --git a/src/Php/PhpTypeExpression.php b/src/Php/PhpTypeExpression.php index ecbea1e..b3a1707 100644 --- a/src/Php/PhpTypeExpression.php +++ b/src/Php/PhpTypeExpression.php @@ -194,8 +194,16 @@ private function parseType(Property|Identifier|NullableType|Name|UnionType|Inter } } } + /** @var list $parts */ $typeName = array_pop($parts); - return new PhpType($parts, empty($type) ? '' : $type->getType(), $typeName ?? '', null, $nullable); + + return new PhpType( + namespace: $parts, + meta: empty($type) ? '' : $type->getType(), + name: $typeName ?? '', + alias: null, + nullable: $nullable + ); } /**