FixtureFactory::canCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
3
namespace DoctrineDataFixtureModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use Zend\ServiceManager\Factory\FactoryInterface;
7
8
/**
9
 * Factory for Fixtures
10
 *
11
 * @license MIT
12
 * @link    www.doctrine-project.org
13
 * @author  Martin Shwalbe <[email protected]>
14
 * @author  Rob van der Lee <[email protected]>
15
 */
16
class FixtureFactory implements FactoryInterface
17
{
18
    /**
19
     * @param ContainerInterface $container
20
     * @param string $requestedName
21
     * @return bool
22
     */
23
    public function canCreate(ContainerInterface $container, $requestedName)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function canCreate(/** @scrutinizer ignore-unused */ ContainerInterface $container, $requestedName)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        return class_exists($requestedName);
26
    }
27
28
    /**
29
     * @param ContainerInterface $container
30
     * @param string $requestedName
31
     * @param array|null $options
32
     * @return array|object
33
     * @throws \Psr\Container\ContainerExceptionInterface
34
     * @throws \Psr\Container\NotFoundExceptionInterface
35
     */
36
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38
        return $this->getOptions($container, 'fixtures');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getOptions($container, 'fixtures') returns the type array which is incompatible with the return type mandated by Zend\ServiceManager\Fact...ryInterface::__invoke() of object.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
39
    }
40
41
    /**
42
     * @param ContainerInterface $container
43
     * @param $key
44
     * @return array
45
     * @throws \Psr\Container\ContainerExceptionInterface
46
     * @throws \Psr\Container\NotFoundExceptionInterface
47
     */
48
    public function getOptions(ContainerInterface $container, $key)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function getOptions(ContainerInterface $container, /** @scrutinizer ignore-unused */ $key)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $options = $container->get('config');
51
        if (!isset($options['doctrine']['fixture'])) {
52
            return array();
53
        }
54
        
55
        return $options['doctrine']['fixture'];
56
    }
57
}
58