diff --git a/composer.json b/composer.json index 51fc28e6..47a90bf6 100644 --- a/composer.json +++ b/composer.json @@ -53,15 +53,15 @@ "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", "phpstan/extension-installer": "^1.0", "phpstan/phpdoc-parser": "^1.0", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpstan/phpstan-symfony": "^1.0", + "phpstan/phpstan": "^1.0 || ^2.0", + "phpstan/phpstan-phpunit": "^1.0 || ^2.0", + "phpstan/phpstan-strict-rules": "^1.0 || ^2.0", + "phpstan/phpstan-symfony": "^1.0 || ^2.0", "phpunit/phpunit": "^9.5", - "psalm/plugin-phpunit": "^0.18", + "psalm/plugin-phpunit": "^0.18 || ^0.19", "psalm/plugin-symfony": "^5.0", - "rector/rector": "^1.1", - "sonata-project/admin-bundle": "^4.34", + "rector/rector": "^1.1 || ^2.0", + "sonata-project/admin-bundle": "^4.35.4", "sonata-project/block-bundle": "^4.11 || ^5.0", "sonata-project/doctrine-orm-admin-bundle": "^4.0", "symfony/asset": "^6.4 || ^7.1", @@ -72,7 +72,7 @@ "symfony/security-csrf": "^6.4 || ^7.1", "symfony/twig-bundle": "^6.4 || ^7.1", "symfony/yaml": "^6.4 || ^7.1", - "vimeo/psalm": "^5.0" + "vimeo/psalm": "^5.0 || ^6.10" }, "conflict": { "doctrine/mongodb-odm": "<2.4", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 299dcdbf..f8582891 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11,3 +11,6 @@ parameters: message: "#^Parameter \\#2 \\$category of method Sonata\\\\ClassificationBundle\\\\Form\\\\Type\\\\CategorySelectorType\\:\\:childWalker\\(\\) expects Sonata\\\\ClassificationBundle\\\\Model\\\\CategoryInterface, Sonata\\\\ClassificationBundle\\\\Model\\\\CategoryInterface\\|Sonata\\\\ClassificationBundle\\\\Model\\\\ContextInterface given\\.$#" count: 1 path: src/Form/Type/CategorySelectorType.php + - + message: '#^Call to method get\(\) of internal class Symfony\\Bundle\\FrameworkBundle\\Test\\TestContainer from outside its root namespace Symfony.$#' + path: tests/ diff --git a/psalm.xml b/psalm.xml index 72447cea..626e338b 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,11 +12,7 @@ - - - - - + diff --git a/src/DependencyInjection/SonataClassificationExtension.php b/src/DependencyInjection/SonataClassificationExtension.php index a546e7d7..7c1b713e 100644 --- a/src/DependencyInjection/SonataClassificationExtension.php +++ b/src/DependencyInjection/SonataClassificationExtension.php @@ -136,9 +136,12 @@ private function registerSonataDoctrineMapping(array $config): void ); $categoryCascade = ['persist', 'refresh', 'merge', 'detach']; - $categoryIsEntity = \in_array(BaseCategory::class, class_parents($config['class']['category']), true); - if ($categoryIsEntity && class_exists(EntityManager::class) && !method_exists(EntityManager::class, 'merge')) { // @phpstan-ignore-line - unset($categoryCascade[array_search('merge', $categoryCascade, true)]); + $parents = class_parents($config['class']['category']); + if (false !== $parents) { + $categoryIsEntity = \in_array(BaseCategory::class, $parents, true); + if ($categoryIsEntity && class_exists(EntityManager::class) && !method_exists(EntityManager::class, 'merge')) { // @phpstan-ignore-line + unset($categoryCascade[array_search('merge', $categoryCascade, true)]); + } } $collector->addAssociation( $config['class']['category'], diff --git a/tests/Admin/Filter/CategoryFilterTest.php b/tests/Admin/Filter/CategoryFilterTest.php index 09a93139..1daa613e 100644 --- a/tests/Admin/Filter/CategoryFilterTest.php +++ b/tests/Admin/Filter/CategoryFilterTest.php @@ -30,7 +30,7 @@ final class CategoryFilterTest extends TestCase protected function setUp(): void { - $this->categoryManager = $this->createStub(CategoryManagerInterface::class); + $this->categoryManager = static::createStub(CategoryManagerInterface::class); } public function testRenderSettings(): void diff --git a/tests/Admin/Filter/CollectionFilterTest.php b/tests/Admin/Filter/CollectionFilterTest.php index 4d74f75e..e56f3c9a 100644 --- a/tests/Admin/Filter/CollectionFilterTest.php +++ b/tests/Admin/Filter/CollectionFilterTest.php @@ -28,7 +28,7 @@ final class CollectionFilterTest extends TestCase protected function setUp(): void { - $this->collectionManager = $this->createStub(CollectionManagerInterface::class); + $this->collectionManager = static::createStub(CollectionManagerInterface::class); } public function testRenderSettings(): void diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index e76c24d6..d1598b89 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -33,6 +33,7 @@ use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; use Symfony\Component\Security\Http\Attribute\IsGranted; +use Symfony\UX\StimulusBundle\StimulusBundle; final class AppKernel extends Kernel { @@ -54,6 +55,7 @@ public function registerBundles(): iterable new SonataDoctrineORMAdminBundle(), new SonataClassificationBundle(), new TwigBundle(), + new StimulusBundle(), ]; } diff --git a/tests/App/Entity/Category.php b/tests/App/Entity/Category.php index b04b2cbc..4e49d603 100644 --- a/tests/App/Entity/Category.php +++ b/tests/App/Entity/Category.php @@ -17,6 +17,9 @@ use Doctrine\ORM\Mapping as ORM; use Sonata\ClassificationBundle\Entity\BaseCategory; +/** + * @psalm-suppress ClassMustBeFinal + */ #[ORM\Entity] #[ORM\Table(name: 'classification__category')] class Category extends BaseCategory diff --git a/tests/App/Entity/Collection.php b/tests/App/Entity/Collection.php index b159c813..07896372 100644 --- a/tests/App/Entity/Collection.php +++ b/tests/App/Entity/Collection.php @@ -17,6 +17,9 @@ use Doctrine\ORM\Mapping as ORM; use Sonata\ClassificationBundle\Entity\BaseCollection; +/** + * @psalm-suppress ClassMustBeFinal + */ #[ORM\Entity] #[ORM\Table(name: 'classification__collection')] class Collection extends BaseCollection diff --git a/tests/App/Entity/Context.php b/tests/App/Entity/Context.php index 2b8a4f59..a800fef9 100644 --- a/tests/App/Entity/Context.php +++ b/tests/App/Entity/Context.php @@ -17,6 +17,9 @@ use Doctrine\ORM\Mapping as ORM; use Sonata\ClassificationBundle\Entity\BaseContext; +/** + * @psalm-suppress ClassMustBeFinal + */ #[ORM\Entity] #[ORM\Table(name: 'classification__context')] class Context extends BaseContext diff --git a/tests/App/Entity/Tag.php b/tests/App/Entity/Tag.php index 9382917a..6c3633a2 100644 --- a/tests/App/Entity/Tag.php +++ b/tests/App/Entity/Tag.php @@ -17,6 +17,9 @@ use Doctrine\ORM\Mapping as ORM; use Sonata\ClassificationBundle\Entity\BaseTag; +/** + * @psalm-suppress ClassMustBeFinal + */ #[ORM\Entity] #[ORM\Table(name: 'classification__tag')] class Tag extends BaseTag diff --git a/tests/Entity/CategoryManagerTest.php b/tests/Entity/CategoryManagerTest.php index daeb44ad..9c4289e2 100644 --- a/tests/Entity/CategoryManagerTest.php +++ b/tests/Entity/CategoryManagerTest.php @@ -20,7 +20,7 @@ use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -class CategoryManagerTest extends KernelTestCase +final class CategoryManagerTest extends KernelTestCase { public function testGetRootCategoryWithChildren(): void { diff --git a/tests/Form/Type/CategorySelectorTypeTest.php b/tests/Form/Type/CategorySelectorTypeTest.php index f881d604..2c653bda 100644 --- a/tests/Form/Type/CategorySelectorTypeTest.php +++ b/tests/Form/Type/CategorySelectorTypeTest.php @@ -26,7 +26,7 @@ final class CategorySelectorTypeTest extends TestCase { public function testConfigureOptions(): void { - $manager = $this->createStub(CategoryManagerInterface::class); + $manager = static::createStub(CategoryManagerInterface::class); $categorySelectorType = new CategorySelectorType($manager); $optionsResolver = new OptionsResolver(); $categorySelectorType->configureOptions($optionsResolver);