EnvContextFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 15 2
A createService() 0 4 1
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 MehrAlsNix\FeatureToggle\Context\EnvContext;
23
use Qandidate\Toggle\Context;
24
use Zend\Http\PhpEnvironment\Request;
25
use Zend\ServiceManager\Exception\ServiceNotFoundException;
26
use Zend\ServiceManager\FactoryInterface;
27
use Zend\ServiceManager\ServiceLocatorInterface;
28
29
class EnvContextFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
30
{
31
    private $name = '';
32
33
    public function __construct($name = '')
34
    {
35
        $this->name = $name;
36
    }
37
38
    public function __invoke(ContainerInterface $container, $requestedName = '', array $options = null)
39
    {
40
        $name = $this->name;
41
42
        if ($name === '') {
43
            $name = $container->get('Config')['zf2_featureflags']['envContext'];
44
        }
45
46
        /** @var Request $request */
47
        $request = $container->get('Request');
48
49
        $envContext = new EnvContext($name, $request);
50
51
        return $envContext->createContext();
52
    }
53
54
    /**
55
     * Create service
56
     *
57
     * @param ServiceLocatorInterface $serviceLocator
58
     *
59
     * @return Context
60
     *
61
     * @throws ServiceNotFoundException
62
     */
63
    public function createService(ServiceLocatorInterface $serviceLocator)
64
    {
65
        return $this($serviceLocator);
66
    }
67
}
68