Passed
Branch request-processor (31ada2)
by Iakov
02:59
created

PersistStep::requiresBefore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Common;
5
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\ORMException;
8
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractStep;
9
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
10
11
class PersistStep extends AbstractStep
12
{
13
    /**
14
     * @var EntityManager
15
     */
16
    protected $manager;
17
18
    public function execute()
19
    {
20
        $entity = $this->getFromResponse('entity');
21
22
        try {
23
            $this->manager->persist($entity);
24
            $this->manager->flush();
25
        } catch (ORMException $exception) {
26
            throw new BadRequestHttpException('Your request can not be stored', $exception);
27
        }
28
29
        $this->createResponse(['response_data' => $entity], true, 200);
30
    }
31
32
    public function setDoctrine(EntityManager $manager)
33
    {
34
        $this->manager = $manager;
35
    }
36
37
    public function requiresBefore()
38
    {
39
        return [ValidateFormStep::class, GetEntityFromReflectionStep::class];
0 ignored issues
show
Bug introduced by
The type Kami\ApiCoreBundle\Reque...ntityFromReflectionStep was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
    }
41
42
43
}