FactoryFoo   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 4 1
1
<?php
2
3
namespace Example;
4
5
use SlidesWorker\ServiceLocator\ServiceLocator;
6
use SlidesWorker\ServiceLocator\FactoryInterface;
7
use SlidesWorker\ServiceLocator\ServiceLocatorInterface;
8
9
class FactoryFoo implements FactoryInterface
10
{
11
    public function createService(ServiceLocatorInterface $locator, $cName, $rName)
12
    {
13
        return new Service();
14
    }
15
}
16
17
class Service {}
18
19
function FactoryFunction (ServiceLocatorInterface $locator, $cName, $rName)
0 ignored issues
show
Unused Code introduced by
The parameter $locator is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $cName is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $rName is not used and could be removed.

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

Loading history...
20
{
21
    return new Service();
22
}
23
24
25
// setup ServiceLocator
26
$serviceLocator = new ServiceLocator();
27
28
29
// factory as closure
30
$serviceLocator->setFactory('service1', function (ServiceLocatorInterface $locator) {
0 ignored issues
show
Unused Code introduced by
The parameter $locator is not used and could be removed.

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

Loading history...
31
    return Service();
32
});
33
34
// factory as closure
35
$serviceLocator->setFactory('service2', 'FactoryFunction');
36
37
// factory as class
38
$serviceLocator->setFactory('service3', '\Example\FactoryFoo');
39
40
// factory as instance
41
$serviceLocator->setFactory('service4', new FactoryFoo());
42
43
44
45
46
// get a service
47
$service1 = $serviceLocator->get('service1');
48
$service2 = $serviceLocator->get('service2');
49
$service3 = $serviceLocator->get('service3');
50
$service4 = $serviceLocator->get('service4');
51