diff --git a/composer.json b/composer.json index d34700e..34713d6 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "cakephp/plugin-installer": "^1.3", "league/flysystem-memory": "^3.0", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan": "^2.2", + "phpstan/phpstan-deprecation-rules": "^2.0", "phpunit/phpunit": "^11.1", "vimeo/psalm": "^6.8" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5f9db58..c7b2876 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,3 +5,9 @@ parameters: - src - tests level: 8 + ignoreErrors: + - + # Outdated `@method` annotation on BEdita\Core\Model\Table\MediaTable + message: '#^Unknown parameter \$contain in call to method BEdita\\Core\\Model\\Table\\MediaTable::get\(\)\.$#' + identifier: argument.unknown + path: tests diff --git a/src/Event/JsonSchemaEventHandler.php b/src/Event/JsonSchemaEventHandler.php index 53fc35f..ddecad7 100644 --- a/src/Event/JsonSchemaEventHandler.php +++ b/src/Event/JsonSchemaEventHandler.php @@ -43,13 +43,13 @@ public function implementedEvents(): array * @param \Cake\Event\Event<\BEdita\Core\Model\Table\ObjectTypesTable> $event Dispatched event. * @param array $schema Automatically generated JSON schema. * @param \BEdita\Core\Model\Entity\ObjectType $objectType Object type. - * @return array + * @return void */ - public function onGetSchema(Event $event, array $schema, ObjectType $objectType): array + public function onGetSchema(Event $event, array $schema, ObjectType $objectType): void { $table = $this->getTableLocator()->get($objectType->table); if (!$table->hasBehavior('Placeholders')) { - return $schema; + return; } $behavior = $table->getBehavior('Placeholders'); @@ -76,6 +76,6 @@ public function onGetSchema(Event $event, array $schema, ObjectType $objectType) $schema['relations'][$relName]['readonly'] = true; } - return $schema; + $event->setResult($schema); } } diff --git a/src/Plugin.php b/src/PlaceholdersPlugin.php similarity index 89% rename from src/Plugin.php rename to src/PlaceholdersPlugin.php index 83a7e0e..29639d0 100644 --- a/src/Plugin.php +++ b/src/PlaceholdersPlugin.php @@ -24,12 +24,12 @@ /** * Plugin for BEdita\Placeholders */ -class Plugin extends BasePlugin +class PlaceholdersPlugin extends BasePlugin { /** * {@inheritDoc} * - * @param \Cake\Core\PluginApplicationInterface<\Cake\Core\ContainerInterface> $app + * @param \Cake\Core\PluginApplicationInterface $app * @codeCoverageIgnore */ public function bootstrap(PluginApplicationInterface $app): void diff --git a/tests/TestApp/Application.php b/tests/TestApp/Application.php index 73cbc36..243463c 100644 --- a/tests/TestApp/Application.php +++ b/tests/TestApp/Application.php @@ -24,8 +24,6 @@ * * This defines the bootstrapping logic and middleware layers you * want to use in your application. - * - * @extends \Cake\Http\BaseApplication<\BEdita\Placeholders\Test\TestApp\Application> */ class Application extends BaseApplication { diff --git a/tests/TestCase/Controller/Component/PlaceholdersComponentTest.php b/tests/TestCase/Controller/Component/PlaceholdersComponentTest.php index f1acc93..371de42 100644 --- a/tests/TestCase/Controller/Component/PlaceholdersComponentTest.php +++ b/tests/TestCase/Controller/Component/PlaceholdersComponentTest.php @@ -50,16 +50,6 @@ public function setUp(): void $this->controller->loadComponent(PlaceholdersComponent::class); } - /** - * @inheritDoc - */ - public function tearDown(): void - { - unset($this->controller); - - parent::tearDown(); - } - /** * Data provider for {@see PlaceholdersComponentTest::testBeforeFilter()} test case. * diff --git a/tests/TestCase/Model/Behavior/PlaceholdedBehaviorTest.php b/tests/TestCase/Model/Behavior/PlaceholdedBehaviorTest.php index 482df01..dc463dd 100644 --- a/tests/TestCase/Model/Behavior/PlaceholdedBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/PlaceholdedBehaviorTest.php @@ -69,16 +69,16 @@ class PlaceholdedBehaviorTest extends TestCase /** * ObjectsTable instance * - * @var \BEdita\Core\Model\Table\ObjectsTable|null + * @var \BEdita\Core\Model\Table\ObjectsTable */ - protected ?ObjectsTable $Documents = null; + protected ObjectsTable $Documents; /** * MediaTable instance * - * @var \BEdita\Core\Model\Table\MediaTable|null + * @var \BEdita\Core\Model\Table\MediaTable */ - protected ?MediaTable $Media = null; + protected MediaTable $Media; /** * @inheritDoc @@ -107,17 +107,17 @@ public function testBeforeSaveLockedEntity(): void $body = '

