Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,677 changes: 31 additions & 1,646 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/Rules/Arrays/AppendedArrayItemTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
use PhpParser\Node\Expr\AssignOp;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ArrayType;
use PHPStan\Type\VerbosityLevel;

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

Expand All @@ -34,11 +38,6 @@ public function getNodeType(): string
return \PhpParser\Node\Expr::class;
}

/**
* @param \PhpParser\Node\Expr $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if (
Expand Down Expand Up @@ -79,11 +78,11 @@ public function processNode(\PhpParser\Node $node, Scope $scope): array
if (!$this->ruleLevelHelper->accepts($itemType, $assignedValueType, $scope->isDeclareStrictTypes())) {
$verbosityLevel = $itemType->isCallable()->and($assignedValueType->isCallable())->yes() ? VerbosityLevel::value() : VerbosityLevel::typeOnly();
return [
sprintf(
RuleErrorBuilder::message(sprintf(
'Array (%s) does not accept %s.',
$assignedToType->describe($verbosityLevel),
$assignedValueType->describe($verbosityLevel)
),
))->build(),
];
}

Expand Down
13 changes: 6 additions & 7 deletions src/Rules/Arrays/AppendedArrayKeyTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
use PhpParser\Node\Expr\Assign;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\Assign>
*/
class AppendedArrayKeyTypeRule implements \PHPStan\Rules\Rule
{

Expand All @@ -34,11 +38,6 @@ public function getNodeType(): string
return Assign::class;
}

/**
* @param \PhpParser\Node\Expr\Assign $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if (!($node->var instanceof ArrayDimFetch)) {
Expand Down Expand Up @@ -80,11 +79,11 @@ public function processNode(\PhpParser\Node $node, Scope $scope): array

if (!$arrayType->getIterableKeyType()->isSuperTypeOf($keyType)->yes()) {
return [
sprintf(
RuleErrorBuilder::message(sprintf(
'Array (%s) does not accept key %s.',
$arrayType->describe(VerbosityLevel::typeOnly()),
$keyType->describe(VerbosityLevel::value())
),
))->build(),
];
}

Expand Down
11 changes: 5 additions & 6 deletions src/Rules/Arrays/DeadForeachRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Foreach_>
*/
class DeadForeachRule implements Rule
{

Expand All @@ -14,11 +18,6 @@ public function getNodeType(): string
return Node\Stmt\Foreach_::class;
}

/**
* @param \PhpParser\Node\Stmt\Foreach_ $node
* @param Scope $scope
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
$iterableType = $scope->getType($node->expr);
Expand All @@ -31,7 +30,7 @@ public function processNode(Node $node, Scope $scope): array
}

return [
'Empty array passed to foreach.',
RuleErrorBuilder::message('Empty array passed to foreach.')->build(),
];
}

Expand Down
9 changes: 3 additions & 6 deletions src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use PHPStan\Analyser\Scope;
use PHPStan\Node\LiteralArrayNode;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ConstantScalarType;

/**
* @implements \PHPStan\Rules\Rule<\PHPStan\Node\LiteralArrayNode>
*/
class DuplicateKeysInLiteralArraysRule implements \PHPStan\Rules\Rule
{

Expand All @@ -26,11 +28,6 @@ public function getNodeType(): string
return LiteralArrayNode::class;
}

/**
* @param LiteralArrayNode $node
* @param \PHPStan\Analyser\Scope $scope
* @return RuleError[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
$values = [];
Expand Down
17 changes: 10 additions & 7 deletions src/Rules/Arrays/InvalidKeyInArrayDimFetchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace PHPStan\Rules\Arrays;

use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\MixedType;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\ArrayDimFetch>
*/
class InvalidKeyInArrayDimFetchRule implements \PHPStan\Rules\Rule
{

Expand All @@ -23,11 +27,6 @@ public function getNodeType(): string
return \PhpParser\Node\Expr\ArrayDimFetch::class;
}

