Passed
Push — develop ( 3e7b2f...75e02f )
by Andrea
15:44
created

TableSchemaSubscriber   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 21.74%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 35
ccs 5
cts 23
cp 0.2174
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B loadClassMetadata() 0 26 7
A getSubscribedEvents() 0 3 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Subscriber;
4
5
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
6
use Doctrine\ORM\Mapping\ClassMetadataInfo;
7
use Doctrine\ORM\Id\SequenceGenerator;
8
9
class TableSchemaSubscriber implements \Doctrine\Common\EventSubscriber
10
{
11
    public $container;
12
    
13 43
    public function getSubscribedEvents()
14
    {
15 43
        return array('loadClassMetadata');
16
    }
17
18 30
    public function loadClassMetadata(LoadClassMetadataEventArgs $args)
19
    {
20 30
        $tableschema = $this->container->getParameter('bi_core.table_schema');
21 30
        if ($tableschema != '') {
22
            $classMetadata = $args->getClassMetadata();
23
24
            $classMetadata->setPrimaryTable(array('name' => $tableschema.'.'.$classMetadata->getTableName()));
25
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
26
                $jointablename = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
27
                if ($mapping['type'] == ClassMetadataInfo::MANY_TO_MANY && isset($jointablename)) {
28
                    $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 53 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $tableschema.'.'.$mappedTableName;
30
                }
31
            }
32
            if ($classMetadata->isIdGeneratorSequence()) {
33
                $newDefinition = $classMetadata->sequenceGeneratorDefinition;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
                $newDefinition['sequenceName'] = $tableschema.'.'.$newDefinition['sequenceName'];
35
36
                $classMetadata->setSequenceGeneratorDefinition($newDefinition);
37
                $em = $args->getEntityManager();
38
                if (isset($classMetadata->idGenerator)) {
39
                    $sequncename = $em->getConfiguration()->getQuoteStrategy()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40
                            ->getSequenceName($newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform());
41
                    $allocationSize = $newDefinition['allocationSize'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
                    $sequenceGenerator = new SequenceGenerator($sequncename, $allocationSize);
43
                    $classMetadata->setIdGenerator($sequenceGenerator);
44
                }
45
            }
46
        }
47 30
    }
48
}
49