Skip to content

Commit

Permalink
Add parameter types and update CS for PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 14, 2023
1 parent eb3667b commit 6fcf84e
Show file tree
Hide file tree
Showing 37 changed files with 132 additions and 204 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
2 changes: 1 addition & 1 deletion 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 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
22 changes: 9 additions & 13 deletions src/AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ private function getReferenceRepository(): ReferenceRepository
* and referenced to managed $object. If $name
* already is set, it overrides it
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference
* @see ReferenceRepository::setReference()
*
* @param string $name
* @param object $object - managed object
* @param object $object managed object
*
* @return void
*/
public function setReference($name, $object)
public function setReference(string $name, object $object)
{
$this->getReferenceRepository()->setReference($name, $object);
}
Expand All @@ -61,16 +60,15 @@ public function setReference($name, $object)
* already is set, it throws a
* BadMethodCallException exception
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference
* @see ReferenceRepository::addReference()
*
* @param string $name
* @param object $object - managed object
*
* @return void
*
* @throws BadMethodCallException - if repository already has a reference by $name.
*/
public function addReference($name, $object)
public function addReference(string $name, object $object)
{
$this->getReferenceRepository()->addReference($name, $object);
}
Expand All @@ -79,17 +77,16 @@ public function addReference($name, $object)
* Loads an object using stored reference
* named by $name
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference
* @see ReferenceRepository::getReference()
*
* @param string $name
* @psalm-param class-string<T>|null $class
*
* @return object
* @psalm-return ($class is null ? object : T)
*
* @template T of object
*/
public function getReference($name, ?string $class = null)
public function getReference(string $name, string|null $class = null)
{
if ($class === null) {
Deprecation::trigger(
Expand All @@ -107,14 +104,13 @@ public function getReference($name, ?string $class = null)
* Check if an object is stored using reference
* named by $name
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference
* @see ReferenceRepository::hasReference()
*
* @param string $name
* @psalm-param class-string $class
*
* @return bool
*/
public function hasReference($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);
}
}
}
11 changes: 3 additions & 8 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 @@ -76,23 +75,19 @@ public function getPurger()
/**
* Set the logger callable to execute with the log() method.
*
* @param callable $logger
*
* @return void
*/
public function setLogger($logger)
public function setLogger(callable $logger)
{
$this->logger = $logger;
}

/**
* Logs a message using the logger.
*
* @param string $message
*
* @return void
*/
public function log($message)
public function log(string $message)
{
$logger = $this->logger;
$logger($message);
Expand All @@ -111,7 +106,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
6 changes: 2 additions & 4 deletions src/Executor/MongoDBExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,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 Expand Up @@ -60,7 +58,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository)
}

/** @inheritDoc */
public function execute(array $fixtures, $append = false)
public function execute(array $fixtures, bool $append = false)
{
if ($append === false) {
$this->purge();
Expand Down
2 changes: 1 addition & 1 deletion src/Executor/MultipleTransactionORMExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class MultipleTransactionORMExecutor extends AbstractExecutor
use ORMExecutorCommon;

/** @inheritDoc */
public function execute(array $fixtures, $append = false): void
public function execute(array $fixtures, bool $append = false): void
{
$executor = $this;
if ($append === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Executor/ORMExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ORMExecutor extends AbstractExecutor
use ORMExecutorCommon;

/** @inheritDoc */
public function execute(array $fixtures, $append = false)
public function execute(array $fixtures, bool $append = false)
{
$executor = $this;
$this->em->wrapInTransaction(static function (EntityManagerInterface $em) use ($executor, $fixtures, $append) {
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
7 changes: 2 additions & 5 deletions src/Executor/PHPCRExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,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 All @@ -40,7 +37,7 @@ public function getObjectManager()
}

/** @inheritDoc */
public function execute(array $fixtures, $append = false)
public function execute(array $fixtures, bool $append = false)
{
$that = $this;

Expand Down
Loading

0 comments on commit 6fcf84e

Please sign in to comment.