Passed
Push — master ( 1e250a...632266 )
by Andrea
22:07
created

TablePrefixSubscriber::loadClassMetadata()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

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