Skip to content

Commit

Permalink
Merge pull request #154 from sascha-egerer/add-type-declarations
Browse files Browse the repository at this point in the history
[TASK] Use Type declarations and remove redundant docblocks
  • Loading branch information
sascha-egerer authored Feb 9, 2024
2 parents b73c577 + df4ccc3 commit 947b026
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 100 deletions.
19 changes: 9 additions & 10 deletions src/Reflection/RepositoryCountByMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\IntegerType;
Expand All @@ -15,11 +16,9 @@
class RepositoryCountByMethodReflection implements MethodReflection
{

/** @var \PHPStan\Reflection\ClassReflection */
private $classReflection;
private ClassReflection $classReflection;

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

public function __construct(ClassReflection $classReflection, string $name)
{
Expand Down Expand Up @@ -76,7 +75,7 @@ public function getReturnType(): Type
}

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
* @return ParametersAcceptor[]
*/
public function getVariants(): array
{
Expand All @@ -96,7 +95,7 @@ public function getDocComment(): ?string
return null;
}

public function isDeprecated(): \PHPStan\TrinaryLogic
public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
Expand All @@ -106,22 +105,22 @@ public function getDeprecatedDescription(): ?string
return null;
}

public function isFinal(): \PHPStan\TrinaryLogic
public function isFinal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function isInternal(): \PHPStan\TrinaryLogic
public function isInternal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function getThrowType(): ?\PHPStan\Type\Type
public function getThrowType(): ?Type
{
return null;
}

