Completed
Push — master ( 077837...1dc5b3 )
by Andrea
51:40 queued 46:37
created

TablePrefixSubscriber::loadClassMetadata()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.2269

Importance

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