Completed
Push — master ( 7a82a2...eef030 )
by Pavel
02:12
created

CreateAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 34.38 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 11
loc 32
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createEntity() 0 6 1
A handle() 10 10 1

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\Action\CanHydrate;
4
use Pz\Doctrine\Rest\Action\RestActionAbstract;
5
use Pz\Doctrine\Rest\RestRequestAbstract;
6
use Pz\Doctrine\Rest\RestResponse;
7
8
class CreateAction extends RestActionAbstract
9
{
10
    use CanHydrate;
11
12
    /**
13
     * @param RestRequestAbstract $request
14
     *
15
     * @return RestResponse
16
     */
17 View Code Duplication
    public function handle(RestRequestAbstract $request)
0 ignored issues
show
Duplication introduced by
This method 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...
18
    {
19
        $request->authorize($this->repository()->getClassName());
20
21
        $entity = $this->createEntity($request);
22
23
        $this->repository()->em()->persist($entity);
24
        $this->repository()->em()->flush();
25
26
        return $this->response()->create($request, $entity);
27
    }
28
29
    /**
30
     * @param RestRequestAbstract $request
31
     *
32
     * @return object
33
     */
34
    protected function createEntity(RestRequestAbstract $request)
35
    {
36
        return $this->hydrate(
37
            $this->repository()->getClassName(),
38
            $this->repository()->em(),
39
            $request
40
        );
41
    }
42
}
43