Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more precise list<type> instead of type[] where possible #214

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
CallParamConfig: 'array<int|string, int|bool|string|array{position:int, value?:int|bool|string, name?:string}>'
CallParamAnyValueConfig: 'array<int|string, int|array{position:int, value?:int|bool|string, name?:string}>'
CallParamFlagAnyValueConfig: 'array<int|string, int|array{position:int, value?:int, name?:string}>'
AllowDirectives: 'allowIn?:string[], allowExceptIn?:string[], disallowIn?:string[], allowInFunctions?:string[], allowInMethods?:string[], allowExceptInFunctions?:string[], allowExceptInMethods?:string[], disallowInFunctions?:string[], disallowInMethods?:string[], allowParamsInAllowed?:CallParamConfig, allowParamsInAllowedAnyValue?:CallParamAnyValueConfig, allowParamFlagsInAllowed?:CallParamFlagAnyValueConfig, allowParamsAnywhere?:CallParamConfig, allowParamsAnywhereAnyValue?:CallParamAnyValueConfig, allowParamFlagsAnywhere?:CallParamFlagAnyValueConfig, allowExceptParamsInAllowed?:CallParamConfig, allowExceptParamFlagsInAllowed?:CallParamFlagAnyValueConfig, disallowParamFlagsInAllowed?:CallParamFlagAnyValueConfig, disallowParamsInAllowed?:CallParamConfig, allowExceptParams?:CallParamConfig, disallowParams?:CallParamConfig, allowExceptParamFlags?:CallParamFlagAnyValueConfig, disallowParamFlags?:CallParamFlagAnyValueConfig, allowExceptCaseInsensitiveParams?:CallParamConfig, disallowCaseInsensitiveParams?:CallParamConfig'
AllowDirectives: 'allowIn?:list<string>, allowExceptIn?:list<string>, disallowIn?:list<string>, allowInFunctions?:list<string>, allowInMethods?:list<string>, allowExceptInFunctions?:list<string>, allowExceptInMethods?:list<string>, disallowInFunctions?:list<string>, disallowInMethods?:list<string>, allowParamsInAllowed?:CallParamConfig, allowParamsInAllowedAnyValue?:CallParamAnyValueConfig, allowParamFlagsInAllowed?:CallParamFlagAnyValueConfig, allowParamsAnywhere?:CallParamConfig, allowParamsAnywhereAnyValue?:CallParamAnyValueConfig, allowParamFlagsAnywhere?:CallParamFlagAnyValueConfig, allowExceptParamsInAllowed?:CallParamConfig, allowExceptParamFlagsInAllowed?:CallParamFlagAnyValueConfig, disallowParamFlagsInAllowed?:CallParamFlagAnyValueConfig, disallowParamsInAllowed?:CallParamConfig, allowExceptParams?:CallParamConfig, disallowParams?:CallParamConfig, allowExceptParamFlags?:CallParamFlagAnyValueConfig, disallowParamFlags?:CallParamFlagAnyValueConfig, allowExceptCaseInsensitiveParams?:CallParamConfig, disallowCaseInsensitiveParams?:CallParamConfig'
ForbiddenCallsConfig: 'array<array{function?:string|list<string>, method?:string|list<string>, exclude?:string|list<string>, definedIn?:string|list<string>, message?:string, %typeAliases.AllowDirectives%, errorIdentifier?:string, errorTip?:string}>'
DisallowedAttributesConfig: 'array<array{attribute:string|list<string>, exclude?:string|list<string>, message?:string, %typeAliases.AllowDirectives%, errorIdentifier?:string, errorTip?:string}>'
AllowDirectivesConfig: 'array{%typeAliases.AllowDirectives%}'
Expand Down
24 changes: 12 additions & 12 deletions src/Allowed/AllowedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
class AllowedConfig
{

/** @var string[] */
/** @var list<string> */
private $allowIn;

/** @var string[] */
/** @var list<string> */
private $allowExceptIn;

/** @var string[] */
/** @var list<string> */
private $allowInCalls;

/** @var string[] */
/** @var list<string> */
private $allowExceptInCalls;

/** @var array<int|string, Param> */
Expand All @@ -34,10 +34,10 @@ class AllowedConfig


/**
* @param string[] $allowIn
* @param string[] $allowExceptIn
* @param string[] $allowInCalls
* @param string[] $allowExceptInCalls
* @param list<string> $allowIn
* @param list<string> $allowExceptIn
* @param list<string> $allowInCalls
* @param list<string> $allowExceptInCalls
* @param array<int|string, Param> $allowParamsInAllowed
* @param array<int|string, Param> $allowParamsAnywhere
* @param array<int|string, Param> $allowExceptParamsInAllowed
Expand Down Expand Up @@ -65,7 +65,7 @@ public function __construct(


/**
* @return string[]
* @return list<string>
*/
public function getAllowIn(): array
{
Expand All @@ -74,7 +74,7 @@ public function getAllowIn(): array


/**
* @return string[]
* @return list<string>
*/
public function getAllowExceptIn(): array
{
Expand All @@ -83,7 +83,7 @@ public function getAllowExceptIn(): array


/**
* @return string[]
* @return list<string>
*/
public function getAllowInCalls(): array
{
Expand All @@ -92,7 +92,7 @@ public function getAllowInCalls(): array


/**
* @return string[]
* @return list<string>
*/
public function getAllowExceptInCalls(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/EchoCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EchoCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
/**
* @param Echo_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/EmptyCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EmptyCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
/**
* @param Empty_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/EvalCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EvalCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
/**
* @param Eval_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/ExitDieCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ExitDieCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
/**
* @param Exit_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/FunctionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FunctionCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;

/** @var ReflectionProvider */
Expand Down Expand Up @@ -60,7 +60,7 @@ public function getNodeType(): string
/**
* @param FuncCall $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/MethodCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MethodCalls implements Rule
/** @var DisallowedMethodRuleErrors */
private $disallowedMethodRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -55,7 +55,7 @@ public function getNodeType(): string
/**
* @param MethodCall $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/NewCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NewCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -56,7 +56,7 @@ public function getNodeType(): string
/**
* @param New_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/PrintCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PrintCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -53,7 +53,7 @@ public function getNodeType(): string
/**
* @param Print_ $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/ShellExecCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ShellExecCalls implements Rule
/** @var DisallowedCallsRuleErrors */
private $disallowedCallsRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -57,7 +57,7 @@ public function getNodeType(): string
/**
* @param ShellExec $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
4 changes: 2 additions & 2 deletions src/Calls/StaticCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StaticCalls implements Rule
/** @var DisallowedMethodRuleErrors */
private $disallowedMethodRuleErrors;

/** @var DisallowedCall[] */
/** @var list<DisallowedCall> */
private $disallowedCalls;


Expand Down Expand Up @@ -55,7 +55,7 @@ public function getNodeType(): string
/**
* @param StaticCall $node
* @param Scope $scope
* @return RuleError[]
* @return list<RuleError>
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
Expand Down
8 changes: 4 additions & 4 deletions src/Disallowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ interface Disallowed
{

/**
* @return string[]
* @return list<string>
*/
public function getAllowIn(): array;


/**
* @return string[]
* @return list<string>
*/
public function getAllowExceptIn(): array;


/**
* @return string[]
* @return list<string>
*/
public function getAllowInCalls(): array;


/**
* @return string[]
* @return list<string>
*/
public function getAllowExceptInCalls(): array;

Expand Down
2 changes: 1 addition & 1 deletion src/DisallowedAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(Allowed $allowed, Normalizer $normalizer)
/**
* @param array $config
* @phpstan-param DisallowedAttributesConfig $config
* @return DisallowedAttribute[]
* @return list<DisallowedAttribute>
* @throws UnsupportedParamTypeInConfigException
*/
public function createFromConfig(array $config): array
Expand Down
2 changes: 1 addition & 1 deletion src/DisallowedCallFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Formatter $formatter, Normalizer $normalizer, Allowe
* @param array $config
* @phpstan-param ForbiddenCallsConfig $config
* @noinspection PhpUndefinedClassInspection ForbiddenCallsConfig is a type alias defined in PHPStan config
* @return DisallowedCall[]
* @return list<DisallowedCall>
* @throws ShouldNotHappenException
*/
public function createFromConfig(array $config): array
Expand Down
8 changes: 4 additions & 4 deletions src/DisallowedConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class DisallowedConstant implements Disallowed
/** @var string|null */
private $message;

/** @var string[] */
/** @var list<string> */
private $allowIn;

/** @var string[] */
/** @var list<string> */
private $allowExceptIn;

/** @var string|null */
Expand All @@ -30,8 +30,8 @@ class DisallowedConstant implements Disallowed
/**
* @param string $constant
* @param string|null $message
* @param string[] $allowIn
* @param string[] $allowExceptIn
* @param list<string> $allowIn
* @param list<string> $allowExceptIn
* @param string|null $errorIdentifier
* @param string|null $errorTip
*/
Expand Down
4 changes: 2 additions & 2 deletions src/DisallowedConstantFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function __construct(Normalizer $normalizer)


/**
* @param array<array{class?:string, constant?:string, message?:string, allowIn?:string[], allowExceptIn?:string[], disallowIn?:string[], errorIdentifier?:string, errorTip?:string}> $config
* @return DisallowedConstant[]
* @param array<array{class?:string, constant?:string, message?:string, allowIn?:list<string>, allowExceptIn?:list<string>, disallowIn?:list<string>, errorIdentifier?:string, errorTip?:string}> $config
* @return list<DisallowedConstant>
* @throws ShouldNotHappenException
*/
public function createFromConfig(array $config): array
Expand Down
8 changes: 4 additions & 4 deletions src/DisallowedNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class DisallowedNamespace implements Disallowed
/** @var string|null */
private $message;

/** @var string[] */
/** @var list<string> */
private $allowIn;

/** @var string[] */
/** @var list<string> */
private $allowExceptIn;

/** @var string|null */
Expand All @@ -34,8 +34,8 @@ class DisallowedNamespace implements Disallowed
* @param string $namespace
* @param list<string> $excludes
* @param string|null $message
* @param string[] $allowIn
* @param string[] $allowExceptIn
* @param list<string> $allowIn
* @param list<string> $allowExceptIn
* @param string|null $errorIdentifier
* @param string|null $errorTip
*/
Expand Down
4 changes: 2 additions & 2 deletions src/DisallowedNamespaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function __construct(Normalizer $normalizer)


/**
* @param array<array{namespace?:string, class?:string, exclude?:string|list<string>, message?:string, allowIn?:string[], allowExceptIn?:string[], disallowIn?:string[], errorIdentifier?:string, errorTip?:string}> $config
* @return DisallowedNamespace[]
* @param array<array{namespace?:string, class?:string, exclude?:string|list<string>, message?:string, allowIn?:list<string>, allowExceptIn?:list<string>, disallowIn?:list<string>, errorIdentifier?:string, errorTip?:string}> $config
* @return list<DisallowedNamespace>
*/
public function createFromConfig(array $config): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/DisallowedSuperglobalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class DisallowedSuperglobalFactory implements DisallowedVariableFactory


/**
* @param array<array{superglobal?:string, message?:string, allowIn?:string[], allowExceptIn?:string[], disallowIn?:string[], errorIdentifier?:string, errorTip?:string}> $config
* @return DisallowedVariable[]
* @param array<array{superglobal?:string, message?:string, allowIn?:list<string>, allowExceptIn?:list<string>, disallowIn?:list<string>, errorIdentifier?:string, errorTip?:string}> $config
* @return list<DisallowedVariable>
* @throws ShouldNotHappenException
*/
public function getDisallowedVariables(array $config): array
Expand Down