Completed
Push — master ( da7714...2001b3 )
by Pavel
02:43
created

RelationshipsItemDeleteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 1
A __construct() 0 5 1
1
<?php namespace Pz\Doctrine\Rest\Action\Relationships;
2
3
use League\Fractal\TransformerAbstract;
4
use Pz\Doctrine\Rest\Contracts\RestRequestContract;
5
use Pz\Doctrine\Rest\Exceptions\RestException;
6
use Pz\Doctrine\Rest\RestAction;
7
use Pz\Doctrine\Rest\RestRepository;
8
use Pz\Doctrine\Rest\RestResponse;
9
use Pz\Doctrine\Rest\Traits\RelatedAction;
10
11
class RelationshipsItemDeleteAction extends RestAction
12
{
13
    use RelatedAction;
14
15
    /**
16
     * RelatedRestAction constructor.
17
     *
18
     * @param RestRepository      $repository
19
     * @param string              $field
20
     * @param RestRepository      $related
21
     * @param TransformerAbstract $transformer
22
     */
23 1
    public function __construct(RestRepository $repository, $field, RestRepository $related, $transformer)
24
    {
25 1
        parent::__construct($repository, $transformer);
26 1
        $this->related = $related;
27 1
        $this->field = $field;
28 1
    }
29
30
    /**
31
     * @param RestRequestContract $request
32
     *
33
     * @return RestResponse
34
     * @throws RestException
35
     */
36 1
    public function handle($request)
37
    {
38 1
        $entity = $this->repository()->findById($request->getId());
39
40 1
        $this->authorize($request, $entity);
41
42 1
        $this->setProperty($entity, $this->field(), null);
43
44 1
        $this->repository()->getEntityManager()->flush($entity);
45
46 1
        return $this->response()->noContent();
47
    }
48
}
49