ServiceLocatorAwareLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addFixture() 0 7 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
namespace DoctrineFixturesModule\Loader;
20
21
use Doctrine\Common\DataFixtures\Loader as BaseLoader;
22
use Zend\ServiceManager\ServiceLocatorAwareInterface;
23
use Zend\ServiceManager\ServiceLocatorInterface;
24
use Doctrine\Common\DataFixtures\FixtureInterface;
25
26
/**
27
 * Doctrine fixture loader which is ZF2 Service Locator-aware
28
 * Will inject the service locator instance into all SL-aware fixtures on add
29
 *
30
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
31
 * @link    www.doctrine-project.org
32
 * @author  Adam Lundrigan <[email protected]>
33
 */
34
class ServiceLocatorAwareLoader extends BaseLoader
35
{
36
    /**
37
     * @var ServiceLocatorInterface
38
     */
39
    protected $serviceLocator;
40
41
    public function __construct(ServiceLocatorInterface $serviceLocator)
42
    {
43
        $this->serviceLocator = $serviceLocator;
44
    }
45
46
    /**
47
     * Add a fixture object instance to the loader.
48
     *
49
     * @param FixtureInterface $fixture
50
     */
51
    public function addFixture(FixtureInterface $fixture)
52
    {
53
        if ($fixture instanceof ServiceLocatorAwareInterface) {
0 ignored issues
show
Bug introduced by
The class Zend\ServiceManager\ServiceLocatorAwareInterface 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...
54
            $fixture->setServiceLocator($this->serviceLocator);
55
        }
56
        parent::addFixture($fixture);
57
    }
58
}
59