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

DeleteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A delete() 12 12 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\DeleteRequestInterface;
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 DeleteAction
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 DeleteRequestInterface $request
24
     *
25
     * @return array
26
     */
27
    public function delete(DeleteRequestInterface $request)
28
    {
29
        if (null === ($entity = $this->repository()->find($request->getId()))) {
30
            throw new NotFoundHttpException();
31
        }
32
33
        $request->authorize($entity);
34
35
        $this->repository()->em()->remove($entity);
36
        $this->repository()->em()->flush();
37
38
        return $this->response()->delete($request, $entity);
39
    }
40
}
41