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
93 changes: 92 additions & 1 deletion config/rector/sets/cakephp60.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\Arguments\NodeAnalyzer\ArgumentAddingScope;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Arguments\ValueObject\ArgumentAdder;
Expand Down Expand Up @@ -69,6 +70,70 @@
new RenameProperty('Cake\ORM\Entity', '_accessible', 'patchable'),
// View::$_helpers conflicts with View::$helpers (config array), so rename to $helperRegistry
new RenameProperty('Cake\View\View', '_helpers', 'helperRegistry'),
// Entity::$_fields became $dynamicFields, not $fields
// @see https://github.com/cakephp/cakephp/pull/19381
new RenameProperty('Cake\ORM\Entity', '_fields', 'dynamicFields'),
new RenameProperty('Cake\Datasource\EntityTrait', '_fields', 'dynamicFields'),
]);

// ===== Dependency injection: league/container is gone, use Cake\Container =====
// @see https://github.com/cakephp/cakephp/pull/19559
$containerClasses = [
'Argument\ArgumentInterface',
'Argument\ArgumentResolverInterface',
'Argument\ArgumentResolverTrait',
'Argument\DefaultValueArgument',
'Argument\DefaultValueInterface',
'Argument\Literal\ArrayArgument',
'Argument\Literal\BooleanArgument',
'Argument\Literal\CallableArgument',
'Argument\Literal\FloatArgument',
'Argument\Literal\IntegerArgument',
'Argument\Literal\ObjectArgument',
'Argument\Literal\StringArgument',
'Argument\LiteralArgument',
'Argument\LiteralArgumentInterface',
'Argument\ResolvableArgument',
'Argument\ResolvableArgumentInterface',
'Container',
'ContainerAwareInterface',
'ContainerAwareTrait',
'Definition\Definition',
'Definition\DefinitionAggregate',
'Definition\DefinitionAggregateInterface',
'Definition\DefinitionInterface',
'Exception\ContainerException',
'Exception\NotFoundException',
'Inflector\Inflector',
'Inflector\InflectorAggregate',
'Inflector\InflectorAggregateInterface',
'Inflector\InflectorInterface',
'ReflectionContainer',
'ServiceProvider\AbstractServiceProvider',
'ServiceProvider\BootableServiceProviderInterface',
'ServiceProvider\ServiceProviderAggregate',
'ServiceProvider\ServiceProviderAggregateInterface',
'ServiceProvider\ServiceProviderInterface',
];
$containerRenames = [
'Cake\Core\Container' => 'Cake\Container\Container',
'Cake\Core\ContainerInterface' => 'Cake\Container\ContainerInterface',
'Cake\Core\ServiceProvider' => 'Cake\Container\ServiceProvider',
'Cake\Container\DefinitionContainerInterface' => 'Cake\Container\ContainerInterface',
'League\Container\DefinitionContainerInterface' => 'Cake\Container\ContainerInterface',
];
foreach ($containerClasses as $containerClass) {
$containerRenames['League\\Container\\' . $containerClass] = 'Cake\\Container\\' . $containerClass;
}
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, $containerRenames);

// Controller callbacks now declare a void return type
// @see https://github.com/cakephp/cakephp/pull/18660
$rectorConfig->ruleWithConfiguration(AddReturnTypeDeclarationRector::class, [
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'beforeFilter', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'beforeRender', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'afterFilter', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'beforeRedirect', new VoidType()),
]);

$rectorConfig->ruleWithConfiguration(RenameStringRector::class, [
Expand Down Expand Up @@ -326,7 +391,7 @@
'Cake\Datasource\ModelAwareTrait' => ['_modelFactories', '_modelType'],
'Cake\Datasource\ConnectionManager' => ['_dsnClassMap', '_registry', '_aliasMap'],
'Cake\Datasource\EntityTrait' => [
'_fields', '_original', '_originalFields', '_hidden', '_virtual', '_dirty',
'_original', '_originalFields', '_hidden', '_virtual', '_dirty',
'_accessors', '_new', '_errors', '_invalid', '_registryAlias', '_hasBeenVisited',
],
],
Expand Down Expand Up @@ -649,6 +714,30 @@
1,
new ObjectType('Cake\Console\ConsoleIoInterface'),
),
new AddParamTypeDeclaration(
'Cake\\Command\\Command',
'beforeExecute',
2,
new ObjectType('Cake\\Console\\ConsoleIoInterface'),
),
new AddParamTypeDeclaration(
'Cake\\Console\\BaseCommand',
'beforeExecute',
2,
new ObjectType('Cake\\Console\\ConsoleIoInterface'),
),
new AddParamTypeDeclaration(
'Cake\\Command\\Command',
'afterExecute',
2,
new ObjectType('Cake\\Console\\ConsoleIoInterface'),
),
new AddParamTypeDeclaration(
'Cake\\Console\\BaseCommand',
'afterExecute',
2,
new ObjectType('Cake\\Console\\ConsoleIoInterface'),
),
]);

