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

EnvContextFactory::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 6
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 MehrAlsNix\FeatureToggle\Context\EnvContext;
22
use Qandidate\Toggle\Context;
23
use Zend\Http\PhpEnvironment\Request;
24
use Zend\ServiceManager\Exception\ServiceNotFoundException;
25
use Zend\ServiceManager\FactoryInterface;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
class EnvContextFactory implements FactoryInterface
0 ignored issues
show
Bug introduced by
There is one abstract method __invoke in this class; you could implement it, or declare this class as abstract.
Loading history...
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...
29
{
30
    private $name = '';
31
32
    public function __construct($name = '')
33
    {
34
        $this->name = $name;
35
    }
36
37
    /**
38
     * Create service
39
     *
40
     * @param ServiceLocatorInterface $serviceLocator
41
     *
42
     * @return Context
43
     *
44
     * @throws ServiceNotFoundException
45
     */
46
    public function createService(ServiceLocatorInterface $serviceLocator)
47
    {
48
        $name = $this->name;
49
50
        if ($name === '') {
51
            $name = $serviceLocator->get('Config')['zf2_featureflags']['envContext'];
52
        }
53
54
        /** @var Request $request */
55
        $request = $serviceLocator->get('Request');
56
57
        $envContext = new EnvContext($name, $request);
58
59
        return $envContext->createContext();
60
    }
61
}
62