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 681b2db commit 4590cf6
Show file tree
Hide file tree
Showing 38 changed files with 121 additions and 166 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/main
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ final class LazyDeprecatedScopeResolverProvider

public const EXTENSION_TAG = 'phpstan.deprecations.deprecatedScopeResolver';

/** @var Container */
private $container;
private Container $container;

/** @var DeprecatedScopeHelper */
private $scopeHelper;
private ?DeprecatedScopeHelper $scopeHelper = null;

public function __construct(Container $container)
{
Expand All @@ -24,7 +22,7 @@ public function get(): DeprecatedScopeHelper
{
if ($this->scopeHelper === null) {
$this->scopeHelper = new DeprecatedScopeHelper(
$this->container->getServicesByTag(self::EXTENSION_TAG)
$this->container->getServicesByTag(self::EXTENSION_TAG),
);
}
return $this->scopeHelper;
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/Deprecations/AccessDeprecatedPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
class AccessDeprecatedPropertyRule implements Rule
{

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -64,7 +62,7 @@ public function processNode(Node $node, Scope $scope): array
'Access to deprecated property $%s of %s %s.',
$propertyName,
strtolower($propertyReflection->getDeclaringClass()->getClassTypeDescription()),
$propertyReflection->getDeclaringClass()->getName()
$propertyReflection->getDeclaringClass()->getName(),
))->identifier('property.deprecated')->build(),
];
}
Expand All @@ -75,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array
$propertyName,
strtolower($propertyReflection->getDeclaringClass()->getClassTypeDescription()),
$propertyReflection->getDeclaringClass()->getName(),
$description
$description,
))->identifier('property.deprecated')->build(),
];
}
Expand Down
17 changes: 6 additions & 11 deletions src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
class AccessDeprecatedStaticPropertyRule implements Rule
{

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

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -65,9 +62,7 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($propertyName): bool {
return $type->canAccessProperties()->yes() && $type->hasProperty($propertyName)->yes();
}
static fn (Type $type): bool => $type->canAccessProperties()->yes() && $type->hasProperty($propertyName)->yes(),
);

