Completed
Push — develop ( dbe1ef...a58ad8 )
by Siad
02:57
created

ToggleManagerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 77.78%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 2
c 5
b 1
f 2
lcom 0
cbo 4
dl 0
loc 27
ccs 7
cts 9
cp 0.7778
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 15 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 1
    public function createService(ServiceLocatorInterface $serviceLocator)
40
    {
41 1
        $coll = (new InMemoryCollectionSerializer())
42 1
            ->deserialize(
43 1
                $serviceLocator->get('config')['zf2_featureflags']['features']
44 1
            );
45
46 1
        if (!$coll instanceof ToggleCollection) {
47
            throw new ServiceNotFoundException(
48
                'Service received is not of type ToggleCollection'
49
            );
50
        }
51
52 1
        return new ToggleManager($coll);
53
    }
54
}
55