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

UserContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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\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