R3VoLuT1OneR /
doctrine-rest
| 1 | <?php namespace Pz\Doctrine\Rest\Action\Related; |
||||||
| 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\Resource\Item; |
||||||
| 7 | use Pz\Doctrine\Rest\RestAction; |
||||||
| 8 | use Pz\Doctrine\Rest\RestRepository; |
||||||
| 9 | use Pz\Doctrine\Rest\RestResponse; |
||||||
| 10 | use Pz\Doctrine\Rest\RestResponseFactory; |
||||||
| 11 | use Pz\Doctrine\Rest\Traits\CanHydrate; |
||||||
| 12 | use Pz\Doctrine\Rest\Traits\CanValidate; |
||||||
| 13 | use Pz\Doctrine\Rest\Traits\RelatedAction; |
||||||
| 14 | |||||||
| 15 | class RelatedItemCreateAction extends RestAction |
||||||
| 16 | { |
||||||
| 17 | use RelatedAction; |
||||||
| 18 | use CanHydrate; |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 19 | use CanValidate; |
||||||
| 20 | |||||||
| 21 | /** |
||||||
| 22 | * RelatedCollectionCreateAction constructor. |
||||||
| 23 | * |
||||||
| 24 | * @param RestRepository $repository |
||||||
| 25 | * @param string $field |
||||||
| 26 | * @param RestRepository $related |
||||||
| 27 | * @param \Closure|TransformerAbstract $transformer |
||||||
| 28 | */ |
||||||
| 29 | 1 | public function __construct(RestRepository $repository, $field, RestRepository $related, $transformer) |
|||||
| 30 | { |
||||||
| 31 | 1 | parent::__construct($repository, $transformer); |
|||||
| 32 | 1 | $this->related = $related; |
|||||
| 33 | 1 | $this->field = $field; |
|||||
| 34 | 1 | } |
|||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * @param RestRequestContract $request |
||||||
| 38 | * |
||||||
| 39 | * @return RestResponse |
||||||
| 40 | * @throws RestException |
||||||
| 41 | */ |
||||||
| 42 | 1 | public function handle($request) |
|||||
| 43 | { |
||||||
| 44 | 1 | $entity = $this->repository()->findById($request->getId()); |
|||||
| 45 | 1 | $this->authorize($request, $entity); |
|||||
| 46 | |||||||
| 47 | 1 | $item = $this->hydrateEntity($this->related()->getClassName(), $request->getData()); |
|||||
| 48 | 1 | $this->validateEntity($item); |
|||||
| 49 | 1 | $this->related()->getEntityManager()->persist($item); |
|||||
| 50 | 1 | $this->setProperty($entity, $this->field(), $item); |
|||||
| 51 | |||||||
| 52 | 1 | $this->related()->getEntityManager()->flush($entity); |
|||||
| 53 | |||||||
| 54 | 1 | return RestResponseFactory::resource($request, |
|||||
| 55 | 1 | new Item($item, $this->transformer(), $this->related()->getResourceKey()), |
|||||
|
0 ignored issues
–
show
The call to
Pz\Doctrine\Rest\Resource\Item::__construct() has too many arguments starting with $this->related()->getResourceKey().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. Loading history...
|
|||||||
| 56 | 1 | RestResponse::HTTP_CREATED |
|||||
| 57 | ); |
||||||
| 58 | } |
||||||
| 59 | } |
||||||
| 60 |