Base::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Factory Pattern Base Class
6
 * @package     Ticaje_Contract
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\Contract\Factory;
11
12
use Ticaje\Contract\Application\Service\ServiceLocatorInterface;
13
14
/**
15
 * Class Base
16
 * @package Ticaje\Contract\Factory
17
 */
18
abstract class Base implements FactoryInterface
19
{
20
    protected $serviceLocator;
21
22
    protected $instanceName;
23
24
    /**
25
     * Base constructor.
26
     * @param ServiceLocatorInterface $serviceLocator
27
     * @param string $instanceName
28
     */
29
    public function __construct(
30
        ServiceLocatorInterface $serviceLocator,
31
        string $instanceName
32
    ) {
33
        $this->serviceLocator = $serviceLocator;
34
        $this->instanceName = $instanceName;
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function create(array $data = [])
41
    {
42
        return $this->serviceLocator->create($this->instanceName, $data);
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function get($class)
49
    {
50
        return $this->serviceLocator->create($class);
0 ignored issues
show
Bug introduced by
The call to Ticaje\Contract\Applicat...atorInterface::create() has too few arguments starting with arguments. ( Ignorable by Annotation )

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

50
        return $this->serviceLocator->/** @scrutinizer ignore-call */ create($class);

This check compares calls to functions or methods with their respective definitions. If the call has less 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. Please note the @ignore annotation hint above.

Loading history...
51
    }
52
}
53