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

ToggleContextFactory::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 6
nc 2
nop 3
crap 3.0416
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\Context;
23
use Zend\Config\Config;
24
use Zend\ServiceManager\Factory\FactoryInterface;
25
26
class ToggleContextFactory implements FactoryInterface
27
{
28
    /**
29
     * Create an object
30
     *
31
     * @param  ContainerInterface $container
32
     * @param  string $requestedName
33
     * @param  null|array $options
34
     *
35
     * @return Context
36
     *
37
     * @throws \Psr\Container\ContainerExceptionInterface
38
     */
39 1
    public function __invoke(ContainerInterface $container, $requestedName = '', array $options = null)
40
    {
41 1
        $factory = (new Config($container->get('config')))['zf2_featureflags']['qandidate_toggle']['context_factory'];
42
43 1
        $context = new Context();
44
45 1
        if ($factory !== null && $container->has($factory)) {
46
            /** @var Context $context */
47
            $context = $container->get($factory);
48
        }
49
50 1
        return $context;
51
    }
52
}
53