Passed
Push — master ( 27fd8a...0e6745 )
by Luiz Kim
10:23 queued 02:06
created

ExtraDataService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A persist() 0 23 4
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\ExtraData;
6
use ControleOnline\Entity\ExtraFields;
7
use Symfony\Component\Security\Core\Security;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\Security 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...
8
use Symfony\Component\Serializer\SerializerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\SerializerInterface 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...
9
use Symfony\Component\HttpFoundation\RequestStack;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\RequestStack 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...
10
11
12
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface 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...
13
14
15
class ExtraDataService
16
{
17
    private $request;
18
    public function __construct(
19
        private  EntityManagerInterface $manager,
20
        RequestStack $requestStack
21
    ) {
22
        $this->request = $requestStack->getCurrentRequest();
23
    }
24
    public function persist($class)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

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

24
    public function persist(/** @scrutinizer ignore-unused */ $class)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $extra_data = $this->request->get('extra-data');
27
        if (!$extra_data)
28
            return;
29
        foreach ($extra_data['entity_id']['data'] as $data) {
30
            $extra_fields = $this->manager->getRepository(ExtraFields::class)->find($data['id']);
31
32
            $extraData = $this->manager->getRepository(ExtraData::class)->findOneBy([
33
                'entity_id' => $extra_data['entity_id'],
34
                'entity_name' => $extra_data['entity_name'],
35
                'extra_fields' => $extra_fields
36
            ]);
37
38
            if (!$extraData)
39
                $extraData = new ExtraData();
40
41
            $extraData->setExtraFields($extra_fields);
42
            $extraData->setEntityName($extra_data['entity_name']);
43
            $extraData->setEntityId($extra_data['entity_id']);
44
            $extraData->setValue($extra_data['value']);
45
            $this->manager->persist($extraData);
46
            $this->manager->flush();
47
        }
48
    }
49
}
50