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

TablePrefixSubscriber::loadClassMetadata()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7.0283

Importance

Changes 0
Metric Value
cc 7
eloc 11
nc 5
nop 1
dl 0
loc 16
ccs 11
cts 12
cp 0.9167
crap 7.0283
rs 8.8333
c 0
b 0
f 0
1
<?php
2
namespace Cdf\BiCoreBundle\Subscriber;
3
4
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
5
6
class TablePrefixSubscriber implements \Doctrine\Common\EventSubscriber
7
{
8
    public $container;
9
    
10 43
    public function getSubscribedEvents()
11
    {
12 43
        return array('loadClassMetadata');
13
    }
14
15 30
    public function loadClassMetadata(LoadClassMetadataEventArgs $args)
16
    {
17 30
        $classMetadata = $args->getClassMetadata();
18 30
        if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
19
            // if we are in an inheritance hierarchy, only apply this once
20 30
            return;
21
        }
22 30
        if (false !== strpos($classMetadata->namespace, 'Cdf\BiCoreBundle')) {
23 30
            $tableprefix = $this->container->getParameter('bi_core.table_prefix');
24 30
            $classMetadata->setPrimaryTable(array('name' =>  $tableprefix . $classMetadata->getTableName()));
25 30
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
26 28
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY &&
27 28
                    isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])
28
                ) {
29
                    $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...
30 28
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $tableprefix . $mappedTableName;
31
                }
32
            }
33
        }
34 30
    }
35
}
36