| 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
|
|||
| 51 | } |
||
| 52 | } |
||
| 53 |
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.