Completed
Push — develop ( 3ebc1f...23dc53 )
by Siad
07:55
created

ToggleManagerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 3
crap 2
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\Factory\FactoryInterface;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
class ToggleManagerFactory implements FactoryInterface
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