1 | <?php |
||
2 | |||
3 | /** |
||
4 | * ServiceFactory.php |
||
5 | * |
||
6 | * @author Dominik Kocuj |
||
7 | * @license https://opensource.org/licenses/MIT The MIT License |
||
8 | * @copyright Copyright (c) 2017 kocuj.pl |
||
9 | * @package kocuj_di |
||
10 | */ |
||
11 | namespace Kocuj\Di\Service; |
||
12 | |||
13 | use Kocuj\Di\ArgumentParser\ArgumentParser; |
||
14 | use Kocuj\Di\Container\ContainerInterface; |
||
15 | use Kocuj\Di\Service\Shared\Shared; |
||
16 | use Kocuj\Di\Service\Standard\Standard; |
||
17 | |||
18 | /** |
||
19 | * Service factory |
||
20 | */ |
||
21 | class ServiceFactory implements ServiceFactoryInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Create standard or shared service |
||
26 | * |
||
27 | * @param ContainerInterface $container |
||
28 | * Dependency injection container for services |
||
29 | * @param ServiceType $serviceType |
||
30 | * Service type |
||
31 | * @param string $id |
||
32 | * Service identifier |
||
33 | * @param string $source |
||
34 | * Source for service to create |
||
35 | * @param array $arguments |
||
36 | * Service arguments to parse |
||
37 | * @return ServiceInterface Service creator object |
||
38 | * @see \Kocuj\Di\Service\ServiceFactoryInterface::create() @codeCoverageIgnore |
||
39 | */ |
||
40 | public function create(ContainerInterface $container, ServiceType $serviceType, string $id, string $source, array $arguments = []): ServiceInterface |
||
41 | { |
||
42 | // exit |
||
43 | switch ($serviceType->getValue()) { |
||
44 | case ServiceType::STANDARD: |
||
45 | return new Standard(new ArgumentParser(), $container, $id, $source, $arguments); |
||
46 | break; |
||
0 ignored issues
–
show
|
|||
47 | case ServiceType::SHARED: |
||
48 | return new Shared(new ArgumentParser(), $container, $id, $source, $arguments); |
||
49 | break; |
||
50 | default: |
||
51 | throw new \Exception('This exception will not be executed!'); |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.