ToggleManagerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 38
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
A createService() 0 4 1
1
<?php
2
/**
3
 * zf2-featureflags.
4
 *
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
11
 * SOFTWARE.
12
 *
13
 * @copyright 2016 MehrAlsNix (http://www.mehralsnix.de)
14
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
15
 *
16
 * @link      http://github.com/MehrAlsNix/zf2-featureflags
17
 */
18
19
namespace MehrAlsNix\FeatureToggle\Factory;
20
21
use Interop\Container\ContainerInterface;
22
use Qandidate\Toggle\ToggleCollection;
23
use Qandidate\Toggle\ToggleManager;
24
use Zend\ServiceManager\Exception\ServiceNotFoundException;
25
use Zend\ServiceManager\FactoryInterface;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
class ToggleManagerFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
29
{
30
    /**
31
     * Create service
32
     *
33
     * @param ServiceLocatorInterface $serviceLocator
0 ignored issues
show
Bug introduced by
There is no parameter named $serviceLocator. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     *
35
     * @return ToggleManager
36
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
37
     */
38 2
    public function __invoke(ContainerInterface $container, $requestedName = '', array $options = null)
39
    {
40 2
        $coll = $container->get(
41 2
            'ToggleFeature\InMemoryCollSerializer'
42 2
        )->deserialize(
43 2
            $container->get('config')['zf2_featureflags']['features']
44
        );
45
46 2
        if (!$coll instanceof ToggleCollection) {
47 1
            throw new ServiceNotFoundException(
48 1
                'Service received is not of type ToggleCollection'
49
            );
50
        }
51
52 1
        return new ToggleManager($coll);
53
    }
54
55
    /**
56
     * Create service
57
     *
58
     * @param ServiceLocatorInterface $serviceLocator
59
     * @return mixed
60
     */
61
    public function createService(ServiceLocatorInterface $serviceLocator)
62
    {
63
        return $this($serviceLocator);
64
    }
65
}
66