Passed
Push — master ( 8d03dd...568a3e )
by Divine Niiquaye
89:14
created

RepositoryValueResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Biurad\Cycle;
19
20
use Cycle\ORM\ORMInterface;
21
use Cycle\ORM\Schema;
22
use Cycle\ORM\Select;
23
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;
0 ignored issues
show
Bug introduced by
The type DivineNii\Invoker\Interf...tValueResolverInterface 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...
24
use ReflectionClass;
25
use ReflectionParameter;
26
27
/**
28
 * Find a role then Injects it into a repository class object,
29
 * returning the repository class object.
30
 *
31
 * @author Divine Niiquaye Ibok <[email protected]>
32
 */
33
class RepositoryValueResolver implements ArgumentValueResolverInterface
34
{
35
    /** @var ORMInterface */
36
    private $orm;
37
38
    public function __construct(ORMInterface $orm)
39
    {
40
        $this->orm = $orm;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function resolve(ReflectionParameter $parameter, array $providedParameters)
47
    {
48
        $parameterClass = $parameter->getClass();
49
50
        if (!$parameterClass instanceof ReflectionClass) {
0 ignored issues
show
introduced by
$parameterClass is always a sub-type of ReflectionClass.
Loading history...
51
            return;
52
        }
53
54
        $schema = $this->orm->getSchema();
55
56
        foreach ($schema->getRoles() as $role) {
57
            $repository = $schema->define($role, Schema::REPOSITORY);
58
59
            if (
60
                $repository !== Select\Repository::class
61
                && $repository === $parameterClass->getName()
62
            ) {
63
                return $this->orm->getRepository($role);
64
            }
65
        }
66
    }
67
}
68