GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — 1.x (#354)
by
unknown
57:29 queued 22:30
created

FixturesExecutor::getExecutor()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 43
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 7.0031

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 24
cts 25
cp 0.96
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 29
nc 4
nop 3
crap 7.0031
1
<?php
2
3
/*
4
 * This file is part of the Hautelook\AliceBundle package.
5
 *
6
 * (c) Baldur Rensch <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Hautelook\AliceBundle\Doctrine\DataFixtures\Executor;
13
14
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
15
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
16
use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Doctrine\ODM\MongoDB\DocumentManager as MongoDBDocumentManager;
19
use Doctrine\ODM\PHPCR\DocumentManager as PHPCRDocumentManager;
20
use Doctrine\ORM\EntityManagerInterface;
21
use Doctrine\ORM\Mapping\ClassMetadata;
22
use Hautelook\AliceBundle\Alice\DataFixtures\LoaderInterface;
23
24
/**
25
 * @author Théo FIDRY <[email protected]>
26
 */
27
class FixturesExecutor implements FixturesExecutorInterface
28
{
29
    /**
30
     * {@inheritdoc}
31 84
     */
32
    public function execute(
33
        ObjectManager $manager,
34
        LoaderInterface $loader,
35
        array $fixturesFiles,
36
        $append,
37
        $loggerCallable,
38
        $truncate = false
39
    ) {
40 84
        // Get executor
41 84
        $executor = $this->getExecutor($manager, $loader, $truncate);
42
        $executor->setLogger($loggerCallable);
43
44 84
        // Purge database and load fixtures
45 84
        $executor->execute($fixturesFiles, $append);
46
    }
47
48
    /**
49
     * Gets the executor for the matching the given object manager.
50
     *
51
     * @param ObjectManager   $manager
52
     * @param LoaderInterface $loader
53
     * @param bool|null       $purgeMode
54
     *
55
     * @return ExecutorInterface
56 84
     */
57
    private function getExecutor(ObjectManager $manager, LoaderInterface $loader, $purgeMode)
58 84
    {
59 84
        switch (true) {
60 78
            case $manager instanceof EntityManagerInterface:
61 78
                $executor = new ORMExecutor($manager, $loader);
62 78
                $metaData = $manager->getMetadataFactory()->getAllMetadata();
63
64 78
                $excluded = [];
65
                foreach ($metaData as $classMetadata) {
66 78
                    /** @var ClassMetadata $classMetadata */
67 78
                    if ($classMetadata->isReadOnly) {
68
                        $excluded[] = implode('.', [$classMetadata->getSchemaName(), $classMetadata->getTableName()]);
69 12
                    }
70 12
                }
71 12
                $purger = new ORMPurger($manager, $excluded);
0 ignored issues
show
Unused Code introduced by
The call to ORMPurger::__construct() has too many arguments starting with $excluded.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
72 12
                $purger->setPurgeMode(
73
                    $purgeMode
74 6
                        ? ORMPurger::PURGE_MODE_TRUNCATE
75 6
                        : ORMPurger::PURGE_MODE_DELETE
76 6
                );
77 6
                break;
78
79 6
            case $manager instanceof MongoDBDocumentManager:
80 6
                $executor = new MongoDBExecutor($manager, $loader);
81 6
                $purger = new MongoDBPurger($manager);
82 6
                break;
83 6
84 6
            case $manager instanceof PHPCRDocumentManager:
0 ignored issues
show
Bug introduced by
The class Doctrine\ODM\PHPCR\DocumentManager does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
85
                $executor = new PHPCRExecutor($manager, $loader);
86 84
                $purger = new PHPCRPurger($manager);
87
                break;
88 84
89
            default:
90
                throw new \InvalidArgumentException(sprintf(
91
                    'Unsupported manager type %s',
92
                    get_class($manager))
93
                );
94
        }
95
96
        $executor->setPurger($purger);
97
98
        return $executor;
99
    }
100
}
101