Completed
Push — master ( 8413a9...d75c00 )
by Narcotic
10:07
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * a CompilerPass to assist the new JSON schema based validation for recordOriginException fields
4
 */
5
6
namespace Graviton\DocumentBundle\DependencyInjection\Compiler;
7
8
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
12
/**
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17 View Code Duplication
class RecordOriginExceptionFieldsCompilerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * @var DocumentMap
21
     */
22
    private $documentMap;
23
24
    /**
25
     * Make recordOriginException fields map and set it to parameter
26
     *
27
     * @param ContainerBuilder $container container builder
28
     *
29
     * @return void
30
     */
31 2
    public function process(ContainerBuilder $container)
32
    {
33 2
        $this->documentMap = $container->get('graviton.document.map');
34
35 2
        $map = [];
36 2
        foreach ($this->documentMap->getDocuments() as $document) {
37 2
            $recordOriginExceptionFields = $this->documentMap->getFieldNamesFlat(
38
                $document,
39 2
                '',
40 2
                '',
41 2
                function ($field) {
42 2
                    return $field->isRecordOriginException();
43 2
                }
44
            );
45
46 2
            if (!empty($recordOriginExceptionFields)) {
47 2
                foreach ($recordOriginExceptionFields as $key => $recordOriginExceptionField) {
48 2
                    if (substr($recordOriginExceptionField, -2) == '.0') {
49 1
                        unset($recordOriginExceptionFields[$key]);
50
                    }
51
                }
52
53 2
                $map[$document->getClass()] = array_values($recordOriginExceptionFields);
54
            }
55
        }
56
57 2
        $container->setParameter('graviton.document.recordoriginexception.fields', $map);
58 2
    }
59
}
60