Completed
Push — develop ( 0d8372...6867cd )
by Siad
09:33
created

ToggleManagerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 2
c 3
b 0
f 2
lcom 0
cbo 4
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 14 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\ToggleCollection;
22
use Qandidate\Toggle\ToggleManager;
23
use Zend\Config\Config;
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
        $toggleConfig = new Config($serviceLocator->get('config'));
42 2
        $persistence = $toggleConfig->zf2_featureflags->qandidate_toggle->get('persistence', 'Qandidate\Toggle\Collection\InMemory');
43
44
        /** @var ToggleCollection $coll */
45 2
        $coll = $serviceLocator->get($persistence);
46
47 2
        if (!$coll instanceof ToggleCollection) {
48 1
            throw new ServiceNotFoundException('Service received is not of type ToggleCollection');
49
        }
50
51 1
        return new ToggleManager($coll);
52
    }
53
}
54