Skip to content

Commit

Permalink
Update build-cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 4, 2024
1 parent f647999 commit f8092f9
Show file tree
Hide file tree
Showing 47 changed files with 112 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
with:
repository: "phpstan/build-cs"
path: "build-cs"
ref: "1.x"
ref: "2.x"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lint:
.PHONY: cs-install
cs-install:
git clone https://github.com/phpstan/build-cs.git || true
git -C build-cs fetch origin && git -C build-cs reset --hard origin/1.x
git -C build-cs fetch origin && git -C build-cs reset --hard origin/2.x
composer install --working-dir build-cs

.PHONY: cs
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
class BooleanInBooleanAndRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

/** @var bool */
private $bleedingEdge;
private bool $bleedingEdge;

public function __construct(BooleanRuleHelper $helper, bool $bleedingEdge)
{
Expand All @@ -44,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in %s, %s given on the left side.',
$nodeText,
$leftType->describe(VerbosityLevel::typeOnly())
$leftType->describe(VerbosityLevel::typeOnly()),
))->identifier(sprintf('%s.leftNotBoolean', $identifierType))->build();
}

Expand All @@ -54,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in %s, %s given on the right side.',
$nodeText,
$rightType->describe(VerbosityLevel::typeOnly())
$rightType->describe(VerbosityLevel::typeOnly()),
))->identifier(sprintf('%s.rightNotBoolean', $identifierType))->build();
}

Expand Down
5 changes: 2 additions & 3 deletions src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class BooleanInBooleanNotRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

public function __construct(BooleanRuleHelper $helper)
{
Expand All @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in a negated boolean, %s given.',
$expressionType->describe(VerbosityLevel::typeOnly())
$expressionType->describe(VerbosityLevel::typeOnly()),
))->identifier('booleanNot.exprNotBoolean')->build(),
];
}
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
class BooleanInBooleanOrRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

/** @var bool */
private $bleedingEdge;
private bool $bleedingEdge;

public function __construct(BooleanRuleHelper $helper, bool $bleedingEdge)
{
Expand All @@ -44,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in %s, %s given on the left side.',
$nodeText,
$leftType->describe(VerbosityLevel::typeOnly())
$leftType->describe(VerbosityLevel::typeOnly()),
))->identifier(sprintf('%s.leftNotBoolean', $identifierType))->build();
}

Expand All @@ -54,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in %s, %s given on the right side.',
$nodeText,
$rightType->describe(VerbosityLevel::typeOnly())
$rightType->describe(VerbosityLevel::typeOnly()),
))->identifier(sprintf('%s.rightNotBoolean', $identifierType))->build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class BooleanInElseIfConditionRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

public function __construct(BooleanRuleHelper $helper)
{
Expand All @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in an elseif condition, %s given.',
$conditionExpressionType->describe(VerbosityLevel::typeOnly())
$conditionExpressionType->describe(VerbosityLevel::typeOnly()),
))->identifier('elseif.condNotBoolean')->build(),
];
}
Expand Down
5 changes: 2 additions & 3 deletions src/Rules/BooleansInConditions/BooleanInIfConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class BooleanInIfConditionRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

