Completed
Pull Request — master (#9)
by Iakov
03:57
created

FetchEntityByIdStep   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A execute() 0 11 2
A requiresBefore() 0 3 1
1
<?php
2
3
4
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Common;
5
6
use Doctrine\Bundle\DoctrineBundle\Registry;
7
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractStep;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10
11
class FetchEntityByIdStep extends AbstractStep
12
{
13
    /**
14
     * @var Registry
15
     */
16
    protected $doctrine;
17
18
    public function __construct(Registry $doctrine)
19
    {
20
        $this->doctrine = $doctrine;
21
    }
22
23
    public function execute()
24
    {
25
        /** @var \ReflectionClass $reflection */
26
        $reflection = $this->getFromResponse('reflection');
27
        $entity = $this->doctrine->getRepository($reflection->getName())->find($this->request->get('id'), 0);
0 ignored issues
show
Unused Code introduced by
The call to Doctrine\Common\Persiste...bjectRepository::find() has too many arguments starting with 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $entity = $this->doctrine->getRepository($reflection->getName())->/** @scrutinizer ignore-call */ find($this->request->get('id'), 0);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
29
        if (!$entity) {
30
            throw new NotFoundHttpException('Resource not found');
31
        }
32
33
        return $this->createResponse(['entity' => $entity]);
34
    }
35
36
    public function requiresBefore()
37
    {
38
        return [GetReflectionFromRequestStep::class];
39
    }
40
41
}