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

DocumentFieldNamesCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 10 2
A getFieldNames() 0 8 2
1
<?php
2
/**
3
 * DocumentFieldNamesCompilerPass class file
4
 */
5
6
namespace Graviton\DocumentBundle\DependencyInjection\Compiler;
7
8
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\Document;
9
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
13
/**
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class DocumentFieldNamesCompilerPass implements CompilerPassInterface
19
{
20
    /**
21
     * @var DocumentMap
22
     */
23
    private $documentMap;
24
25
    /**
26
     * load services
27
     *
28
     * @param ContainerBuilder $container container builder
29
     *
30
     * @return void
31
     */
32 4
    public function process(ContainerBuilder $container)
33
    {
34 4
        $this->documentMap = $container->get('graviton.document.map');
35
36 4
        $map = [];
37 4
        foreach ($this->documentMap->getDocuments() as $document) {
38 4
            $map[$document->getClass()] = $this->getFieldNames($document);
39
        }
40 4
        $container->setParameter('graviton.document.field.names', $map);
41 4
    }
42
43
    /**
44
     * Get field names
45
     *
46
     * @param Document $document Document
47
     * @return array
48
     */
49 4
    private function getFieldNames(Document $document)
50
    {
51 4
        $result = [];
52 4
        foreach ($document->getFields() as $field) {
53 4
            $result[$field->getFieldName()] = $field->getExposedName();
54
        }
55 4
        return $result;
56
    }
57
}
58