// ===== Remove underscores from method names =====
Expand Down Expand Up @@ -1223,6 +1312,8 @@
new VoidMethod('Cake\Http\Session', 'close'),
// Table::deleteOrFail() - returns void or throws PersistenceFailedException
new VoidMethod('Cake\ORM\Table', 'deleteOrFail'),
// Table::deleteManyOrFail() - returns void or throws PersistenceFailedException
new VoidMethod('Cake\ORM\Table', 'deleteManyOrFail'),
// FixtureInterface::insert() - returns void
new VoidMethod('Cake\Datasource\FixtureInterface', 'insert'),
new VoidMethod('Cake\TestSuite\Fixture\TestFixture', 'insert'),
Expand Down
5 changes: 5 additions & 0 deletions src/Rector/Cake6/ReplaceCommandArgsIoWithPropertiesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function refactor(Node $node): ?Node
return null;
}

// The command event hooks still receive $args and $io in 6.x
if ($this->isNames($node, ['beforeExecute', 'afterExecute'])) {
return null;
}

// Find if params are $args and/or $io
$argsParam = $this->findParam($node, 'args');
$ioParam = $this->findParam($node, 'io');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Cake\Upgrade\Test\TestCase\Rector\MethodCall\AddMethodCallArgsRectorTest\Fixture;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Event\EventInterface;

class HookCommand extends Command
{
public function beforeExecute(EventInterface $event, Arguments $args, ConsoleIo $io): void
{
$io->out('before');
}

public function afterExecute(EventInterface $event, Arguments $args, ConsoleIo $io, ?int $result): void
{
$io->out('after');
}
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Event\EventInterface;

class TestCommand extends Command
{
Expand All @@ -16,6 +17,14 @@ public function execute(Arguments $args, ConsoleIo $io)
return static::CODE_SUCCESS;
}

public function beforeExecute(EventInterface $event, Arguments $args, ConsoleIo $io): void
{
}

public function afterExecute(EventInterface $event, Arguments $args, ConsoleIo $io, ?int $result): void
{
}

protected function someMethod(Arguments $args, ConsoleIo $io): void
{
$someArg = $args->getArgument('some');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace App\Container;

use Cake\Core\ContainerInterface;
use Cake\Core\ServiceProvider;
use League\Container\Argument\Literal\StringArgument;
use League\Container\DefinitionContainerInterface;

class AppServiceProvider extends ServiceProvider
{
protected array $provides = ['app.name'];

public function services(ContainerInterface $container): void
{
$container->add('app.name', new StringArgument('app'));
}

public function configure(DefinitionContainerInterface $container): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace App\Container;

use Cake\Core\Container;
use League\Container\ReflectionContainer;

class ContainerUsage
{
public function build(): Container
{
$container = new Container();
$container->delegate(new ReflectionContainer());

return $container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\EventInterface;
use Cake\Http\Response;
use Psr\Http\Message\UriInterface;

class ArticlesController extends Controller
{
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
}

public function beforeRender(EventInterface $event)
{
parent::beforeRender($event);
}

public function afterFilter(EventInterface $event)
{
}

public function beforeRedirect(EventInterface $event, UriInterface|array|string $url, Response $response)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function isAccessible(string $field): bool {
return true;
}

public function hasDynamicField(string $field): bool {
return array_key_exists($field, $this->_fields);
}

public function setSource(string $name) {
return parent::setSource($name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Cake\Core\Configure;
use Cake\Http\ServerRequest;
use Cake\ORM\Table;

class VoidMethods
{
Expand All @@ -20,4 +21,10 @@ public function test(ServerRequest $request): void
$request->allowMethod(['GET', 'POST']);
Configure::load('other');
}

public function deleteMany(Table $table, array $entities): void
{
// Assignment should be removed
$result = $table->deleteManyOrFail($entities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Event\EventInterface;

class TestCommand extends Command
{
Expand All @@ -16,6 +17,14 @@ public function execute()
return static::CODE_SUCCESS;
}

public function beforeExecute(EventInterface $event, Arguments $args, \Cake\Console\ConsoleIoInterface $io): void
{
}

public function afterExecute(EventInterface $event, Arguments $args, \Cake\Console\ConsoleIoInterface $io, ?int $result): void
{
}

protected function someMethod(): void
{
$someArg = $this->args->getArgument('some');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace App\Container;

use Cake\Core\ContainerInterface;
use Cake\Core\ServiceProvider;
use League\Container\Argument\Literal\StringArgument;
use League\Container\DefinitionContainerInterface;

class AppServiceProvider extends \Cake\Container\ServiceProvider
{
protected array $provides = ['app.name'];

public function services(\Cake\Container\ContainerInterface $container): void
{
$container->add('app.name', new \Cake\Container\Argument\Literal\StringArgument('app'));
}

public function configure(\Cake\Container\ContainerInterface $container): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace App\Container;

use Cake\Core\Container;
use League\Container\ReflectionContainer;

class ContainerUsage
{
public function build(): \Cake\Container\Container
{
$container = new \Cake\Container\Container();
$container->delegate(new \Cake\Container\ReflectionContainer());

return $container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\EventInterface;
use Cake\Http\Response;
use Psr\Http\Message\UriInterface;

class ArticlesController extends Controller
{
public function beforeFilter(EventInterface $event): void
{
parent::beforeFilter($event);
}

public function beforeRender(EventInterface $event): void
{
parent::beforeRender($event);
}

public function afterFilter(EventInterface $event): void
{
}

public function beforeRedirect(EventInterface $event, UriInterface|array|string $url, Response $response): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function isPatchable(string $field): bool {
return true;
}

public function hasDynamicField(string $field): bool {
return array_key_exists($field, $this->dynamicFields);
}

public function setSource(string $name): static {
return parent::setSource($name);
}
Expand Down
Loading
Loading