UsernameAndPasswordToken::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 8.8571
cc 5
eloc 9
nc 3
nop 2
crap 5
1
<?php
2
3
namespace Marek\Toggable\API\Security;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class UsernameAndPasswordToken
9
 * @package Marek\Toggable\API\Security
10
 */
11
class UsernameAndPasswordToken implements TokenInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $username;
17
18
    /**
19
     * @var string
20
     */
21
    private $password;
22
23
    /**
24
     * UsernameAndPasswordToken constructor.
25
     *
26
     * @param string $username
27
     * @param string $password
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31 5
    public function __construct($username, $password)
32
    {
33 5
        if (empty($username) || !is_string($username)) {
34 1
            throw new InvalidArgumentException(
35 1
                sprintf('Please provide username in %s', get_class($this))
36 1
            );
37
        }
38 5
        $this->username = $username;
39
40 5
        if (empty($password) || !is_string($password)) {
41 1
            throw new InvalidArgumentException(
42 1
                sprintf('Please provide password in %s', get_class($this))
43 1
            );
44
        }
45 5
        $this->password = $password;
46 5
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function getAuthentication()
52
    {
53 1
        return array($this->username, $this->password);
54
    }
55
}
56