Skip to content

Commit

Permalink
Introduce doctrine/coding-standard and apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Oct 30, 2019
1 parent 4d42030 commit 2be96f2
Show file tree
Hide file tree
Showing 53 changed files with 991 additions and 734 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
phpunit.xml
vendor/
.phpcs-cache
composer.lock
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -28,3 +28,9 @@ jobs:
# Tests the lowest set of dependencies
- php: 7.2
env: LOWEST COMPOSER_FLAGS="--prefer-lowest"

- stage: Code Quality
env: CODING_STANDARDS
php: 7.2
script:
- ./vendor/bin/phpcs
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -22,6 +22,7 @@
},
"require-dev": {
"alcaeus/mongo-php-adapter": "^1.1",
"doctrine/coding-standard": "^6.0",
"doctrine/dbal": "^2.5.4",
"doctrine/mongodb-odm": "^1.3.0",
"doctrine/orm": "^2.5.4",
Expand Down
50 changes: 29 additions & 21 deletions lib/Doctrine/Common/DataFixtures/AbstractFixture.php
@@ -1,86 +1,94 @@
<?php

declare(strict_types=1);

namespace Doctrine\Common\DataFixtures;

use Doctrine\Common\DataFixtures\ReferenceRepository;
use BadMethodCallException;

/**
* Abstract Fixture class helps to manage references
* between fixture classes in order to set relations
* among other fixtures
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*/
abstract class AbstractFixture implements SharedFixtureInterface
{
/**
* Fixture reference repository
*
*
* @var ReferenceRepository
*/
protected $referenceRepository;

/**
* {@inheritdoc}
*/
public function setReferenceRepository(ReferenceRepository $referenceRepository)
{
$this->referenceRepository = $referenceRepository;
}

/**
* Set the reference entry identified by $name
* and referenced to managed $object. If $name
* already is set, it overrides it
*
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference
*
* @param string $name
* @param object $object - managed object
* @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference
*
* @return void
*/
public function setReference($name, $object)
{
$this->referenceRepository->setReference($name, $object);
}

/**
* Set the reference entry identified by $name
* and referenced to managed $object. If $name
* already is set, it throws a
* already is set, it throws a
* BadMethodCallException exception
*
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference
*
* @param string $name
* @param object $object - managed object
* @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference
* @throws \BadMethodCallException - if repository already has
* a reference by $name
*
* @return void
*
* @throws BadMethodCallException - if repository already has a reference by $name.
*/
public function addReference($name, $object)
{
$this->referenceRepository->addReference($name, $object);
}

/**
* Loads an object using stored reference
* named by $name
*
* @param string $name
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference
*
* @param string $name
*
* @return object
*/
public function getReference($name)
{
return $this->referenceRepository->getReference($name);
}

/**
* Check if an object is stored using reference
* named by $name
*
* @param string $name
*
* @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference
* @return boolean
*
* @param string $name
*
* @return bool
*/
public function hasReference($name)
{
Expand Down
56 changes: 19 additions & 37 deletions lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php
@@ -1,37 +1,19 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\Common\DataFixtures;

/**
* DependentFixtureInterface needs to be implemented
* by fixtures which depend on other fixtures
*
* @author Gustavo Adrian <comfortablynumb@gmail.com>
*/
interface DependentFixtureInterface
{
/**
* This method must return an array of fixtures classes
* on which the implementing class depends on
*
* @return array
*/
public function getDependencies();
}
<?php

declare(strict_types=1);

namespace Doctrine\Common\DataFixtures;

/**
* DependentFixtureInterface needs to be implemented by fixtures which depend on other fixtures
*/
interface DependentFixtureInterface
{
/**
* This method must return an array of fixtures classes
* on which the implementing class depends on
*
* @return array
*/
public function getDependencies();
}
@@ -1,29 +1,24 @@
<?php

declare(strict_types=1);

namespace Doctrine\Common\DataFixtures\Event\Listener;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\DataFixtures\ReferenceRepository;
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;

/**
* Reference Listener populates identities for
* stored references
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*/
final class MongoDBReferenceListener implements EventSubscriber
{
/**
* @var ReferenceRepository
*/
/** @var ReferenceRepository */
private $referenceRepository;

/**
* Initialize listener
*
* @param ReferenceRepository $referenceRepository
*/
public function __construct(ReferenceRepository $referenceRepository)
{
Expand All @@ -35,28 +30,27 @@ public function __construct(ReferenceRepository $referenceRepository)
*/
public function getSubscribedEvents()
{
return [
'postPersist'
];
return ['postPersist'];
}

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

if (($names = $this->referenceRepository->getReferenceNames($object)) !== false) {
foreach ($names as $name) {
$identity = $args->getDocumentManager()
->getUnitOfWork()
->getDocumentIdentifier($object);
$names = $this->referenceRepository->getReferenceNames($object);
if ($names === false) {
return;
}

foreach ($names as $name) {
$identity = $args->getDocumentManager()
->getUnitOfWork()
->getDocumentIdentifier($object);

$this->referenceRepository->setReferenceIdentity($name, $identity);
}
$this->referenceRepository->setReferenceIdentity($name, $identity);
}
}
}
@@ -1,29 +1,24 @@
<?php

declare(strict_types=1);

namespace Doctrine\Common\DataFixtures\Event\Listener;

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\DataFixtures\ReferenceRepository;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;

/**
* Reference Listener populates identities for
* stored references
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*/
final class ORMReferenceListener implements EventSubscriber
{
/**
* @var ReferenceRepository
*/
/** @var ReferenceRepository */
private $referenceRepository;

/**
* Initialize listener
*
* @param ReferenceRepository $referenceRepository
*/
public function __construct(ReferenceRepository $referenceRepository)
{
Expand All @@ -35,28 +30,28 @@ public function __construct(ReferenceRepository $referenceRepository)
*/
public function getSubscribedEvents()
{
return [
'postPersist' // would be better to use onClear, but it is supported only in 2.1
];
// would be better to use onClear, but it is supported only in 2.1
return ['postPersist'];
}

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

if (($names = $this->referenceRepository->getReferenceNames($object)) !== false) {
foreach ($names as $name) {
$identity = $args->getEntityManager()
->getUnitOfWork()
->getEntityIdentifier($object);
$names = $this->referenceRepository->getReferenceNames($object);
if ($names === false) {
return;
}

foreach ($names as $name) {
$identity = $args->getEntityManager()
->getUnitOfWork()
->getEntityIdentifier($object);

$this->referenceRepository->setReferenceIdentity($name, $identity);
}
$this->referenceRepository->setReferenceIdentity($name, $identity);
}
}
}
@@ -1,9 +1,11 @@
<?php

namespace Doctrine\Common\DataFixtures\Exception;

use Doctrine\Common\CommonException;

class CircularReferenceException extends CommonException
{
}
<?php

declare(strict_types=1);

namespace Doctrine\Common\DataFixtures\Exception;

use Doctrine\Common\CommonException;

class CircularReferenceException extends CommonException
{
}

0 comments on commit 2be96f2

Please sign in to comment.