Passed
Push — master ( 4b954d...b01812 )
by Gabor
03:38
created

Auth   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 9 1
A getIdentity() 0 20 3
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Auth;
13
14
use Exception;
15
use WebHemi\Data\Storage\User\UserStorage;
16
use WebHemi\Data\Entity\User\UserEntity;
17
use WebHemi\Adapter\Auth\AbstractAuthAdapter;
18
19
/**
20
 * Class Auth
21
 *
22
 * @method UserStorage getDataStorage()
23
 *
24
 * @codeCoverageIgnore - unfinished code
25
 */
26
class Auth extends AbstractAuthAdapter
27
{
28
    /**
29
     * Authenticates the user.
30
     *
31
     * @return Result
32
     */
33
    public function authenticate()
34
    {
35
        // TODO implement
36
        $result = $this->getAuthResult();
37
        $user = $this->getDataStorage()->getUserById(1);
38
        $result->setIdentity($user);
0 ignored issues
show
Documentation introduced by
$user is of type object<WebHemi\Data\Enti...aEntityInterface>|false, but the function expects a object<WebHemi\Data\Entity\User\UserEntity>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $result->setCode(Result::SUCCESS);
40
        return $result;
41
    }
42
43
    /**
44
     * Gets the authenticated user's entity.
45
     *
46
     * @throws Exception
47
     * @return null|string|UserEntity
48
     */
49
    public function getIdentity()
50
    {
51
        $identity = parent::getIdentity();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::getIdentity(); of type null|string|WebHemi\Data...ity\DataEntityInterface adds the type string to the return on line 67 which is incompatible with the return type declared by the interface WebHemi\Adapter\Auth\Aut...rInterface::getIdentity of type WebHemi\Data\Entity\DataEntityInterface.
Loading history...
52
        // TODO implement
53
54
        if (!$identity instanceof UserEntity) {
55
            $userName = 'admin';
0 ignored issues
show
Bug Compatibility introduced by
The expression 'admin'; of type string adds the type string to the return on line 67 which is incompatible with the return type declared by the interface WebHemi\Adapter\Auth\Aut...rInterface::getIdentity of type WebHemi\Data\Entity\DataEntityInterface.
Loading history...
56
57
            /** @var UserEntity $userEntity */
58
            $userEntity = $this->getDataStorage()->getUserByUserName($userName);
59
60
            if (!$userEntity) {
61
                $identity = $userName;
62
            } else {
63
                return $userEntity;
64
            }
65
        }
66
67
        return $identity;
68
    }
69
}
70