/**
* @param \PhpParser\Node\Expr\ArrayDimFetch $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if ($node->dim === null) {
Expand All @@ -43,11 +42,15 @@ public function processNode(\PhpParser\Node $node, Scope $scope): array
$isSuperType = AllowedArrayKeysTypes::getType()->isSuperTypeOf($dimensionType);
if ($isSuperType->no()) {
return [
sprintf('Invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly())),
RuleErrorBuilder::message(
sprintf('Invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly()))
)->build(),
];
} elseif ($this->reportMaybes && $isSuperType->maybe() && !$dimensionType instanceof MixedType) {
return [
sprintf('Possibly invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly())),
RuleErrorBuilder::message(
sprintf('Possibly invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly()))
)->build(),
];
}

Expand Down
17 changes: 10 additions & 7 deletions src/Rules/Arrays/InvalidKeyInArrayItemRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
namespace PHPStan\Rules\Arrays;

use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\MixedType;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\ArrayItem>
*/
class InvalidKeyInArrayItemRule implements \PHPStan\Rules\Rule
{

Expand All @@ -22,11 +26,6 @@ public function getNodeType(): string
return \PhpParser\Node\Expr\ArrayItem::class;
}

/**
* @param \PhpParser\Node\Expr\ArrayItem $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if ($node->key === null) {
Expand All @@ -37,11 +36,15 @@ public function processNode(\PhpParser\Node $node, Scope $scope): array
$isSuperType = AllowedArrayKeysTypes::getType()->isSuperTypeOf($dimensionType);
if ($isSuperType->no()) {
return [
sprintf('Invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly())),
RuleErrorBuilder::message(
sprintf('Invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly()))
)->build(),
];
} elseif ($this->reportMaybes && $isSuperType->maybe() && !$dimensionType instanceof MixedType) {
return [
sprintf('Possibly invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly())),
RuleErrorBuilder::message(
sprintf('Possibly invalid array key type %s.', $dimensionType->describe(VerbosityLevel::typeOnly()))
)->build(),
];
}

Expand Down
9 changes: 3 additions & 6 deletions src/Rules/Arrays/IterableInForeachRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Foreach_>
*/
class IterableInForeachRule implements \PHPStan\Rules\Rule
{

Expand All @@ -27,11 +29,6 @@ public function getNodeType(): string
return \PhpParser\Node\Stmt\Foreach_::class;
}

/**
* @param \PhpParser\Node\Stmt\Foreach_ $node
* @param \PHPStan\Analyser\Scope $scope
* @return RuleError[]
*/
public function processNode(Node $node, Scope $scope): array
{
$typeResult = $this->ruleLevelHelper->findTypeToCheck(
Expand Down
9 changes: 3 additions & 6 deletions src/Rules/Arrays/NonexistentOffsetInArrayDimFetchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PHPStan\Rules\Arrays;

use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
Expand All @@ -12,6 +11,9 @@
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\ArrayDimFetch>
*/
class NonexistentOffsetInArrayDimFetchRule implements \PHPStan\Rules\Rule
{

Expand All @@ -35,11 +37,6 @@ public function getNodeType(): string
return \PhpParser\Node\Expr\ArrayDimFetch::class;
}

/**
* @param \PhpParser\Node\Expr\ArrayDimFetch $node
* @param \PHPStan\Analyser\Scope $scope
* @return RuleError[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if ($node->dim !== null) {
Expand Down
31 changes: 17 additions & 14 deletions src/Rules/Arrays/OffsetAccessAssignOpRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use PhpParser\Node\Expr\ArrayDimFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\AssignOp>
*/
class OffsetAccessAssignOpRule implements \PHPStan\Rules\Rule
{

Expand All @@ -26,11 +30,6 @@ public function getNodeType(): string
return \PhpParser\Node\Expr\AssignOp::class;
}

/**
* @param \PhpParser\Node\Expr\AssignOp $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[]
*/
public function processNode(\PhpParser\Node $node, Scope $scope): array
{
if (!$node->var instanceof ArrayDimFetch) {
Expand Down Expand Up @@ -79,17 +78,21 @@ static function (Type $dimType) use ($varType): bool {
}

if ($dimType === null) {
return [sprintf(
'Cannot assign new offset to %s.',
$varType->describe(VerbosityLevel::typeOnly())
)];
return [
RuleErrorBuilder::message(sprintf(
'Cannot assign new offset to %s.',
$varType->describe(VerbosityLevel::typeOnly())
))->build(),
];
}

return [sprintf(
'Cannot assign offset %s to %s.',
$dimType->describe(VerbosityLevel::value()),
$varType->describe(VerbosityLevel::typeOnly())
)];
return [
RuleErrorBuilder::message(sprintf(
'Cannot assign offset %s to %s.',
$dimType->describe(VerbosityLevel::value()),
$varType->describe(VerbosityLevel::typeOnly())
))->build(),
];
}

}
Loading