public function __construct(BooleanRuleHelper $helper)
{
Expand All @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in an if condition, %s given.',
$conditionExpressionType->describe(VerbosityLevel::typeOnly())
$conditionExpressionType->describe(VerbosityLevel::typeOnly()),
))->identifier('if.condNotBoolean')->build(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class BooleanInTernaryOperatorRule implements Rule
{

/** @var BooleanRuleHelper */
private $helper;
private BooleanRuleHelper $helper;

public function __construct(BooleanRuleHelper $helper)
{
Expand All @@ -44,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
'Only booleans are allowed in a ternary operator condition, %s given.',
$conditionExpressionType->describe(VerbosityLevel::typeOnly())
$conditionExpressionType->describe(VerbosityLevel::typeOnly()),
))->identifier('ternary.condNotBoolean')->build(),
];
}
Expand Down
7 changes: 2 additions & 5 deletions src/Rules/BooleansInConditions/BooleanRuleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
class BooleanRuleHelper
{

/** @var RuleLevelHelper */
private $ruleLevelHelper;
private RuleLevelHelper $ruleLevelHelper;

public function __construct(RuleLevelHelper $ruleLevelHelper)
{
Expand All @@ -30,9 +29,7 @@ public function passesAsBoolean(Scope $scope, Expr $expr): bool
$scope,
$expr,
'',
static function (Type $type): bool {
return $type->isBoolean()->yes();
}
static fn (Type $type): bool => $type->isBoolean()->yes(),
);
$foundType = $typeToCheck->getType();
if ($foundType instanceof ErrorType) {
Expand Down
5 changes: 2 additions & 3 deletions src/Rules/Cast/UselessCastRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
class UselessCastRule implements Rule
{

/** @var bool */
private $treatPhpDocTypesAsCertain;
private bool $treatPhpDocTypesAsCertain;

public function __construct(bool $treatPhpDocTypesAsCertain)
{
Expand Down Expand Up @@ -61,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array
$addTip(RuleErrorBuilder::message(sprintf(
'Casting to %s something that\'s already %s.',
$castType->describe(VerbosityLevel::typeOnly()),
$expressionType->describe(VerbosityLevel::typeOnly())
$expressionType->describe(VerbosityLevel::typeOnly()),
)))->identifier('cast.useless')->build(),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Classes/RequireParentConstructCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array
RuleErrorBuilder::message(sprintf(
'%s::__construct() does not call parent constructor from %s.',
$classReflection->getName(),
$parentClass->getName()
$parentClass->getName(),
))->identifier('constructor.missingParentCall')->build(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function processNode(Node $node, Scope $scope): array
if ($node instanceof Equal) {
return [
RuleErrorBuilder::message(
'Loose comparison via "==" is not allowed.'
'Loose comparison via "==" is not allowed.',
)->tip('Use strict comparison via "===" instead.')
->identifier('equal.notAllowed')
->build(),
Expand All @@ -35,7 +35,7 @@ public function processNode(Node $node, Scope $scope): array
if ($node instanceof NotEqual) {
return [
RuleErrorBuilder::message(
'Loose comparison via "!=" is not allowed.'
'Loose comparison via "!=" is not allowed.',
)->tip('Use strict comparison via "!==" instead.')
->identifier('notEqual.notAllowed')
->build(),
Expand Down
13 changes: 5 additions & 8 deletions src/Rules/Functions/ArrayFilterStrictRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
class ArrayFilterStrictRule implements Rule
{

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

/** @var bool */
private $treatPhpDocTypesAsCertain;
private bool $treatPhpDocTypesAsCertain;

/** @var bool */
private $checkNullables;
private bool $checkNullables;

public function __construct(
ReflectionProvider $reflectionProvider,
Expand Down Expand Up @@ -68,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->getArgs(),
$functionReflection->getVariants(),
$functionReflection->getNamedArgumentsVariants()
$functionReflection->getNamedArgumentsVariants(),
);

$normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
Expand Down Expand Up @@ -132,7 +129,7 @@ public function processNode(Node $node, Scope $scope): array
$message = 'Parameter #2 of array_filter() cannot be null to avoid loose comparison semantics (%s given).';
$errorBuilder = RuleErrorBuilder::message(sprintf(
$message,
$callbackType->describe(VerbosityLevel::typeOnly())
$callbackType->describe(VerbosityLevel::typeOnly()),
))->identifier('arrayFilter.strict');

if (!$this->isCallbackTypeNull($nativeCallbackType) && $this->treatPhpDocTypesAsCertain) {
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Methods/WrongCaseOfInheritedMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function processNode(
$parentMessage = $this->findMethod(
$declaringClass,
$declaringClass->getParentClass(),
$methodReflection->getName()
$methodReflection->getName(),
);
if ($parentMessage !== null) {
$messages[] = $parentMessage;
Expand All @@ -46,7 +46,7 @@ public function processNode(
$interfaceMessage = $this->findMethod(
$declaringClass,
$interface,
$methodReflection->getName()
$methodReflection->getName(),
);
if ($interfaceMessage === null) {
continue;
Expand Down Expand Up @@ -79,7 +79,7 @@ private function findMethod(
$methodName,
$classReflection->isInterface() ? 'interface' : 'parent',
$classReflection->getDisplayName(),
$parentMethod->getName()
$parentMethod->getName(),
))->identifier('method.nameCase')->build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
abstract class OperandInArithmeticIncrementOrDecrementRule implements Rule
{

/** @var OperatorRuleHelper */
private $helper;
private OperatorRuleHelper $helper;

public function __construct(OperatorRuleHelper $helper)
{
Expand All @@ -45,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array
$messages[] = RuleErrorBuilder::message(sprintf(
'Only numeric types are allowed in %s, %s given.',
$this->describeOperation(),
$varType->describe(VerbosityLevel::typeOnly())
$varType->describe(VerbosityLevel::typeOnly()),
))->identifier(sprintf('%s.nonNumeric', $this->getIdentifier()))->build();
}

Expand Down
10 changes: 4 additions & 6 deletions src/Rules/Operators/OperandsInArithmeticAdditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
class OperandsInArithmeticAdditionRule implements Rule
{

/** @var OperatorRuleHelper */
private $helper;
private OperatorRuleHelper $helper;

/** @var bool */
private $bleedingEdge;
private bool $bleedingEdge;

public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge)
{
Expand Down Expand Up @@ -58,13 +56,13 @@ public function processNode(Node $node, Scope $scope): array
if (!$this->helper->isValidForArithmeticOperation($scope, $left)) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Only numeric types are allowed in +, %s given on the left side.',
$leftType->describe(VerbosityLevel::typeOnly())
$leftType->describe(VerbosityLevel::typeOnly()),
))->identifier('plus.leftNonNumeric')->build();
}
if (!$this->helper->isValidForArithmeticOperation($scope, $right)) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Only numeric types are allowed in +, %s given on the right side.',
$rightType->describe(VerbosityLevel::typeOnly())
$rightType->describe(VerbosityLevel::typeOnly()),
))->identifier('plus.rightNonNumeric')->build();
}

Expand Down
10 changes: 4 additions & 6 deletions src/Rules/Operators/OperandsInArithmeticDivisionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
class OperandsInArithmeticDivisionRule implements Rule
{

/** @var OperatorRuleHelper */
private $helper;
private OperatorRuleHelper $helper;

/** @var bool */
private $bleedingEdge;
private bool $bleedingEdge;

public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge)
{
Expand Down Expand Up @@ -52,15 +50,15 @@ public function processNode(Node $node, Scope $scope): array
if (!$this->helper->isValidForArithmeticOperation($scope, $left)) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Only numeric types are allowed in /, %s given on the left side.',
$leftType->describe(VerbosityLevel::typeOnly())
$leftType->describe(VerbosityLevel::typeOnly()),
))->identifier('div.leftNonNumeric')->build();
}

$rightType = $scope->getType($right);
if (!$this->helper->isValidForArithmeticOperation($scope, $right)) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Only numeric types are allowed in /, %s given on the right side.',
$rightType->describe(VerbosityLevel::typeOnly())
$rightType->describe(VerbosityLevel::typeOnly()),
))->identifier('div.rightNonNumeric')->build();
}

Expand Down
Loading

0 comments on commit f8092f9

Please sign in to comment.