Completed
Push — master ( cd391d...67f3cd )
by Pavel
01:53
created

DeleteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 31
loc 31
ccs 7
cts 7
cp 1
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
7 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...
8
{
9
    /**
10
     * Doctrine repository from where get data.
11
     *
12
     * @return RestRepository
13
     */
14
    abstract protected function repository();
15
16
    /**
17
     * @return RestResponseInterface
18
     */
19
    abstract protected function response();
20
21
    /**
22
     * @param DeleteRequestInterface $request
23
     *
24
     * @return array
25
     */
26 2
    public function delete(DeleteRequestInterface $request)
27
    {
28 2
        if (null === ($entity = $this->repository()->find($request->getId()))) {
29 1
            return $this->response()->notFound($request);
30
        }
31
32 1
        $request->authorize($entity);
33
34 1
        $this->repository()->em()->remove($entity);
35 1
        $this->repository()->em()->flush();
36
37 1
        return $this->response()->delete($request, $entity);
38
    }
39
}
40