Skip to content

Commit

Permalink
Drop support for PHP 7
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Dec 16, 2023
1 parent c39f678 commit a853610
Show file tree
Hide file tree
Showing 36 changed files with 103 additions and 140 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand All @@ -35,7 +33,7 @@ jobs:
stability:
- "stable"
include:
- php-version: "7.4"
- php-version: "8.1"
dependencies: "lowest"
stability: "stable"
- php-version: "8.3"
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ awareness about deprecated code.
- Use of our low-overhead runtime deprecation API, details:
https://github.com/doctrine/deprecations/

# Upgrade to 2.0

You need PHP 8.1 or newer to use this library.

# Upgrade to 1.8

Executor and Purger classes are final, they cannot be extended.
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"doctrine/deprecations": "^0.5.3 || ^1.0",
"doctrine/persistence": "^2.0|^3.0"
},
Expand All @@ -31,10 +31,10 @@
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
"doctrine/orm": "^2.14 || ^3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6.13 || ^10.4.2",
"symfony/cache": "^5.4 || ^6.3 || ^7",
"symfony/var-exporter": "^5.4 || ^6.3 || ^7",
"vimeo/psalm": "^5.9"
"phpunit/phpunit": "^10.5.3",
"symfony/cache": "^6.4 || ^7",
"symfony/var-exporter": "^6.4 || ^7",
"vimeo/psalm": "^5.18"
},
"suggest": {
"alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)",
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors" />

<config name="php_version" value="70400"/>
<config name="php_version" value="80100"/>

<!-- Ignore warnings and show progress of the run -->
<arg value="nps"/>
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parameters:

-
message: "#^Property Doctrine\\\\Common\\\\DataFixtures\\\\Executor\\\\PHPCRExecutor\\:\\:\\$dm has unknown class Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManagerInterface as its type\\.$#"
count: 1
count: 2
path: src/Executor/PHPCRExecutor.php

-
Expand Down
6 changes: 2 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.9.0@8b9ad1eb9e8b7d3101f949291da2b9f7767cd163">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="src/Executor/PHPCRExecutor.php">
<UndefinedClass>
<code>DocumentManagerInterface</code>
<code>DocumentManagerInterface</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>DocumentManagerInterface</code>
Expand All @@ -12,10 +11,9 @@
<file src="src/Purger/PHPCRPurger.php">
<UndefinedClass>
<code><![CDATA[$this->dm]]></code>
<code>?DocumentManagerInterface</code>
<code>?DocumentManagerInterface</code>
<code>DocumentManager</code>
<code>NodeHelper</code>
<code>private</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>DocumentManagerInterface|null</code>
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function addReference(string $name, object $object)
*
* @template T of object
*/
public function getReference(string $name, ?string $class = null)
public function getReference(string $name, string|null $class = null)
{
if ($class === null) {
Deprecation::trigger(
Expand All @@ -110,7 +110,7 @@ public function getReference(string $name, ?string $class = null)
*
* @return bool
*/
public function hasReference(string $name, ?string $class = null)
public function hasReference(string $name, string|null $class = null)
{
if ($class === null) {
Deprecation::trigger(
Expand Down
9 changes: 2 additions & 7 deletions src/Event/Listener/MongoDBReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;

use function get_class;

/**
* Reference Listener populates identities for
* stored references
*/
final class MongoDBReferenceListener implements EventSubscriber
{
private ReferenceRepository $referenceRepository;

public function __construct(ReferenceRepository $referenceRepository)
public function __construct(private ReferenceRepository $referenceRepository)
{
$this->referenceRepository = $referenceRepository;
}

/**
Expand Down Expand Up @@ -48,7 +43,7 @@ public function postPersist(LifecycleEventArgs $args): void
->getUnitOfWork()
->getDocumentIdentifier($object);

$this->referenceRepository->setReferenceIdentity($name, $identity, get_class($object));
$this->referenceRepository->setReferenceIdentity($name, $identity, $object::class);
}
}
}
9 changes: 2 additions & 7 deletions src/Event/Listener/ORMReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\PostPersistEventArgs;

use function get_class;

/**
* Reference Listener populates identities for
* stored references
*/
final class ORMReferenceListener implements EventSubscriber
{
private ReferenceRepository $referenceRepository;

public function __construct(ReferenceRepository $referenceRepository)
public function __construct(private ReferenceRepository $referenceRepository)
{
$this->referenceRepository = $referenceRepository;
}

/**
Expand Down Expand Up @@ -49,7 +44,7 @@ public function postPersist(PostPersistEventArgs $args): void
->getUnitOfWork()
->getEntityIdentifier($object);

$this->referenceRepository->setReferenceIdentity($name, $identity, get_class($object));
$this->referenceRepository->setReferenceIdentity($name, $identity, $object::class);
}
}
}
3 changes: 1 addition & 2 deletions src/Executor/AbstractExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\Persistence\ObjectManager;
use Exception;

use function get_class;
use function sprintf;

/**
Expand Down Expand Up @@ -109,7 +108,7 @@ public function load(ObjectManager $manager, FixtureInterface $fixture)
$prefix = sprintf('[%d] ', $fixture->getOrder());
}

$this->log('loading ' . $prefix . get_class($fixture));
$this->log('loading ' . $prefix . $fixture::class);
}

// additionally pass the instance of reference repository to shared fixtures
Expand Down
4 changes: 1 addition & 3 deletions src/Executor/MongoDBExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
*/
class MongoDBExecutor extends AbstractExecutor
{
private DocumentManager $dm;
private MongoDBReferenceListener $listener;

/**
* Construct new fixtures loader instance.
*
* @param DocumentManager $dm DocumentManager instance used for persistence.
*/
public function __construct(DocumentManager $dm, ?MongoDBPurger $purger = null)
public function __construct(private DocumentManager $dm, MongoDBPurger|null $purger = null)
{
$this->dm = $dm;
if ($purger !== null) {
$this->purger = $purger;
$this->purger->setDocumentManager($dm);
Expand Down
2 changes: 1 addition & 1 deletion src/Executor/ORMExecutorCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait ORMExecutorCommon
private EntityManagerInterface $originalManager;
private ORMReferenceListener $listener;

public function __construct(EntityManagerInterface $em, ?ORMPurgerInterface $purger = null)
public function __construct(EntityManagerInterface $em, ORMPurgerInterface|null $purger = null)
{
$this->originalManager = $em;
// Make sure, wrapInTransaction() exists on the EM.
Expand Down
5 changes: 1 addition & 4 deletions src/Executor/PHPCRExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
*/
class PHPCRExecutor extends AbstractExecutor
{
private DocumentManagerInterface $dm;

/**
* @param DocumentManagerInterface $dm manager instance used for persisting the fixtures
* @param PHPCRPurger|null $purger to remove the current data if append is false
*/
public function __construct(DocumentManagerInterface $dm, ?PHPCRPurger $purger = null)
public function __construct(private DocumentManagerInterface $dm, PHPCRPurger|null $purger = null)
{
parent::__construct($dm);

$this->dm = $dm;
if ($purger === null) {
return;
}
Expand Down
11 changes: 5 additions & 6 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function class_exists;
use function class_implements;
use function count;
use function get_class;
use function get_declared_classes;
use function implode;
use function in_array;
Expand Down Expand Up @@ -112,7 +111,7 @@ public function loadFromFile(string $fileName)
*/
public function hasFixture(FixtureInterface $fixture)
{
return isset($this->fixtures[get_class($fixture)]);
return isset($this->fixtures[$fixture::class]);
}

/**
Expand All @@ -137,7 +136,7 @@ public function getFixture(string $className)
*/
public function addFixture(FixtureInterface $fixture)
{
$fixtureClass = get_class($fixture);
$fixtureClass = $fixture::class;

if (isset($this->fixtures[$fixtureClass])) {
return;
Expand All @@ -146,7 +145,7 @@ public function addFixture(FixtureInterface $fixture)
if ($fixture instanceof OrderedFixtureInterface && $fixture instanceof DependentFixtureInterface) {
throw new InvalidArgumentException(sprintf(
'Class "%s" can\'t implement "%s" and "%s" at the same time.',
get_class($fixture),
$fixture::class,
'OrderedFixtureInterface',
'DependentFixtureInterface',
));
Expand Down Expand Up @@ -281,7 +280,7 @@ private function orderFixturesByDependencies()

// First we determine which classes has dependencies and which don't
foreach ($this->fixtures as $fixture) {
$fixtureClass = get_class($fixture);
$fixtureClass = $fixture::class;

if ($fixture instanceof OrderedFixtureInterface) {
continue;
Expand Down Expand Up @@ -382,7 +381,7 @@ private function validateDependencies(iterable $dependenciesClasses): bool
*
* @psalm-return array<class-string<FixtureInterface>>
*/
private function getUnsequencedClasses(array $sequences, ?iterable $classes = null): array
private function getUnsequencedClasses(array $sequences, iterable|null $classes = null): array
{
$unsequencedClasses = [];

Expand Down
3 changes: 1 addition & 2 deletions src/ProxyReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use function file_exists;
use function file_get_contents;
use function file_put_contents;
use function get_class;
use function serialize;
use function unserialize;

Expand All @@ -30,7 +29,7 @@ public function serialize()
$simpleReferences = [];

foreach ($this->getReferences() as $name => $reference) {
$className = $this->getRealClass(get_class($reference));
$className = $this->getRealClass($reference::class);

$simpleReferences[$name] = [$className, $this->getIdentifier($reference, $unitOfWork)];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Purger/MongoDBPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
*/
class MongoDBPurger implements PurgerInterface
{
private ?DocumentManager $dm;

/**
* Construct new purger instance.
*
* @param DocumentManager|null $dm DocumentManager instance used for persistence.
*/
public function __construct(?DocumentManager $dm = null)
public function __construct(private DocumentManager|null $dm = null)
{
$this->dm = $dm;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Purger/ORMPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ORMPurger implements PurgerInterface, ORMPurgerInterface
public const PURGE_MODE_DELETE = 1;
public const PURGE_MODE_TRUNCATE = 2;

private ?EntityManagerInterface $em;

/**
* If the purge should be done through DELETE or TRUNCATE statements
*
Expand All @@ -44,17 +42,16 @@ class ORMPurger implements PurgerInterface, ORMPurgerInterface
private array $excluded;

/** @var list<string>|null */
private ?array $cachedSqlStatements = null;
private array|null $cachedSqlStatements = null;

/**
* Construct new purger instance.
*
* @param EntityManagerInterface|null $em EntityManagerInterface instance used for persistence.
* @param string[] $excluded array of table/view names to be excluded from purge
*/
public function __construct(?EntityManagerInterface $em = null, array $excluded = [])
public function __construct(private EntityManagerInterface|null $em = null, array $excluded = [])
{
$this->em = $em;
$this->excluded = $excluded;
}

Expand Down Expand Up @@ -261,7 +258,7 @@ private function getTableName(ClassMetadata $class, AbstractPlatform $platform):
private function getJoinTableName(
$assoc,
ClassMetadata $class,
AbstractPlatform $platform
AbstractPlatform $platform,
): string {
return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Purger/PHPCRPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/
class PHPCRPurger implements PurgerInterface
{
private ?DocumentManagerInterface $dm;

public function __construct(?DocumentManagerInterface $dm = null)
public function __construct(private DocumentManagerInterface|null $dm = null)
{
$this->dm = $dm;
}

public function setDocumentManager(DocumentManager $dm)
Expand Down
Loading

0 comments on commit a853610

Please sign in to comment.