Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/install_in_craftcms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.2
coverage: none

- run: git clone https://github.com/craftcms/cms.git --depth 1
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "craftcms/rector",
"description": "Rector sets to automate Craft CMS upgrades",
"require": {
"rector/rector": "^1.0.0"
"rector/rector": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"craftcms/cms": "^4.0.0|^5.0.0",
"craftcms/ecs": "dev-main",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2.0",
"symfony/var-exporter": "^6.0"
},
"autoload": {
Expand All @@ -34,4 +34,4 @@
"craftcms/plugin-installer": true
}
}
}
}
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
parameters:
level: 8

checkGenericClassInNonGenericObjectType: false

paths:
- ecs.php
- scripts
Expand All @@ -11,6 +9,8 @@ parameters:
- tests

ignoreErrors:
- identifier: missingType.generics

- '#expects string, ((.*?)string|string(.*?)) given#'

# false positives on static calls
Expand Down
20 changes: 14 additions & 6 deletions scripts/signature-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function normalizeNamespace(string $namespace): string
$excludeNamespaces = array_map(fn($namespace) => normalizeNamespace($namespace), explode(',', $excludeNamespaces));
}

$filterNamespace = function($class) use ($namespaces, $excludeNamespaces): bool {
$filterNamespace = function ($class) use ($namespaces, $excludeNamespaces): bool {
if ($namespaces) {
$include = false;
foreach ($namespaces as $namespace) {
Expand Down Expand Up @@ -174,16 +174,24 @@ public function build(array $classes): array
return $this->signatures;
}

private function serializeTypeCallback(string $className): callable
{
return function (ReflectionNamedType|ReflectionIntersectionType $type) use ($className): string {
if ($type instanceof ReflectionIntersectionType) {
return implode('|', array_map($this->serializeTypeCallback($className), $type->getTypes()));
}
$name = $type->getName();
return $name === 'self' ? $className : $name;
};
}

private function serializeType(?ReflectionType $type, string $className): ?string
{
if ($type === null) {
return null;
}
if ($type instanceof ReflectionUnionType) {
return implode('|', array_map(function(ReflectionNamedType $type) use ($className) {
$name = $type->getName();
return $name === 'self' ? $className : $name;
}, $type->getTypes()));
return implode('|', array_map($this->serializeTypeCallback($className), $type->getTypes()));
}
// todo:
// if ($type instanceof ReflectionIntersectionType) {
Expand Down Expand Up @@ -213,7 +221,7 @@ private function analyzeClass(ReflectionClass $class): void

$parentClass = $class->getParentClass() ?: null;
$properties = $class->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
usort($properties, fn(ReflectionProperty $a, ReflectionProperty$b) => $a->getName() <=> $b->getName());
usort($properties, fn(ReflectionProperty $a, ReflectionProperty $b) => $a->getName() <=> $b->getName());

foreach ($properties as $property) {
$declaringClass = $property->getDeclaringClass();
Expand Down
17 changes: 13 additions & 4 deletions scripts/signature-diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,25 @@ private function includeMethodParamType(string $className, string $method, int $
return !isset($oldParams[$position]) || $paramType !== $this->serializeType($oldParams[$position]->getType(), $className);
}

private function serializeTypeCallback(string $className): callable
{
return function (ReflectionNamedType|ReflectionIntersectionType $type) use ($className): string {
if ($type instanceof ReflectionIntersectionType) {
return implode('|', array_map($this->serializeTypeCallback($className), $type->getTypes()));
}
$name = $type->getName();
return $name === 'self' ? $className : $name;
};
}

private function serializeType(?ReflectionType $type, string $className): ?string
{
if ($type === null) {
return null;
}

if ($type instanceof ReflectionUnionType) {
return implode('|', array_map(function(ReflectionNamedType $type) use ($className) {
$name = $type->getName();
return $name === 'self' ? $className : $name;
}, $type->getTypes()));
return implode('|', array_map($this->serializeTypeCallback($className), $type->getTypes()));
}
// todo:
// if ($type instanceof ReflectionIntersectionType) {
Expand Down
2 changes: 1 addition & 1 deletion sets/craft-cms-50.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Arguments\ValueObject\RemoveMethodCallParam;
use Rector\Config\RectorConfig;
use Rector\ValueObject\Visibility;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
Expand All @@ -20,6 +19,7 @@
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\ValueObject\Visibility;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;

Expand Down
4 changes: 1 addition & 3 deletions src/SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace craft\rector;

use Rector\Set\Contract\SetListInterface;

final class SetList implements SetListInterface
final class SetList
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/SignatureConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function configure(RectorConfig $rectorConfig, string $name): void

private static function type(string $type): Type
{
if (! isset(self::$types[$type])) {
if (!isset(self::$types[$type])) {
self::$types[$type] = self::createType($type);
}

Expand Down
Loading