Skip to content

Commit

Permalink
Dynamically fix compatibility with doctrine/data-fixtures v2
Browse files Browse the repository at this point in the history
Classes that extend ContainerAwareLoader have to also extend Loader, meaning
this is no breaking change because it can be argued that the incompatibility of
the extending class would be with the Loader interface.
  • Loading branch information
greg0ire authored and nicolas-grekas committed Nov 20, 2024
1 parent 4b8695c commit 1812aaf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"doctrine/annotations": "^1.13.1|^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/collections": "^1.0|^2.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/data-fixtures": "^1.1|^2",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.7.4",
"guzzlehttp/promises": "^1.4|^2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\DataFixtures;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\ReferenceRepository;

if (method_exists(ReferenceRepository::class, 'getReferences')) {
/** @internal */
trait AddFixtureImplementation
{
public function addFixture(FixtureInterface $fixture)
{
$this->doAddFixture($fixture);
}
}
} else {
/** @internal */
trait AddFixtureImplementation

Check failure on line 28 in src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php:28:11: DuplicateClass: Class Symfony\Bridge\Doctrine\DataFixtures\AddFixtureImplementation has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php (see https://psalm.dev/071)

Check failure on line 28 in src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php

View workflow job for this annotation

GitHub Actions / Psalm

DuplicateClass

src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php:28:11: DuplicateClass: Class Symfony\Bridge\Doctrine\DataFixtures\AddFixtureImplementation has already been defined in /home/runner/work/symfony/symfony/src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php (see https://psalm.dev/071)
{
public function addFixture(FixtureInterface $fixture): void

Check failure on line 30 in src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php:30:9: MethodSignatureMismatch: Method Symfony\Bridge\Doctrine\DataFixtures\AddFixtureImplementation::addFixture with return type '' is different to return type 'void' of inherited method Doctrine\Common\DataFixtures\Loader::addFixture (see https://psalm.dev/042)

Check failure on line 30 in src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/Symfony/Bridge/Doctrine/DataFixtures/AddFixtureImplementation.php:30:9: MethodSignatureMismatch: Method Symfony\Bridge\Doctrine\DataFixtures\AddFixtureImplementation::addFixture with return type '' is different to return type 'void' of inherited method Doctrine\Common\DataFixtures\Loader::addFixture (see https://psalm.dev/042)
{
$this->doAddFixture($fixture);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
*/
class ContainerAwareLoader extends Loader
{
use AddFixtureImplementation;

private $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

/**
* {@inheritdoc}
*/
public function addFixture(FixtureInterface $fixture)
private function doAddFixture(FixtureInterface $fixture): void
{
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"symfony/var-dumper": "^4.4|^5.0|^6.0",
"doctrine/annotations": "^1.10.4|^2",
"doctrine/collections": "^1.0|^2.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/data-fixtures": "^1.1|^2",
"doctrine/dbal": "^2.13.1|^3|^4",
"doctrine/orm": "^2.7.4|^3",
"psr/log": "^1|^2|^3"
Expand Down

0 comments on commit 1812aaf

Please sign in to comment.