Skip to content

Commit

Permalink
Modernize codebase for PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Apr 3, 2023
1 parent 4d16277 commit 5330482
Show file tree
Hide file tree
Showing 43 changed files with 220 additions and 299 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
dependencies:
- "highest"
include:
- php-version: "7.2"
- php-version: "7.4"
dependencies: "lowest"

steps:
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"doctrine/persistence": "^2.0|^3.0"
},
"conflict": {
"doctrine/dbal": "<2.13",
"doctrine/orm": "<2.12",
"doctrine/orm": "<2.13",
"doctrine/phpcr-odm": "<1.3.0"
},
"require-dev": {
"ext-sqlite3": "*",
"doctrine/coding-standard": "^11.0",
"doctrine/coding-standard": "^11.1",
"doctrine/dbal": "^2.13 || ^3.0",
"doctrine/deprecations": "^1.0",
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
"doctrine/orm": "^2.12",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5 || ^9.5 || ^10.0",
"symfony/cache": "^5.0 || ^6.0",
"vimeo/psalm": "^4.10 || ^5.9"
"doctrine/orm": "^2.13",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6.6 || ^10.0",
"symfony/cache": "^5.4 || ^6.2",
"vimeo/psalm": "^5.9"
},
"suggest": {
"alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)",
Expand Down
24 changes: 19 additions & 5 deletions 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="70200"/>
<config name="php_version" value="70400"/>

<!-- Ignore warnings and show progress of the run -->
<arg value="nps"/>
Expand All @@ -19,10 +19,6 @@
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>

<!-- Will cause BC breaks to method signatures - disabled for now -->
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
Expand All @@ -47,6 +43,24 @@
<exclude-pattern>src/SharedFixtureInterface.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
<!-- Adding property types is a BC break in most cases. -->
<exclude-pattern>src/*</exclude-pattern>

<!-- Don't add parameter types to overridden methods -->
<exclude-pattern>tests/Common/DataFixtures/TestTypes/UuidType.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<!-- Adding property types is a BC break in most cases. -->
<exclude-pattern>src/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<!-- Adding property types is a BC break in most cases. -->
<exclude-pattern>src/*</exclude-pattern>
</rule>

<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ parameters:

-
message: "#^Method Doctrine\\\\Tests\\\\Common\\\\DataFixtures\\\\Executor\\\\PHPCRExecutorTest\\:\\:getDocumentManager\\(\\) has invalid return type Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManager\\.$#"
count: 1
count: 2
path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php

-
Expand Down
18 changes: 9 additions & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703">
<files psalm-version="5.9.0@8b9ad1eb9e8b7d3101f949291da2b9f7767cd163">
<file src="src/Executor/PHPCRExecutor.php">
<UndefinedClass occurrences="1">
<UndefinedClass>
<code>DocumentManagerInterface</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="2">
<code>DocumentManagerInterface</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>DocumentManagerInterface</code>
</UndefinedDocblockClass>
</file>
<file src="src/Purger/PHPCRPurger.php">
<UndefinedClass occurrences="3">
<UndefinedClass>
<code><![CDATA[$this->dm]]></code>
<code>?DocumentManagerInterface</code>
<code>?DocumentManagerInterface</code>
<code>DocumentManager</code>
<code>NodeHelper</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="3">
<code>$this-&gt;dm</code>
<code>DocumentManagerInterface|null</code>
<UndefinedDocblockClass>
<code>DocumentManagerInterface|null</code>
</UndefinedDocblockClass>
</file>
<file src="src/ReferenceRepository.php">
<UndefinedClass occurrences="2">
<UndefinedClass>
<code>PhpcrDocumentManager</code>
<code>PhpcrDocumentManager</code>
</UndefinedClass>
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
phpVersion="7.4"
phpVersion="8.2"
errorLevel="7"
findUnusedBaselineEntry="true"
findUnusedCode="false"
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getReference($name, ?string $class = null)
'doctrine/data-fixtures',
'https://github.com/doctrine/data-fixtures/pull/409',
'Argument $class of %s() will be mandatory in 2.0.',
__METHOD__
__METHOD__,
);
}

Expand All @@ -121,7 +121,7 @@ public function hasReference($name, ?string $class = null)
'doctrine/data-fixtures',
'https://github.com/doctrine/data-fixtures/pull/409',
'Argument $class of %s() will be mandatory in 2.0.',
__METHOD__
__METHOD__,
);
}

Expand Down
9 changes: 3 additions & 6 deletions src/Event/Listener/MongoDBReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
final class MongoDBReferenceListener implements EventSubscriber
{
/** @var ReferenceRepository */
private $referenceRepository;
private ReferenceRepository $referenceRepository;

public function __construct(ReferenceRepository $referenceRepository)
{
Expand All @@ -27,17 +26,15 @@ public function __construct(ReferenceRepository $referenceRepository)
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return ['postPersist'];
}

/**
* Populates identities for stored references
*
* @return void
*/
public function postPersist(LifecycleEventArgs $args)
public function postPersist(LifecycleEventArgs $args): void
{
$object = $args->getDocument();

Expand Down
9 changes: 3 additions & 6 deletions src/Event/Listener/ORMReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
final class ORMReferenceListener implements EventSubscriber
{
/** @var ReferenceRepository */
private $referenceRepository;
private ReferenceRepository $referenceRepository;

public function __construct(ReferenceRepository $referenceRepository)
{
Expand All @@ -27,18 +26,16 @@ public function __construct(ReferenceRepository $referenceRepository)
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
// would be better to use onClear, but it is supported only in 2.1
return ['postPersist'];
}

/**
* Populates identities for stored references
*
* @return void
*/
public function postPersist(LifecycleEventArgs $args)
public function postPersist(LifecycleEventArgs $args): void
{
$object = $args->getEntity();

Expand Down
4 changes: 2 additions & 2 deletions src/Executor/AbstractExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function purge()
if ($this->purger === null) {
throw new Exception(
PurgerInterface::class .
' instance is required if you want to purge the database before loading your data fixtures.'
' instance is required if you want to purge the database before loading your data fixtures.',
);
}

Expand All @@ -154,5 +154,5 @@ public function purge()
*
* @return void
*/
abstract public function execute(array $fixtures, $append = false);
abstract public function execute(array $fixtures, bool $append = false);
}
9 changes: 3 additions & 6 deletions src/Executor/MongoDBExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
*/
class MongoDBExecutor extends AbstractExecutor
{
/** @var DocumentManager */
private $dm;

/** @var MongoDBReferenceListener */
private $listener;
private DocumentManager $dm;
private MongoDBReferenceListener $listener;

/**
* Construct new fixtures loader instance.
Expand Down Expand Up @@ -54,7 +51,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository)
{
$this->dm->getEventManager()->removeEventListener(
$this->listener->getSubscribedEvents(),
$this->listener
$this->listener,
);

$this->referenceRepository = $referenceRepository;
Expand Down
8 changes: 2 additions & 6 deletions src/Executor/MultipleTransactionORMExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ public function execute(array $fixtures, $append = false): void
{
$executor = $this;
if ($append === false) {
$this->em->wrapInTransaction(static function () use ($executor) {
$executor->purge();
});
$this->em->wrapInTransaction(static fn () => $executor->purge());
}

foreach ($fixtures as $fixture) {
$this->em->wrapInTransaction(static function (EntityManagerInterface $em) use ($executor, $fixture) {
$executor->load($em, $fixture);
});
$this->em->wrapInTransaction(static fn (EntityManagerInterface $em) => $executor->load($em, $fixture));
}
}
}
11 changes: 4 additions & 7 deletions src/Executor/ORMExecutorCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
trait ORMExecutorCommon
{
/** @var EntityManager|EntityManagerDecorator */
private $em;
private EntityManagerInterface $em;

/** @var EntityManagerInterface */
private $originalManager;

/** @var ORMReferenceListener */
private $listener;
private EntityManagerInterface $originalManager;
private ORMReferenceListener $listener;

public function __construct(EntityManagerInterface $em, ?ORMPurgerInterface $purger = null)
{
Expand Down Expand Up @@ -59,7 +56,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository)
{
$this->em->getEventManager()->removeEventListener(
$this->listener->getSubscribedEvents(),
$this->listener
$this->listener,
);

parent::setReferenceRepository($referenceRepository);
Expand Down
3 changes: 1 addition & 2 deletions src/Executor/PHPCRExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/
class PHPCRExecutor extends AbstractExecutor
{
/** @var DocumentManagerInterface */
private $dm;
private DocumentManagerInterface $dm;

/**
* @param DocumentManagerInterface $dm manager instance used for persisting the fixtures
Expand Down
Loading

0 comments on commit 5330482

Please sign in to comment.