From 02ff521b329fc0047ec5aa12ff339e150f278a8e Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Sun, 18 Oct 2026 09:59:44 +0200 Subject: [PATCH 1/4] Check generated PHP syntax, coding standards, and Rector rules --- README.md | 11 + composer.json | 3 +- src/Command/TestCommand.php | 4 +- templates/bake/Controller/component.twig | 1 - templates/bake/Controller/controller.twig | 6 +- templates/bake/Model/behavior.twig | 1 - templates/bake/Model/table.twig | 9 +- templates/bake/Plugin/src/Plugin.php.twig | 4 +- .../bake/Plugin/tests/bootstrap.php.twig | 2 +- templates/bake/View/cell.twig | 2 +- templates/bake/View/helper.twig | 1 - templates/bake/element/Controller/delete.twig | 2 +- templates/bake/element/Controller/edit.twig | 2 +- templates/bake/element/Controller/view.twig | 2 +- tests/TestCase/Command/AllCommandTest.php | 2 +- tests/TestCase/Command/TestCommandTest.php | 8 +- tests/TestCase/GeneratedCodeTest.php | 250 ++++++++++++++++++ tests/TestCase/TestCase.php | 27 +- tests/comparisons/Cell/testBakePlugin.php | 2 +- .../Controller/testBakeActions.php | 7 +- .../testBakeActionsAuthenticationPlugin.php | 7 +- .../testBakeActionsAuthorizationPlugin.php | 7 +- .../Controller/testBakeActionsContent.php | 7 +- ...eAuthenticationWithoutAttributeRouting.php | 8 +- .../Controller/testBakeWithPlugin.php | 7 +- .../testBakeWithoutAttributeRouting.php | 8 +- ...iationDetectionCategoriesProductsTable.php | 2 - ...akeAssociationDetectionCategoriesTable.php | 2 - ...keAssociationDetectionOldProductsTable.php | 2 - ...ionDetectionProductVersionsTableSigned.php | 1 - .../comparisons/Model/testBakeTableConfig.php | 1 - .../Model/testBakeTableNullableForeignKey.php | 2 - .../comparisons/Model/testBakeTableRules.php | 2 - .../Model/testBakeTableValidation.php | 2 - .../Model/testBakeTableWithCounterCache.php | 2 - .../Model/testBakeTableWithPlugin.php | 2 - .../Model/testBakeUpdateTableNoFile.php | 1 - .../Model/testBakeWithRulesUnique.php | 1 - .../Company/Example/src/ExamplePlugin.php | 4 +- .../Company/Example/tests/bootstrap.php | 2 +- tests/comparisons/Plugin/Simple/testBake.php | 1 - .../Plugin/Simple/testBakePlugin.php | 1 - .../SimpleExample/src/SimpleExamplePlugin.php | 4 +- .../comparisons/Test/testBakeCommandTest.php | 1 - .../Test/testBakeControllerTest.php | 1 - .../testBakeControllerWithoutModelTest.php | 1 - .../Test/testBakePrefixControllerTest.php | 1 - ...tBakePrefixControllerTestWithCliOption.php | 1 - tests/rector-generated.php | 7 + 49 files changed, 352 insertions(+), 82 deletions(-) create mode 100644 tests/TestCase/GeneratedCodeTest.php create mode 100644 tests/rector-generated.php diff --git a/README.md b/README.md index 8f43d482e..c9245dc90 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,14 @@ without having to manually edit each one: ```bash UPDATE_TEST_COMPARISON_FILES=1 vendor/bin/phpunit ``` + +Generated PHP registered by command tests is checked with `php -l` before cleanup. +A dedicated integration test also bakes classes, a complete CRUD stack, and plugin +skeletons and checks them against the CakePHP coding standard and the project's +Rector rules. PHPCS uses the generated files' intended application paths so +test-fixture exclusions cannot hide violations. Rector runs in dry-run mode and +fails if it proposes changes; generated files are never rewritten by the checks: + +```bash +vendor/bin/phpunit tests/TestCase/GeneratedCodeTest.php +``` diff --git a/composer.json b/composer.json index 2364a017f..affbaef72 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "require-dev": { "cakephp/cakephp-codesniffer": "^6.0", "cakephp/debug_kit": "^6.0", - "phpunit/phpunit": "^13.0" + "phpunit/phpunit": "^13.0", + "rector/rector": "~2.7.0" }, "autoload": { "psr-4": { diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 58ddead33..a3a30ea20 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -752,7 +752,9 @@ public function generateUses(string $type, string $fullClassName): array if ($type === 'Behavior') { $uses[] = 'Cake\ORM\Table'; } - $uses[] = $fullClassName; + if (!in_array($type, ['Controller', 'Command'], true)) { + $uses[] = $fullClassName; + } return $uses; } diff --git a/templates/bake/Controller/component.twig b/templates/bake/Controller/component.twig index f2e52b123..a4382e7a2 100644 --- a/templates/bake/Controller/component.twig +++ b/templates/bake/Controller/component.twig @@ -17,7 +17,6 @@ namespace: "#{namespace}\\Controller\\Component", classImports: [ 'Cake\\Controller\\Component', - 'Cake\\Controller\\ComponentRegistry', ], }) }} diff --git a/templates/bake/Controller/controller.twig b/templates/bake/Controller/controller.twig index 394dc11e8..7d92b5519 100644 --- a/templates/bake/Controller/controller.twig +++ b/templates/bake/Controller/controller.twig @@ -17,9 +17,13 @@ * @license https://www.opensource.org/licenses/mit-license.php MIT License */ #} +{% set classImports = ((plugin or prefix) ? ["#{baseNamespace}\\Controller\\AppController"] : [])|merge(routingImports) %} +{% if 'delete' in actions %} + {%~ set classImports = classImports|merge(['Cake\\Http\\Response']) %} +{% endif %} {{ element('Bake.file_header', { namespace: "#{namespace}\\Controller#{prefix}", - classImports: ((plugin or prefix) ? ["#{baseNamespace}\\Controller\\AppController"] : [])|merge(routingImports), + classImports: classImports, }) }} {% set has_login = 'login' in actions and Bake.hasPlugin('Authentication') %} {% set include_initialize = components or helpers or has_login %} diff --git a/templates/bake/Model/behavior.twig b/templates/bake/Model/behavior.twig index 88d16a364..811419979 100644 --- a/templates/bake/Model/behavior.twig +++ b/templates/bake/Model/behavior.twig @@ -17,7 +17,6 @@ namespace: "#{namespace}\\Model\\Behavior", classImports: [ 'Cake\\ORM\\Behavior', - 'Cake\\ORM\\Table', ], }) }} diff --git a/templates/bake/Model/table.twig b/templates/bake/Model/table.twig index 76511babc..853634088 100644 --- a/templates/bake/Model/table.twig +++ b/templates/bake/Model/table.twig @@ -15,9 +15,16 @@ #} {% set annotations = DocBlock.buildTableAnnotations(associations, associationInfo, behaviors, entity, namespace) %} {% set generatedFunctions = ['initialize'] %} +{% set classImports = ['Cake\\ORM\\Table'] %} +{% if validation %} + {%~ set classImports = classImports|merge(['Cake\\Validation\\Validator']) %} +{% endif %} +{% if rulesChecker %} + {%~ set classImports = classImports|merge(['Cake\\ORM\\RulesChecker']) %} +{% endif %} {{ element('Bake.file_header', { namespace: fileBuilder.namespace, - classImports: fileBuilder.classImports(['Cake\\ORM\\Query\\SelectQuery', 'Cake\\ORM\\RulesChecker', 'Cake\\ORM\\Table', 'Cake\\Validation\\Validator']), + classImports: fileBuilder.classImports(classImports), }) }} {{ DocBlock.classDescription(name, 'Model', annotations)|raw }} diff --git a/templates/bake/Plugin/src/Plugin.php.twig b/templates/bake/Plugin/src/Plugin.php.twig index 58cebd94c..4892c427c 100644 --- a/templates/bake/Plugin/src/Plugin.php.twig +++ b/templates/bake/Plugin/src/Plugin.php.twig @@ -59,13 +59,13 @@ class {{ name }}Plugin extends BasePlugin $routes->plugin( '{{ plugin }}', ['path' => '/{{ routePath }}'], - function (RouteBuilder $builder) { + function (RouteBuilder $builder): void { // Add custom routes here {% if not attributeRouting %} $builder->fallbacks(); {% endif %} - } + }, ); parent::routes($routes); } diff --git a/templates/bake/Plugin/tests/bootstrap.php.twig b/templates/bake/Plugin/tests/bootstrap.php.twig index 7604c2906..0e3393b6a 100644 --- a/templates/bake/Plugin/tests/bootstrap.php.twig +++ b/templates/bake/Plugin/tests/bootstrap.php.twig @@ -68,4 +68,4 @@ if (file_exists($root . '/config/bootstrap.php')) { use Cake\TestSuite\Fixture\SchemaLoader; // Load a schema dump file. -(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); +new SchemaLoader()->loadSqlFiles('tests/schema.sql', 'test'); diff --git a/templates/bake/View/cell.twig b/templates/bake/View/cell.twig index ce72b3ee5..10d3e7496 100644 --- a/templates/bake/View/cell.twig +++ b/templates/bake/View/cell.twig @@ -47,7 +47,7 @@ class {{ name }}Cell extends Cell * * @return void */ - public function display() + public function display(): void { } } diff --git a/templates/bake/View/helper.twig b/templates/bake/View/helper.twig index bd2e42ac6..66f136b9b 100644 --- a/templates/bake/View/helper.twig +++ b/templates/bake/View/helper.twig @@ -17,7 +17,6 @@ namespace: "#{namespace}\\View\\Helper", classImports: [ 'Cake\\View\\Helper', - 'Cake\\View\\View', ], }) }} diff --git a/templates/bake/element/Controller/delete.twig b/templates/bake/element/Controller/delete.twig index 6945ecbb6..8426c3414 100644 --- a/templates/bake/element/Controller/delete.twig +++ b/templates/bake/element/Controller/delete.twig @@ -23,7 +23,7 @@ {% if attributeRouting %} #[Route('/delete/{id}')] {% endif %} - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); ${{ singularName }} = $this->{{ currentModelName }}->get($id); diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index 0790f6706..ae1daf732 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -26,7 +26,7 @@ {% if attributeRouting %} #[Route('/edit/{id}')] {% endif %} - public function edit($id = null) + public function edit(mixed $id = null) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/templates/bake/element/Controller/view.twig b/templates/bake/element/Controller/view.twig index f12fa9e9d..05085fffb 100644 --- a/templates/bake/element/Controller/view.twig +++ b/templates/bake/element/Controller/view.twig @@ -27,7 +27,7 @@ {% if attributeRouting %} #[Route('/view/{id}')] {% endif %} - public function view($id = null) + public function view(mixed $id = null) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(allAssociations)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/tests/TestCase/Command/AllCommandTest.php b/tests/TestCase/Command/AllCommandTest.php index ebdb1994d..007b060fb 100644 --- a/tests/TestCase/Command/AllCommandTest.php +++ b/tests/TestCase/Command/AllCommandTest.php @@ -200,7 +200,7 @@ public function testExecuteWithPrefix(): void $path . 'Controller/Admin/ProductsController.php', ); $this->assertFileContains( - 'use Bake\Test\App\Controller\Admin\ProductsController;', + '@link \Bake\Test\App\Controller\Admin\ProductsController', $testsPath . 'TestCase/Controller/Admin/ProductsControllerTest.php', ); $this->assertOutputContains('Bake All complete'); diff --git a/tests/TestCase/Command/TestCommandTest.php b/tests/TestCase/Command/TestCommandTest.php index 4ef6ba696..93b529548 100644 --- a/tests/TestCase/Command/TestCommandTest.php +++ b/tests/TestCase/Command/TestCommandTest.php @@ -610,10 +610,10 @@ public function testGenerateUses(): void $this->assertEquals($expected, $result); $result = $command->generateUses('Controller', 'App\Controller\PostsController'); - $expected = [ - 'App\Controller\PostsController', - ]; - $this->assertEquals($expected, $result); + $this->assertSame([], $result); + + $result = $command->generateUses('Command', 'App\Command\ExampleCommand'); + $this->assertSame([], $result); $result = $command->generateUses('Helper', 'App\View\Helper\FormHelper'); $expected = [ diff --git a/tests/TestCase/GeneratedCodeTest.php b/tests/TestCase/GeneratedCodeTest.php new file mode 100644 index 000000000..8c88e42dd --- /dev/null +++ b/tests/TestCase/GeneratedCodeTest.php @@ -0,0 +1,250 @@ + + */ + protected array $fixtures = [ + 'plugin.Bake.Products', + 'plugin.Bake.ProductVersions', + ]; + + protected ?string $pluginDirectory = null; + + protected function setUp(): void + { + parent::setUp(); + $this->setAppNamespace('Bake\\Test\\App'); + } + + protected function tearDown(): void + { + try { + parent::tearDown(); + } finally { + if ($this->pluginDirectory !== null) { + new Filesystem()->deleteDir($this->pluginDirectory); + } + } + } + + /** + * @return array}> + */ + public static function simpleCommandProvider(): array + { + return [ + 'behavior' => ['behavior', 'Model/Behavior/QualityExampleBehavior.php', []], + 'component' => ['component', 'Controller/Component/QualityExampleComponent.php', []], + 'helper' => ['helper', 'View/Helper/QualityExampleHelper.php', []], + 'form' => ['form', 'Form/QualityExampleForm.php', []], + 'middleware' => ['middleware', 'Middleware/QualityExampleMiddleware.php', []], + 'mailer' => ['mailer', 'Mailer/QualityExampleMailer.php', []], + 'command' => ['command', 'Command/QualityExampleCommand.php', []], + 'command helper' => ['command_helper', 'Command/Helper/QualityExampleHelper.php', []], + 'cell' => ['cell', 'View/Cell/QualityExampleCell.php', ['templates/cell/QualityExample/display.php']], + ]; + } + + /** + * @param string $command Bake command. + * @param string $path Generated class path relative to APP. + * @param array $extraFiles Additional generated files relative to ROOT. + * @return void + */ + #[DataProvider('simpleCommandProvider')] + public function testSimpleCommands(string $command, string $path, array $extraFiles): void + { + $this->generatedFile = APP . $path; + foreach ($extraFiles as $extraFile) { + $this->generatedFiles[] = ROOT . $extraFile; + } + $this->exec('bake ' . $command . ' QualityExample --no-test'); + + $this->assertExitSuccess(); + $this->assertGeneratedCodeQuality([$this->generatedFile => 'src/' . $path]); + } + + /** + * @return array + */ + public static function applicationProvider(): array + { + return [ + 'attributes' => ['', true], + 'legacy' => ['--no-attribute-routing', false], + 'prefix' => ['--prefix Admin/Quality', true], + ]; + } + + #[DataProvider('applicationProvider')] + public function testApplication(string $options, bool $attributes): void + { + Configure::write('Bake.attributeRouting', $attributes); + $prefix = str_contains($options, '--prefix') ? 'Admin/Quality/' : ''; + $files = [ + APP . 'Model/Table/ProductsTable.php' => 'src/Model/Table/ProductsTable.php', + APP . 'Model/Entity/Product.php' => 'src/Model/Entity/Product.php', + APP . 'Controller/' . $prefix . 'ProductsController.php' => 'src/Controller/' . $prefix . 'ProductsController.php', + ROOT . 'tests/Fixture/ProductsFixture.php' => 'tests/Fixture/ProductsFixture.php', + ROOT . 'tests/TestCase/Model/Table/ProductsTableTest.php' => 'tests/TestCase/Model/Table/ProductsTableTest.php', + ROOT . 'tests/TestCase/Controller/' . $prefix . 'ProductsControllerTest.php' => 'tests/TestCase/Controller/' . $prefix . 'ProductsControllerTest.php', + ]; + $this->generatedFiles = array_keys($files); + foreach (['index', 'view', 'add', 'edit'] as $action) { + $this->generatedFiles[] = ROOT . 'templates/' . $prefix . 'Products/' . $action . '.php'; + } + $this->exec(rtrim('bake all Products --connection test ' . $options), ['y']); + + $this->assertExitSuccess(); + $this->assertGeneratedCodeQuality($files); + } + + public function testEnum(): void + { + $this->generatedFile = APP . 'Model/Enum/QualityStatus.php'; + $this->exec('bake enum QualityStatus draft,published'); + + $this->assertExitSuccess(); + $this->assertGeneratedCodeQuality([$this->generatedFile => 'src/Model/Enum/QualityStatus.php']); + } + + /** + * @return array + */ + public static function pluginProvider(): array + { + return ['attributes' => [''], 'legacy' => ['--no-attribute-routing']]; + } + + #[DataProvider('pluginProvider')] + public function testPlugin(string $options): void + { + $this->pluginDirectory = TMP . 'bake_generated_quality_' . bin2hex(random_bytes(6)) . DS; + mkdir($this->pluginDirectory, 0777, true); + $this->exec(rtrim('bake plugin QualityCompany/QualityExample --standalone-path ' . + $this->pluginDirectory . ' ' . $options), ['y']); + + $this->assertExitSuccess(); + $root = $this->pluginDirectory . 'QualityCompany/QualityExample/'; + $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)); + $generated = []; + foreach ($files as $file) { + if (!$file->isFile() || $file->getExtension() !== 'php') { + continue; + } + $path = $file->getPathname(); + $this->assertPhpLints($path); + $generated[$path] = substr($path, strlen($root)); + } + $this->assertNotEmpty($generated); + $this->assertGeneratedCodeQuality($generated); + } + + /** + * Check formatting and Rector rules on freshly generated PHP. + * + * @param array $files Generated paths mapped to their intended application paths. + * @return void + */ + protected function assertGeneratedCodeQuality(array $files): void + { + foreach ($files as $file => $relativePath) { + $this->assertCodingStandard($file, $relativePath); + } + + // Run once per generated stack rather than starting Rector for every file. + $root = Plugin::path('Bake'); + $command = [ + PHP_BINARY, + $root . 'vendor/bin/rector', + 'process', + '--config=' . $root . 'tests/rector-generated.php', + '--autoload-file=' . $root . 'vendor/autoload.php', + '--dry-run', + '--debug', + '--clear-cache', + '--no-progress-bar', + '--no-ansi', + ...array_keys($files), + ]; + $process = proc_open($command, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + $this->assertIsResource($process); + fclose($pipes[0]); + $output = stream_get_contents($pipes[1]); + fclose($pipes[1]); + $errors = stream_get_contents($pipes[2]); + fclose($pipes[2]); + $status = proc_close($process); + $report = $output . $errors; + + $this->assertSame(0, $status, "Rector reported issues in generated PHP:\n" . $report); + foreach (array_keys($files) as $file) { + $this->assertStringContainsString('[file] ' . $file, $report, 'Rector did not inspect ' . $file); + } + } + + /** + * Check code using its intended application path so test-fixture exclusions do not hide violations. + * + * @param string $file Generated PHP file. + * @param string $relativePath Intended path within an application or plugin. + * @return void + */ + protected function assertCodingStandard(string $file, string $relativePath): void + { + $this->assertFileExists($file); + $stdinPath = '/bake-generated/' . str_replace('\\', '/', $relativePath); + $command = [ + PHP_BINARY, + Plugin::path('Bake') . 'vendor/bin/phpcs', + '--standard=CakePHP', + '--report=json', + '--stdin-path=' . $stdinPath, + '-q', + '-', + ]; + $process = proc_open($command, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + $this->assertIsResource($process); + fwrite($pipes[0], file_get_contents($file)); + fclose($pipes[0]); + $output = stream_get_contents($pipes[1]); + fclose($pipes[1]); + $errors = stream_get_contents($pipes[2]); + fclose($pipes[2]); + $status = proc_close($process); + $report = json_decode($output, true, flags: JSON_THROW_ON_ERROR); + + $this->assertArrayHasKey($stdinPath, $report['files'], 'PHPCS did not inspect ' . $file); + $messages = json_encode($report['files'][$stdinPath]['messages'], JSON_PRETTY_PRINT); + $this->assertSame(0, $status, $file . ":\n" . $messages . $errors); + $this->assertSame(['errors' => 0, 'warnings' => 0, 'fixable' => 0], $report['totals']); + } +} diff --git a/tests/TestCase/TestCase.php b/tests/TestCase/TestCase.php index 446fbdde6..7a0a85fb6 100644 --- a/tests/TestCase/TestCase.php +++ b/tests/TestCase/TestCase.php @@ -48,18 +48,27 @@ protected function tearDown(): void { parent::tearDown(); - if ($this->generatedFile && file_exists($this->generatedFile)) { - unlink($this->generatedFile); - $this->generatedFile = ''; - } + try { + $files = array_unique(array_merge([$this->generatedFile], $this->generatedFiles)); + foreach ($files as $file) { + if ($file && is_file($file) && str_ends_with($file, '.php')) { + $this->assertPhpLints($file); + } + } + } finally { + if ($this->generatedFile && file_exists($this->generatedFile)) { + unlink($this->generatedFile); + $this->generatedFile = ''; + } - if (count($this->generatedFiles)) { - foreach ($this->generatedFiles as $file) { - if (file_exists($file)) { - unlink($file); + if (count($this->generatedFiles)) { + foreach ($this->generatedFiles as $file) { + if (file_exists($file)) { + unlink($file); + } } + $this->generatedFiles = []; } - $this->generatedFiles = []; } } diff --git a/tests/comparisons/Cell/testBakePlugin.php b/tests/comparisons/Cell/testBakePlugin.php index be3502961..0f1986dfa 100644 --- a/tests/comparisons/Cell/testBakePlugin.php +++ b/tests/comparisons/Cell/testBakePlugin.php @@ -32,7 +32,7 @@ public function initialize(): void * * @return void */ - public function display() + public function display(): void { } } diff --git a/tests/comparisons/Controller/testBakeActions.php b/tests/comparisons/Controller/testBakeActions.php index 103e60a8b..32e243a36 100644 --- a/tests/comparisons/Controller/testBakeActions.php +++ b/tests/comparisons/Controller/testBakeActions.php @@ -3,6 +3,7 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; use Cake\Routing\Attribute\Route; use Cake\Routing\Attribute\Scope; @@ -54,7 +55,7 @@ public function index() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view($id = null) + public function view(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -91,7 +92,7 @@ public function add() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit($id = null) + public function edit(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -116,7 +117,7 @@ public function edit($id = null) * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php index 98b9d2997..54574f075 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php @@ -3,6 +3,7 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; use Cake\Routing\Attribute\Route; use Cake\Routing\Attribute\Scope; @@ -48,7 +49,7 @@ public function index() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view($id = null) + public function view(mixed $id = null) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -83,7 +84,7 @@ public function add() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit($id = null) + public function edit(mixed $id = null) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -106,7 +107,7 @@ public function edit($id = null) * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php index 9c6f52771..0356eb0d0 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php @@ -3,6 +3,7 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; use Cake\Routing\Attribute\Route; use Cake\Routing\Attribute\Scope; @@ -52,7 +53,7 @@ public function index() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view($id = null) + public function view(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->Authorization->authorize($bakeArticle); @@ -91,7 +92,7 @@ public function add() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit($id = null) + public function edit(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); $this->Authorization->authorize($bakeArticle); @@ -117,7 +118,7 @@ public function edit($id = null) * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsContent.php b/tests/comparisons/Controller/testBakeActionsContent.php index 7d0101c6e..847eb7f3f 100644 --- a/tests/comparisons/Controller/testBakeActionsContent.php +++ b/tests/comparisons/Controller/testBakeActionsContent.php @@ -3,6 +3,7 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; use Cake\Routing\Attribute\Route; use Cake\Routing\Attribute\Scope; @@ -38,7 +39,7 @@ public function index() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view($id = null) + public function view(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -75,7 +76,7 @@ public function add() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit($id = null) + public function edit(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -100,7 +101,7 @@ public function edit($id = null) * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php index d163ca7de..c2f0b6c05 100644 --- a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php @@ -3,6 +3,8 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; + /** * Users Controller * @@ -41,7 +43,7 @@ public function index() * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view($id = null) + public function view(mixed $id = null) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -74,7 +76,7 @@ public function add() * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit($id = null) + public function edit(mixed $id = null) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -96,7 +98,7 @@ public function edit($id = null) * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeWithPlugin.php b/tests/comparisons/Controller/testBakeWithPlugin.php index 7f5d13063..fa749d980 100644 --- a/tests/comparisons/Controller/testBakeWithPlugin.php +++ b/tests/comparisons/Controller/testBakeWithPlugin.php @@ -4,6 +4,7 @@ namespace BakeTest\Controller; use Bake\Test\App\Controller\AppController; +use Cake\Http\Response; use Cake\Routing\Attribute\Route; use Cake\Routing\Attribute\Scope; @@ -39,7 +40,7 @@ public function index() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view($id = null) + public function view(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -76,7 +77,7 @@ public function add() * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit($id = null) + public function edit(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -101,7 +102,7 @@ public function edit($id = null) * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php index 8f3df0942..9bee69911 100644 --- a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php @@ -3,6 +3,8 @@ namespace Bake\Test\App\Controller; +use Cake\Http\Response; + /** * BakeArticles Controller * @@ -31,7 +33,7 @@ public function index() * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view($id = null) + public function view(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -66,7 +68,7 @@ public function add() * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit($id = null) + public function edit(mixed $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -90,7 +92,7 @@ public function edit($id = null) * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete($id = null) + public function delete(mixed $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesProductsTable.php b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesProductsTable.php index a99510219..3d8adaf8b 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesProductsTable.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesProductsTable.php @@ -3,10 +3,8 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; -use Cake\Validation\Validator; /** * CategoriesProducts Model diff --git a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTable.php b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTable.php index 9c7643323..f639ac9c2 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTable.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTable.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTable.php b/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTable.php index 49a307a59..d958acb7c 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTable.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTable.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTableSigned.php b/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTableSigned.php index d6728d6d7..ffa42ada7 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTableSigned.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTableSigned.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeTableConfig.php b/tests/comparisons/Model/testBakeTableConfig.php index a208aebf8..50db7b66d 100644 --- a/tests/comparisons/Model/testBakeTableConfig.php +++ b/tests/comparisons/Model/testBakeTableConfig.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeTableNullableForeignKey.php b/tests/comparisons/Model/testBakeTableNullableForeignKey.php index ede629ec7..7da68416a 100644 --- a/tests/comparisons/Model/testBakeTableNullableForeignKey.php +++ b/tests/comparisons/Model/testBakeTableNullableForeignKey.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeTableRules.php b/tests/comparisons/Model/testBakeTableRules.php index 637d3ac5e..0afbdc343 100644 --- a/tests/comparisons/Model/testBakeTableRules.php +++ b/tests/comparisons/Model/testBakeTableRules.php @@ -3,10 +3,8 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; -use Cake\Validation\Validator; /** * UniqueFields Model diff --git a/tests/comparisons/Model/testBakeTableValidation.php b/tests/comparisons/Model/testBakeTableValidation.php index ede629ec7..7da68416a 100644 --- a/tests/comparisons/Model/testBakeTableValidation.php +++ b/tests/comparisons/Model/testBakeTableValidation.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeTableWithCounterCache.php b/tests/comparisons/Model/testBakeTableWithCounterCache.php index c0f0d4ad0..cf41bb042 100644 --- a/tests/comparisons/Model/testBakeTableWithCounterCache.php +++ b/tests/comparisons/Model/testBakeTableWithCounterCache.php @@ -3,10 +3,8 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; -use Cake\Validation\Validator; /** * TodoTasks Model diff --git a/tests/comparisons/Model/testBakeTableWithPlugin.php b/tests/comparisons/Model/testBakeTableWithPlugin.php index 4b7224c9c..5b896a4f2 100644 --- a/tests/comparisons/Model/testBakeTableWithPlugin.php +++ b/tests/comparisons/Model/testBakeTableWithPlugin.php @@ -3,10 +3,8 @@ namespace BakeTest\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; -use Cake\Validation\Validator; /** * Users Model diff --git a/tests/comparisons/Model/testBakeUpdateTableNoFile.php b/tests/comparisons/Model/testBakeUpdateTableNoFile.php index 0b7f21cff..db3150d5a 100644 --- a/tests/comparisons/Model/testBakeUpdateTableNoFile.php +++ b/tests/comparisons/Model/testBakeUpdateTableNoFile.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeWithRulesUnique.php b/tests/comparisons/Model/testBakeWithRulesUnique.php index 97927e120..dd1909c8c 100644 --- a/tests/comparisons/Model/testBakeWithRulesUnique.php +++ b/tests/comparisons/Model/testBakeWithRulesUnique.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Plugin/Company/Example/src/ExamplePlugin.php b/tests/comparisons/Plugin/Company/Example/src/ExamplePlugin.php index 3fb4ba43a..d002bda00 100644 --- a/tests/comparisons/Plugin/Company/Example/src/ExamplePlugin.php +++ b/tests/comparisons/Plugin/Company/Example/src/ExamplePlugin.php @@ -44,9 +44,9 @@ public function routes(RouteBuilder $routes): void $routes->plugin( 'Company/Example', ['path' => '/company/example'], - function (RouteBuilder $builder) { + function (RouteBuilder $builder): void { // Add custom routes here - } + }, ); parent::routes($routes); } diff --git a/tests/comparisons/Plugin/Company/Example/tests/bootstrap.php b/tests/comparisons/Plugin/Company/Example/tests/bootstrap.php index 401fcb40c..b4a802792 100644 --- a/tests/comparisons/Plugin/Company/Example/tests/bootstrap.php +++ b/tests/comparisons/Plugin/Company/Example/tests/bootstrap.php @@ -52,4 +52,4 @@ use Cake\TestSuite\Fixture\SchemaLoader; // Load a schema dump file. -(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test'); +new SchemaLoader()->loadSqlFiles('tests/schema.sql', 'test'); diff --git a/tests/comparisons/Plugin/Simple/testBake.php b/tests/comparisons/Plugin/Simple/testBake.php index a5174de84..3872954ad 100644 --- a/tests/comparisons/Plugin/Simple/testBake.php +++ b/tests/comparisons/Plugin/Simple/testBake.php @@ -4,7 +4,6 @@ namespace Bake\Test\App\Model\Behavior; use Cake\ORM\Behavior; -use Cake\ORM\Table; /** * Example behavior diff --git a/tests/comparisons/Plugin/Simple/testBakePlugin.php b/tests/comparisons/Plugin/Simple/testBakePlugin.php index 55d58cbf8..f27be4796 100644 --- a/tests/comparisons/Plugin/Simple/testBakePlugin.php +++ b/tests/comparisons/Plugin/Simple/testBakePlugin.php @@ -4,7 +4,6 @@ namespace TestBake\Model\Behavior; use Cake\ORM\Behavior; -use Cake\ORM\Table; /** * Example behavior diff --git a/tests/comparisons/Plugin/SimpleExample/src/SimpleExamplePlugin.php b/tests/comparisons/Plugin/SimpleExample/src/SimpleExamplePlugin.php index ab8b4e76d..1b1bc7c33 100644 --- a/tests/comparisons/Plugin/SimpleExample/src/SimpleExamplePlugin.php +++ b/tests/comparisons/Plugin/SimpleExample/src/SimpleExamplePlugin.php @@ -44,9 +44,9 @@ public function routes(RouteBuilder $routes): void $routes->plugin( 'SimpleExample', ['path' => '/simple-example'], - function (RouteBuilder $builder) { + function (RouteBuilder $builder): void { // Add custom routes here - } + }, ); parent::routes($routes); } diff --git a/tests/comparisons/Test/testBakeCommandTest.php b/tests/comparisons/Test/testBakeCommandTest.php index fd3ea530a..da6fb3fbe 100644 --- a/tests/comparisons/Test/testBakeCommandTest.php +++ b/tests/comparisons/Test/testBakeCommandTest.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Test\TestCase\Command; -use Bake\Test\App\Command\OtherExampleCommand; use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\TestCase; diff --git a/tests/comparisons/Test/testBakeControllerTest.php b/tests/comparisons/Test/testBakeControllerTest.php index 8fd6d5a30..495d6a9b1 100644 --- a/tests/comparisons/Test/testBakeControllerTest.php +++ b/tests/comparisons/Test/testBakeControllerTest.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Test\TestCase\Controller; -use Bake\Test\App\Controller\PostsController; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; diff --git a/tests/comparisons/Test/testBakeControllerWithoutModelTest.php b/tests/comparisons/Test/testBakeControllerWithoutModelTest.php index 54f42e261..b49b942c5 100644 --- a/tests/comparisons/Test/testBakeControllerWithoutModelTest.php +++ b/tests/comparisons/Test/testBakeControllerWithoutModelTest.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Test\TestCase\Controller; -use Bake\Test\App\Controller\NoModelController; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; diff --git a/tests/comparisons/Test/testBakePrefixControllerTest.php b/tests/comparisons/Test/testBakePrefixControllerTest.php index 7056f1f41..b2fff19a0 100644 --- a/tests/comparisons/Test/testBakePrefixControllerTest.php +++ b/tests/comparisons/Test/testBakePrefixControllerTest.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Test\TestCase\Controller\Admin; -use Bake\Test\App\Controller\Admin\PostsController; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; diff --git a/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php b/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php index 7056f1f41..b2fff19a0 100644 --- a/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php +++ b/tests/comparisons/Test/testBakePrefixControllerTestWithCliOption.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Test\TestCase\Controller\Admin; -use Bake\Test\App\Controller\Admin\PostsController; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; diff --git a/tests/rector-generated.php b/tests/rector-generated.php new file mode 100644 index 000000000..5b0e229f1 --- /dev/null +++ b/tests/rector-generated.php @@ -0,0 +1,7 @@ +withPaths([]) + ->withCache(cacheDirectory: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'bake-generated-rector'); From db4d8118083373edc93cfbc52e9fb4d64fea3b5c Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Sun, 18 Oct 2026 10:03:47 +0200 Subject: [PATCH 2/4] Update database-specific model comparisons for unused imports --- .../Model/testBakeAssociationDetectionCategoriesTableSigned.php | 2 -- .../testBakeAssociationDetectionOldProductsTableSigned.php | 2 -- .../Model/testBakeAssociationDetectionProductVersionsTable.php | 1 - 3 files changed, 5 deletions(-) diff --git a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTableSigned.php b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTableSigned.php index 9c7643323..f639ac9c2 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTableSigned.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionCategoriesTableSigned.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTableSigned.php b/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTableSigned.php index 49a307a59..d958acb7c 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTableSigned.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionOldProductsTableSigned.php @@ -3,8 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; -use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; diff --git a/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTable.php b/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTable.php index 06fc7d062..4c9e53f0f 100644 --- a/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTable.php +++ b/tests/comparisons/Model/testBakeAssociationDetectionProductVersionsTable.php @@ -3,7 +3,6 @@ namespace Bake\Test\App\Model\Table; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; From 6555a75d88cb33c4798c0f345c6c0b4ac0ee5af6 Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Sun, 18 Oct 2026 13:34:16 +0200 Subject: [PATCH 3/4] Use explicit scalar types for generated controller IDs --- templates/bake/element/Controller/delete.twig | 4 ++-- templates/bake/element/Controller/edit.twig | 4 ++-- templates/bake/element/Controller/view.twig | 4 ++-- tests/comparisons/Controller/testBakeActions.php | 12 ++++++------ .../testBakeActionsAuthenticationPlugin.php | 12 ++++++------ .../testBakeActionsAuthorizationPlugin.php | 12 ++++++------ .../Controller/testBakeActionsContent.php | 12 ++++++------ ...testBakeAuthenticationWithoutAttributeRouting.php | 12 ++++++------ tests/comparisons/Controller/testBakeWithPlugin.php | 12 ++++++------ .../Controller/testBakeWithoutAttributeRouting.php | 12 ++++++------ 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/templates/bake/element/Controller/delete.twig b/templates/bake/element/Controller/delete.twig index 8426c3414..3f49d4ea1 100644 --- a/templates/bake/element/Controller/delete.twig +++ b/templates/bake/element/Controller/delete.twig @@ -16,14 +16,14 @@ /** * Delete method * - * @param string|null $id {{ singularHumanName }} id. + * @param string|int|null $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/delete/{id}')] {% endif %} - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); ${{ singularName }} = $this->{{ currentModelName }}->get($id); diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index ae1daf732..2a52a81a8 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -19,14 +19,14 @@ /** * Edit method * - * @param string|null $id {{ singularHumanName }} id. + * @param string|int|null $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/edit/{id}')] {% endif %} - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/templates/bake/element/Controller/view.twig b/templates/bake/element/Controller/view.twig index 05085fffb..a92ecf929 100644 --- a/templates/bake/element/Controller/view.twig +++ b/templates/bake/element/Controller/view.twig @@ -20,14 +20,14 @@ /** * View method * - * @param string|null $id {{ singularHumanName }} id. + * @param string|int|null $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/view/{id}')] {% endif %} - public function view(mixed $id = null) + public function view(int|string|null $id = null) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(allAssociations)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/tests/comparisons/Controller/testBakeActions.php b/tests/comparisons/Controller/testBakeActions.php index 32e243a36..9c946e7d9 100644 --- a/tests/comparisons/Controller/testBakeActions.php +++ b/tests/comparisons/Controller/testBakeActions.php @@ -50,12 +50,12 @@ public function index() /** * View method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -87,12 +87,12 @@ public function add() /** * Edit method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -112,12 +112,12 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php index 54574f075..5d5d07579 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php @@ -44,12 +44,12 @@ public function index() /** * View method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -79,12 +79,12 @@ public function add() /** * Edit method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -102,12 +102,12 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php index 0356eb0d0..0c256d513 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php @@ -48,12 +48,12 @@ public function index() /** * View method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->Authorization->authorize($bakeArticle); @@ -87,12 +87,12 @@ public function add() /** * Edit method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); $this->Authorization->authorize($bakeArticle); @@ -113,12 +113,12 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsContent.php b/tests/comparisons/Controller/testBakeActionsContent.php index 847eb7f3f..5c03f9690 100644 --- a/tests/comparisons/Controller/testBakeActionsContent.php +++ b/tests/comparisons/Controller/testBakeActionsContent.php @@ -34,12 +34,12 @@ public function index() /** * View method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -71,12 +71,12 @@ public function add() /** * Edit method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -96,12 +96,12 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php index c2f0b6c05..117604856 100644 --- a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php @@ -39,11 +39,11 @@ public function index() /** * View method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -72,11 +72,11 @@ public function add() /** * Edit method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -94,11 +94,11 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id User id. + * @param string|int|null $id User id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeWithPlugin.php b/tests/comparisons/Controller/testBakeWithPlugin.php index fa749d980..93348b562 100644 --- a/tests/comparisons/Controller/testBakeWithPlugin.php +++ b/tests/comparisons/Controller/testBakeWithPlugin.php @@ -35,12 +35,12 @@ public function index() /** * View method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -72,12 +72,12 @@ public function add() /** * Edit method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -97,12 +97,12 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php index 9bee69911..8094b04c7 100644 --- a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php @@ -29,11 +29,11 @@ public function index() /** * View method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view(mixed $id = null) + public function view(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -64,11 +64,11 @@ public function add() /** * Edit method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit(mixed $id = null) + public function edit(int|string|null $id = null) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -88,11 +88,11 @@ public function edit(mixed $id = null) /** * Delete method * - * @param string|null $id Bake Article id. + * @param string|int|null $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete(mixed $id = null): ?Response + public function delete(int|string|null $id = null): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); From 0f1b5226450532d7d49c248be31a75dcc568c28a Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Sun, 18 Oct 2026 13:51:23 +0200 Subject: [PATCH 4/4] Require IDs for generated view, edit, and delete actions --- templates/bake/element/Controller/delete.twig | 4 ++-- templates/bake/element/Controller/edit.twig | 4 ++-- templates/bake/element/Controller/view.twig | 4 ++-- tests/comparisons/Controller/testBakeActions.php | 12 ++++++------ .../testBakeActionsAuthenticationPlugin.php | 12 ++++++------ .../testBakeActionsAuthorizationPlugin.php | 12 ++++++------ .../Controller/testBakeActionsContent.php | 12 ++++++------ ...testBakeAuthenticationWithoutAttributeRouting.php | 12 ++++++------ tests/comparisons/Controller/testBakeWithPlugin.php | 12 ++++++------ .../Controller/testBakeWithoutAttributeRouting.php | 12 ++++++------ 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/templates/bake/element/Controller/delete.twig b/templates/bake/element/Controller/delete.twig index 3f49d4ea1..57b6a5ec2 100644 --- a/templates/bake/element/Controller/delete.twig +++ b/templates/bake/element/Controller/delete.twig @@ -16,14 +16,14 @@ /** * Delete method * - * @param string|int|null $id {{ singularHumanName }} id. + * @param string|int $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/delete/{id}')] {% endif %} - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); ${{ singularName }} = $this->{{ currentModelName }}->get($id); diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index 2a52a81a8..e709c8984 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -19,14 +19,14 @@ /** * Edit method * - * @param string|int|null $id {{ singularHumanName }} id. + * @param string|int $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/edit/{id}')] {% endif %} - public function edit(int|string|null $id = null) + public function edit(int|string $id) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/templates/bake/element/Controller/view.twig b/templates/bake/element/Controller/view.twig index a92ecf929..e3c12dc86 100644 --- a/templates/bake/element/Controller/view.twig +++ b/templates/bake/element/Controller/view.twig @@ -20,14 +20,14 @@ /** * View method * - * @param string|int|null $id {{ singularHumanName }} id. + * @param string|int $id {{ singularHumanName }} id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ {% if attributeRouting %} #[Route('/view/{id}')] {% endif %} - public function view(int|string|null $id = null) + public function view(int|string $id) { ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(allAssociations)|raw }}); {% if Bake.hasPlugin('Authorization') %} diff --git a/tests/comparisons/Controller/testBakeActions.php b/tests/comparisons/Controller/testBakeActions.php index 9c946e7d9..1689ace79 100644 --- a/tests/comparisons/Controller/testBakeActions.php +++ b/tests/comparisons/Controller/testBakeActions.php @@ -50,12 +50,12 @@ public function index() /** * View method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(int|string|null $id = null) + public function view(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -87,12 +87,12 @@ public function add() /** * Edit method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -112,12 +112,12 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php index 5d5d07579..0ddf781a4 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthenticationPlugin.php @@ -44,12 +44,12 @@ public function index() /** * View method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(int|string|null $id = null) + public function view(int|string $id) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -79,12 +79,12 @@ public function add() /** * Edit method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -102,12 +102,12 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php index 0c256d513..ca7326052 100644 --- a/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php +++ b/tests/comparisons/Controller/testBakeActionsAuthorizationPlugin.php @@ -48,12 +48,12 @@ public function index() /** * View method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(int|string|null $id = null) + public function view(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->Authorization->authorize($bakeArticle); @@ -87,12 +87,12 @@ public function add() /** * Edit method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); $this->Authorization->authorize($bakeArticle); @@ -113,12 +113,12 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeActionsContent.php b/tests/comparisons/Controller/testBakeActionsContent.php index 5c03f9690..e2a1b4b7e 100644 --- a/tests/comparisons/Controller/testBakeActionsContent.php +++ b/tests/comparisons/Controller/testBakeActionsContent.php @@ -34,12 +34,12 @@ public function index() /** * View method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(int|string|null $id = null) + public function view(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -71,12 +71,12 @@ public function add() /** * Edit method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -96,12 +96,12 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php index 117604856..6593afdcc 100644 --- a/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeAuthenticationWithoutAttributeRouting.php @@ -39,11 +39,11 @@ public function index() /** * View method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view(int|string|null $id = null) + public function view(int|string $id) { $user = $this->Users->get($id, contain: []); $this->set(compact('user')); @@ -72,11 +72,11 @@ public function add() /** * Edit method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $user = $this->Users->get($id, contain: []); if ($this->request->is(['patch', 'post', 'put'])) { @@ -94,11 +94,11 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id User id. + * @param string|int $id User id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $user = $this->Users->get($id); diff --git a/tests/comparisons/Controller/testBakeWithPlugin.php b/tests/comparisons/Controller/testBakeWithPlugin.php index 93348b562..9140c5585 100644 --- a/tests/comparisons/Controller/testBakeWithPlugin.php +++ b/tests/comparisons/Controller/testBakeWithPlugin.php @@ -35,12 +35,12 @@ public function index() /** * View method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/view/{id}')] - public function view(int|string|null $id = null) + public function view(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -72,12 +72,12 @@ public function add() /** * Edit method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/edit/{id}')] - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -97,12 +97,12 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ #[Route('/delete/{id}')] - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id); diff --git a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php index 8094b04c7..a94e31f5f 100644 --- a/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php +++ b/tests/comparisons/Controller/testBakeWithoutAttributeRouting.php @@ -29,11 +29,11 @@ public function index() /** * View method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function view(int|string|null $id = null) + public function view(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeUsers', 'BakeTags', 'BakeComments']); $this->set(compact('bakeArticle')); @@ -64,11 +64,11 @@ public function add() /** * Edit method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function edit(int|string|null $id = null) + public function edit(int|string $id) { $bakeArticle = $this->BakeArticles->get($id, contain: ['BakeTags']); if ($this->request->is(['patch', 'post', 'put'])) { @@ -88,11 +88,11 @@ public function edit(int|string|null $id = null) /** * Delete method * - * @param string|int|null $id Bake Article id. + * @param string|int $id Bake Article id. * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ - public function delete(int|string|null $id = null): ?Response + public function delete(int|string $id): ?Response { $this->request->allowMethod(['post', 'delete']); $bakeArticle = $this->BakeArticles->get($id);