Completed
Push — master ( 704578...e88511 )
by Alex
32:19
created

UserRepository::getUserEntityByUserCredentials()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 3
eloc 11
nc 2
nop 4
1
<?php
2
/**
3
 * @author      Alex Bilbie <[email protected]>
4
 * @copyright   Copyright (c) Alex Bilbie
5
 * @license     http://mit-license.org/
6
 *
7
 * @link        https://github.com/thephpleague/oauth2-server
8
 */
9
10
namespace OAuth2ServerExamples\Repositories;
11
12
use League\OAuth2\Server\Entities\ClientEntityInterface;
13
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
14
use OAuth2ServerExamples\Entities\ScopeEntity;
15
use OAuth2ServerExamples\Entities\UserEntity;
16
17
class UserRepository implements UserRepositoryInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getUserEntityByUserCredentials(
23
        $username,
24
        $password,
25
        $grantType,
26
        ClientEntityInterface $clientEntity
27
    ) {
28
        if ($username === 'alex' && $password === 'whisky') {
29
            $scope = new ScopeEntity();
30
            $scope->setIdentifier('email');
31
            $scopes[] = $scope;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$scopes was never initialized. Although not strictly required by PHP, it is generally a good practice to add $scopes = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
32
33
            return new UserEntity();
34
        }
35
36
        return;
37
    }
38
}
39