Completed
Push — develop ( a58ad8...588314 )
by Siad
02:50
created

ToggleManagerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 2
c 6
b 2
f 2
lcom 0
cbo 3
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 16 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 Qandidate\Toggle\Serializer\InMemoryCollectionSerializer;
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
29
{
30
    /**
31
     * Create service
32
     *
33
     * @param ServiceLocatorInterface $serviceLocator
34
     *
35
     * @return ToggleManager
36
     *
37
     * @throws ServiceNotFoundException
38
     */
39 2
    public function createService(ServiceLocatorInterface $serviceLocator)
40
    {
41 2
        $coll = $serviceLocator->get(
42
            'ToggleFeature\InMemoryCollSerializer'
43 2
        )->deserialize(
44 2
            $serviceLocator->get('config')['zf2_featureflags']['features']
45 2
        );
46
47 2
        if (!$coll instanceof ToggleCollection) {
48 1
            throw new ServiceNotFoundException(
49
                'Service received is not of type ToggleCollection'
50 1
            );
51
        }
52
53 1
        return new ToggleManager($coll);
54
    }
55
}
56