Test Failed
Push — master ( 5f574e...cd391d )
by Pavel
01:40
created

UpdateAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 41
loc 41
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Pz\Doctrine\Rest\Action;
2
3
use Pz\Doctrine\Rest\Request\UpdateRequestInterface;
4
use Pz\Doctrine\Rest\RestRepository;
5
use Pz\Doctrine\Rest\RestResponseInterface;
6
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...n\NotFoundHttpException 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...
7
8 View Code Duplication
trait UpdateAction
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * Doctrine repository from where get data.
12
     *
13
     * @return RestRepository
14
     */
15
    abstract protected function repository();
16
17
    /**
18
     * @return RestResponseInterface
19
     */
20
    abstract protected function response();
21
22
    /**
23
     * @param UpdateRequestInterface $request
24
     * @param                        $entity
25
     *
26
     * @return object
27
     */
28
    abstract protected function updateEntity($request, $entity);
29
30
    /**
31
     * @param UpdateRequestInterface $request
32
     *
33
     * @return array
34
     * @throws \Doctrine\ORM\EntityNotFoundException
35
     */
36
    public function update(UpdateRequestInterface $request)
37
    {
38
        if (null === ($entity = $this->repository()->find($request->getId()))) {
39
            throw new NotFoundHttpException();
40
        }
41
42
        $request->authorize($entity);
43
44
        $this->updateEntity($request, $entity);
45
46
        $this->repository()->em()->flush();
47
48
        return $this->response()->update($request, $entity);
49
    }
50
}
51