if ($classTypeResult->getType() instanceof ErrorType) {
Expand Down Expand Up @@ -95,7 +90,7 @@ static function (Type $type) use ($propertyName): bool {
'Access to deprecated static property $%s of %s %s.',
$propertyName,
strtolower($property->getDeclaringClass()->getClassTypeDescription()),
$property->getDeclaringClass()->getName()
$property->getDeclaringClass()->getName(),
))->identifier('staticProperty.deprecated')->build(),
];
}
Expand All @@ -106,7 +101,7 @@ static function (Type $type) use ($propertyName): bool {
$propertyName,
strtolower($property->getDeclaringClass()->getClassTypeDescription()),
$property->getDeclaringClass()->getName(),
$description
$description,
))->identifier('staticProperty.deprecated')->build(),
];
}
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/Deprecations/CallToDeprecatedFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
class CallToDeprecatedFunctionRule implements Rule
{

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -58,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
'Call to deprecated function %s().',
$function->getName()
$function->getName(),
))->identifier('function.deprecated')->build(),
];
}
Expand All @@ -67,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array
RuleErrorBuilder::message(sprintf(
"Call to deprecated function %s():\n%s",
$function->getName(),
$description
$description,
))->identifier('function.deprecated')->build(),
];
}
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/Deprecations/CallToDeprecatedMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
class CallToDeprecatedMethodRule implements Rule
{

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -67,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array
'Call to deprecated method %s() of %s %s.',
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName()
$methodReflection->getDeclaringClass()->getName(),
))->identifier('method.deprecated')->build(),
];
}
Expand All @@ -78,7 +76,7 @@ public function processNode(Node $node, Scope $scope): array
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName(),
$description
$description,
))->identifier('method.deprecated')->build(),
];
} catch (ClassNotFoundException $e) {
Expand Down
21 changes: 8 additions & 13 deletions src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
class CallToDeprecatedStaticMethodRule implements Rule
{

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

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -65,9 +62,7 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($methodName): bool {
return $type->canCallMethods()->yes() && $type->hasMethod($methodName)->yes();
}
static fn (Type $type): bool => $type->canCallMethods()->yes() && $type->hasMethod($methodName)->yes(),
);

if ($classTypeResult->getType() instanceof ErrorType) {
Expand Down Expand Up @@ -96,15 +91,15 @@ static function (Type $type) use ($methodName): bool {
'Call to method %s() of deprecated %s %s.',
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName()
$methodReflection->getDeclaringClass()->getName(),
))->identifier(sprintf('staticMethod.deprecated%s', $methodReflection->getDeclaringClass()->getClassTypeDescription()))->build();
} else {
$errors[] = RuleErrorBuilder::message(sprintf(
"Call to method %s() of deprecated %s %s:\n%s",
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName(),
$classDescription
$classDescription,
))->identifier(sprintf('staticMethod.deprecated%s', $methodReflection->getDeclaringClass()->getClassTypeDescription()))->build();
}
}
Expand All @@ -119,15 +114,15 @@ static function (Type $type) use ($methodName): bool {
'Call to deprecated method %s() of %s %s.',
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName()
$methodReflection->getDeclaringClass()->getName(),
))->identifier('staticMethod.deprecated')->build();
} else {
$errors[] = RuleErrorBuilder::message(sprintf(
"Call to deprecated method %s() of %s %s:\n%s",
$methodReflection->getName(),
strtolower($methodReflection->getDeclaringClass()->getClassTypeDescription()),
$methodReflection->getDeclaringClass()->getName(),
$description
$description,
))->identifier('staticMethod.deprecated')->build();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Rules/Deprecations/DeprecatedClassHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class DeprecatedClassHelper
{

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

public function __construct(ReflectionProvider $reflectionProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Deprecations/DeprecatedScopeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DeprecatedScopeHelper
{

/** @var DeprecatedScopeResolver[] */
private $resolvers;
private array $resolvers;

/**
* @param DeprecatedScopeResolver[] $checkers
Expand Down
21 changes: 8 additions & 13 deletions src/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
class FetchingClassConstOfDeprecatedClassRule implements Rule
{

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

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -64,9 +61,7 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($constantName): bool {
return $type->canAccessConstants()->yes() && $type->hasConstant($constantName)->yes();
}
static fn (Type $type): bool => $type->canAccessConstants()->yes() && $type->hasConstant($constantName)->yes(),
);

if ($classTypeResult->getType() instanceof ErrorType) {
Expand All @@ -92,15 +87,15 @@ static function (Type $type) use ($constantName): bool {
'Fetching class constant %s of deprecated %s %s.',
$constantName,
strtolower($class->getClassTypeDescription()),
$referencedClass
$referencedClass,
))->identifier(sprintf('classConstant.deprecated%s', $class->getClassTypeDescription()))->build();
} else {
$errors[] = RuleErrorBuilder::message(sprintf(
"Fetching class constant %s of deprecated %s %s:\n%s",
$constantName,
strtolower($class->getClassTypeDescription()),
$referencedClass,
$classDescription
$classDescription,
))->identifier(sprintf('classConstant.deprecated%s', $class->getClassTypeDescription()))->build();
}
}
Expand All @@ -125,15 +120,15 @@ static function (Type $type) use ($constantName): bool {
'Fetching deprecated class constant %s of %s %s.',
$constantName,
strtolower($class->getClassTypeDescription()),
$referencedClass
$referencedClass,
))->identifier('classConstant.deprecated')->build();
} else {
$errors[] = RuleErrorBuilder::message(sprintf(
"Fetching deprecated class constant %s of %s %s:\n%s",
$constantName,
strtolower($class->getClassTypeDescription()),
$referencedClass,
$description
$description,
))->identifier('classConstant.deprecated')->build();
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/Rules/Deprecations/FetchingDeprecatedConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
class FetchingDeprecatedConstRule implements Rule
{

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

/** @var DeprecatedScopeHelper */
private $deprecatedScopeHelper;
private DeprecatedScopeHelper $deprecatedScopeHelper;

public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper)
{
Expand Down Expand Up @@ -49,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(sprintf(
$constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.',
$constantReflection->getName()
$constantReflection->getName(),
))->identifier('constant.deprecated')->build(),
];
}
Expand Down
Loading

0 comments on commit 4590cf6

Please sign in to comment.