public function hasSideEffects(): \PHPStan\TrinaryLogic
public function hasSideEffects(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class RepositoryCountByMethodsClassReflectionExtension implements MethodsClassRe

use Typo3ClassNamingUtilityTrait;

/** @var ReflectionProvider */
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(ReflectionProvider $reflectionProvider)
{
Expand Down
6 changes: 2 additions & 4 deletions src/Reflection/RepositoryCountByParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
class RepositoryCountByParameterReflection implements ParameterReflection
{

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

/** @var Type */
private $type;
private Type $type;

public function __construct(string $name, Type $type)
{
Expand Down
18 changes: 9 additions & 9 deletions src/Reflection/RepositoryFindByMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use SaschaEgerer\PhpstanTypo3\Helpers\Typo3ClassNamingUtilityTrait;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

Expand All @@ -19,14 +22,11 @@ class RepositoryFindByMethodReflection implements MethodReflection

use Typo3ClassNamingUtilityTrait;

/** @var \PHPStan\Reflection\ClassReflection */
private $classReflection;
private ClassReflection $classReflection;

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

/** @var ReflectionProvider */
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(ClassReflection $classReflection, string $name, ReflectionProvider $reflectionProvider)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public function getParameters(): array
if ($modelReflection->hasNativeProperty($this->getPropertyName())) {
$type = $modelReflection->getNativeProperty($this->getPropertyName())->getReadableType();
} else {
$type = new \PHPStan\Type\MixedType(\false);
$type = new MixedType(\false);
}

return [
Expand All @@ -108,7 +108,7 @@ public function getReturnType(): GenericObjectType
}

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
* @return ParametersAcceptor[]
*/
public function getVariants(): array
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public function isInternal(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function getThrowType(): ?\PHPStan\Type\Type
public function getThrowType(): ?Type
{
return null;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Reflection/RepositoryFindByParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
class RepositoryFindByParameterReflection implements ParameterReflection
{

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

/** @var Type */
private $type;
private Type $type;

public function __construct(string $name, Type $type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class RepositoryFindMethodsClassReflectionExtension implements MethodsClassRefle

use Typo3ClassNamingUtilityTrait;

/** @var ReflectionProvider $reflectionProvider */
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(
ReflectionProvider $reflectionProvider
Expand Down
22 changes: 10 additions & 12 deletions src/Reflection/RepositoryFindOneByMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
Expand All @@ -19,14 +20,11 @@ class RepositoryFindOneByMethodReflection implements MethodReflection

use Typo3ClassNamingUtilityTrait;

/** @var \PHPStan\Reflection\ClassReflection */
private $classReflection;
private ClassReflection $classReflection;

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

/** @var ReflectionProvider */
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(ClassReflection $classReflection, string $name, ReflectionProvider $reflectionProvider)
{
Expand Down Expand Up @@ -105,7 +103,7 @@ public function getReturnType(): Type
}

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
* @return ParametersAcceptor[]
*/
public function getVariants(): array
{
Expand All @@ -125,7 +123,7 @@ public function getDocComment(): ?string
return null;
}

public function isDeprecated(): \PHPStan\TrinaryLogic
public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
Expand All @@ -135,22 +133,22 @@ public function getDeprecatedDescription(): ?string
return null;
}

public function isFinal(): \PHPStan\TrinaryLogic
public function isFinal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function isInternal(): \PHPStan\TrinaryLogic
public function isInternal(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function getThrowType(): ?\PHPStan\Type\Type
public function getThrowType(): ?Type
{
return null;
}

public function hasSideEffects(): \PHPStan\TrinaryLogic
public function hasSideEffects(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
Expand Down
20 changes: 13 additions & 7 deletions src/Rule/ContextAspectValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
namespace SaschaEgerer\PhpstanTypo3\Rule;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use TYPO3\CMS\Core\Context\Context;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\MethodCall>
* @implements Rule<MethodCall>
*/
class ContextAspectValidationRule implements \PHPStan\Rules\Rule
class ContextAspectValidationRule implements Rule
{

/** @var array<string, string> */
private $contextApiGetAspectMapping;
private array $contextApiGetAspectMapping;

/**
* @param array<string, string> $contextApiGetAspectMapping
Expand All @@ -25,15 +31,15 @@ public function __construct(array $contextApiGetAspectMapping)

public function getNodeType(): string
{
return Node\Expr\MethodCall::class;
return MethodCall::class;
}

/**
* @param Node\Expr\MethodCall $node
*/
public function processNode(Node $node, Scope $scope): array
{
if (!$node->name instanceof Node\Identifier) {
if (!$node->name instanceof Identifier) {
return [];
}

Expand All @@ -49,13 +55,13 @@ public function processNode(Node $node, Scope $scope): array

$declaringClass = $methodReflection->getDeclaringClass();

if ($declaringClass->getName() !== \TYPO3\CMS\Core\Context\Context::class) {
if ($declaringClass->getName() !== Context::class) {
return [];
}

$argument = $node->getArgs()[0] ?? null;

if (!($argument instanceof Node\Arg) || !($argument->value instanceof Node\Scalar\String_)) {
if (!($argument instanceof Arg) || !($argument->value instanceof String_)) {
return [];
}

Expand Down
17 changes: 11 additions & 6 deletions src/Rule/RequestAttributeValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
namespace SaschaEgerer\PhpstanTypo3\Rule;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Psr\Http\Message\ServerRequestInterface;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\MethodCall>
* @implements Rule<MethodCall>
*/
class RequestAttributeValidationRule implements \PHPStan\Rules\Rule
class RequestAttributeValidationRule implements Rule
{

/** @var array<string, string> */
private $requestGetAttributeMapping;
private array $requestGetAttributeMapping;

/**
* @param array<string, string> $requestGetAttributeMapping
Expand All @@ -26,15 +31,15 @@ public function __construct(array $requestGetAttributeMapping)

public function getNodeType(): string
{
return Node\Expr\MethodCall::class;
return MethodCall::class;
}

/**
* @param Node\Expr\MethodCall $node
*/
public function processNode(Node $node, Scope $scope): array
{
if (!$node->name instanceof Node\Identifier) {
if (!$node->name instanceof Identifier) {
return [];
}

Expand All @@ -54,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array

$argument = $node->getArgs()[0] ?? null;

if (!($argument instanceof Node\Arg) || !($argument->value instanceof Node\Scalar\String_)) {
if (!($argument instanceof Arg) || !($argument->value instanceof String_)) {
return [];
}

Expand Down
Loading

0 comments on commit 947b026

Please sign in to comment.