Completed
Push — develop ( 93a8b4...80313a )
by Siad
02:18
created

UserContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 23
ccs 8
cts 10
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createContext() 0 9 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\Context;
20
21
use Qandidate\Toggle\Context;
22
use Qandidate\Toggle\ContextFactory;
23
use Zend\Authentication\AuthenticationServiceInterface;
24
25
/**
26
 * {@inheritDoc}
27
 */
28
class UserContext extends ContextFactory
29
{
30
    /** @var AuthenticationServiceInterface $tokenStorage */
31
    private $tokenStorage;
32
33 1
    public function __construct(AuthenticationServiceInterface $storage)
34
    {
35 1
        $this->tokenStorage = $storage;
36 1
    }
37
38
    /**
39
     * @return Context
40
     */
41 1
    public function createContext()
42
    {
43 1
        $context = new Context();
44 1
        $token = $this->tokenStorage->getIdentity();
45 1
        if (null !== $token) {
46
            $context->set('username', $this->tokenStorage->getIdentity());
47
        }
48 1
        return $context;
49
    }
50
}
51