RelationshipsItemUpdateAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 20 1
1
<?php namespace Pz\Doctrine\Rest\Action\Relationships;
2
3
use League\Fractal\TransformerAbstract;
4
use Pz\Doctrine\Rest\Resource\Item;
5
use Pz\Doctrine\Rest\RestAction;
6
use Pz\Doctrine\Rest\RestRepository;
7
use Pz\Doctrine\Rest\Traits\RelatedAction;
8
9
class RelationshipsItemUpdateAction extends RestAction
10
{
11
     use RelatedAction;
12
13
    /**
14
     * RelatedRestAction constructor.
15
     *
16
     * @param RestRepository      $repository
17
     * @param string              $field
18
     * @param RestRepository      $related
19
     * @param TransformerAbstract $transformer
20
     */
21 2
    public function __construct(RestRepository $repository, $field, RestRepository $related, $transformer)
22
    {
23 2
        parent::__construct($repository, $transformer);
24 2
        $this->related = $related;
25 2
        $this->field = $field;
26 2
    }
27
28 2
    public function handle($request)
29
    {
30 2
        $entity = $this->repository()->findById($request->getId());
31
32 2
        $this->authorize($request, $entity);
33
34 2
        $item = $this->getRelatedEntity($request->getData());
35
36 1
        $this->setProperty($entity, $this->field(), $item);
37
38 1
        $this->repository()->getEntityManager()->flush($entity);
39
40
        return (
41 1
            new RelationshipsItemAction(
42 1
                $this->repository(),
43 1
                $this->field(),
44 1
                $this->related(),
45 1
                $this->transformer()
0 ignored issues
show
Bug introduced by
It seems like $this->transformer() can also be of type Closure; however, parameter $transformer of Pz\Doctrine\Rest\Action\...emAction::__construct() does only seem to accept League\Fractal\TransformerAbstract, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
                /** @scrutinizer ignore-type */ $this->transformer()
Loading history...
46
            )
47 1
        )->dispatch($request);
48
    }
49
}
50