Failed Conditions
Push — issue#767 ( 20b3b1 )
by Guilherme
10:48
created

ScopeManager::__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 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Manager;
12
13
use Doctrine\ORM\EntityManager;
14
use LoginCidadao\OpenIDBundle\Entity\Scope;
0 ignored issues
show
Bug introduced by
The type LoginCidadao\OpenIDBundle\Entity\Scope was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use OAuth2\ServerBundle\Manager\ScopeManagerInterface;
16
use OAuth2\ServerBundle\Manager\ScopeManager as BaseManager;
17
18
class ScopeManager extends BaseManager implements ScopeManagerInterface
19
{
20
    private $em;
21
22
    /** @var \OAuth2\ServerBundle\Entity\Scope[] */
23
    private $scopes = array();
24
25 4
    public function __construct(EntityManager $entityManager)
26
    {
27 4
        parent::__construct($entityManager);
28 4
        $this->em = $entityManager;
29 4
    }
30
31 4
    public function setScopes($scopes)
32
    {
33 4
        if (!is_array($scopes)) {
34 4
            $scopes = explode(' ', $scopes);
35
        }
36
37 4
        $this->scopes = array();
38 4
        foreach ($scopes as $scope) {
39 4
            $scopeObj = new \OAuth2\ServerBundle\Entity\Scope();
40 4
            $scopeObj->setScope($scope);
41 4
            $scopeObj->setDescription($scope);
42
43 4
            $this->scopes[$scope] = $scopeObj;
44
        }
45 4
    }
46
47
    /**
48
     * Find a single scope by the scope
49
     *
50
     * @param $scope
51
     * @return Scope
52
     */
53 3
    public function findScopeByScope($scope)
54
    {
55 3
        return $this->scopes[$scope];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->scopes[$scope] returns the type OAuth2\ServerBundle\Entity\Scope which is incompatible with the documented return type LoginCidadao\OpenIDBundle\Entity\Scope.
Loading history...
56
    }
57
58
    /**
59
     * Find all the scopes by an array of scopes
60
     *
61
     * @param array $scopes
62
     * @return mixed|void
63
     */
64 1
    public function findScopesByScopes(array $scopes)
65
    {
66 1
        $result = array();
67 1
        foreach ($this->scopes as $scope => $obj) {
68 1
            if (array_search($scope, $scopes) !== false) {
69 1
                $result[$scope] = $obj;
70
            }
71
        }
72 1
        return $result;
73
    }
74
}
75