My sweet placeholder

'; // Save with placeholder in body. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes']); $document->body = $body; $this->Documents->saveOrFail($document); - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame([10], Hash::extract($document->get('placeholder'), '{n}.id')); // Try to delete media. $this->expectException(LockedResourceException::class); $this->expectExceptionMessage('Cannot delete object 10 because it is still placeholded in one object'); - $media = $this->Media->get(10, ['contain' => ['ObjectTypes']]); + $media = $this->Media->get(10, contain: ['ObjectTypes']); $media->deleted = true; $this->Media->saveOrFail($media); } @@ -129,7 +129,7 @@ public function testBeforeSaveLockedEntity(): void */ public function testBeforeSaveFreeEntity(): void { - $media = $this->Media->get(10, ['contain' => ['ObjectTypes']]); + $media = $this->Media->get(10, contain: ['ObjectTypes']); $media->deleted = true; $actual = $this->Media->saveOrFail($media); diff --git a/tests/TestCase/Model/Behavior/PlaceholdersBehaviorTest.php b/tests/TestCase/Model/Behavior/PlaceholdersBehaviorTest.php index 3ed349d..eda2488 100644 --- a/tests/TestCase/Model/Behavior/PlaceholdersBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/PlaceholdersBehaviorTest.php @@ -71,16 +71,16 @@ class PlaceholdersBehaviorTest extends TestCase /** * ObjectsTable instance * - * @var \BEdita\Core\Model\Table\ObjectsTable|null + * @var \BEdita\Core\Model\Table\ObjectsTable */ - protected ?ObjectsTable $Documents = null; + protected ObjectsTable $Documents; /** * MediaTable instance * - * @var \BEdita\Core\Model\Table\MediaTable|null + * @var \BEdita\Core\Model\Table\MediaTable */ - protected ?MediaTable $Media = null; + protected MediaTable $Media; /** * @inheritDoc @@ -293,7 +293,7 @@ public function testSavePlaceholders(): void $this->Documents->saveOrFail($document); // Reload entity from database, with placeholders. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame($body, $document->body, 'Entity body has been changed'); static::assertTrue($document->has('placeholder')); @@ -337,21 +337,21 @@ public function testSavePlaceholdersReplace(): void // Save hypothetical previous data. $action = new AddRelatedObjectsAction(['association' => $this->Documents->getAssociation('Placeholder')]); $action([ - 'entity' => $this->Documents->get(2, ['contain' => ['ObjectTypes']]), + 'entity' => $this->Documents->get(2, contain: ['ObjectTypes']), 'relatedEntities' => [ - $this->Media->get(10, ['contain' => ['ObjectTypes']])->set(['_joinData' => ['params' => ['description' => []]]]), - $this->Media->get(14, ['contain' => ['ObjectTypes']]), + $this->Media->get(10, contain: ['ObjectTypes'])->patch(['_joinData' => ['params' => ['description' => []]]]), + $this->Media->get(14, contain: ['ObjectTypes']), ], ]); // Save with placeholder in body. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame([10, 14], Hash::extract($document->get('placeholder'), '{n}.id')); // Check that previous placeholders exist. $document->body = $body; $this->Documents->saveOrFail($document); // Reload entity from database, with placeholders. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame($body, $document->body, 'Entity body has been changed'); static::assertTrue($document->has('placeholder')); @@ -379,21 +379,21 @@ public function testSavePlaceholdersRemove(): void // Save hypothetical previous data. $action = new AddRelatedObjectsAction(['association' => $this->Documents->getAssociation('Placeholder')]); $action([ - 'entity' => $this->Documents->get(2, ['contain' => ['ObjectTypes']]), + 'entity' => $this->Documents->get(2, contain: ['ObjectTypes']), 'relatedEntities' => [ - $this->Media->get(10, ['contain' => ['ObjectTypes']])->set(['_joinData' => ['params' => ['description' => []]]]), - $this->Media->get(14, ['contain' => ['ObjectTypes']]), + $this->Media->get(10, contain: ['ObjectTypes'])->patch(['_joinData' => ['params' => ['description' => []]]]), + $this->Media->get(14, contain: ['ObjectTypes']), ], ]); // Save with placeholder in body. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame([10, 14], Hash::extract($document->get('placeholder'), '{n}.id')); // Check that previous placeholders exist. $document->body = $body; $this->Documents->saveOrFail($document); // Reload entity from database, with placeholders. - $document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]); + $document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']); static::assertSame($body, $document->body, 'Entity body has been changed'); static::assertTrue($document->has('placeholder'));