Completed
Push — develop ( 6d9c00...86e352 )
by Siad
02:09
created

ToggleContextFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 3
c 5
b 1
f 3
lcom 0
cbo 3
dl 0
loc 27
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 15 3
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\Context;
22
use Zend\Config\Config;
23
use Zend\ServiceManager\Exception\ServiceNotFoundException;
24
use Zend\ServiceManager\FactoryInterface;
25
use Zend\ServiceManager\ServiceLocatorInterface;
26
27
class ToggleContextFactory implements FactoryInterface
28
{
29
    /**
30
     * Create service
31
     *
32
     * @param ServiceLocatorInterface $serviceLocator
33
     *
34
     * @return Context
35
     *
36
     * @throws ServiceNotFoundException
37
     */
38 1
    public function createService(ServiceLocatorInterface $serviceLocator)
39
    {
40 1
        $toggleConfig = new Config($serviceLocator->get('config'));
41
42 1
        $factory = $toggleConfig->zf2_featureflags->qandidate_toggle->get('context_factory', null);
43
44 1
        $context = new Context();
45
46 1
        if ($factory !== null && $serviceLocator->has($factory)) {
47
            /** @var Context $context */
48
            $context = $serviceLocator->get($factory);
49
        }
50
51 1
        return $context;
52
    }
53
}
54