Passed
Push — master ( 2a39ec...3b6c56 )
by Andrea
03:42
created

TablePrefixSubscriber::loadClassMetadata()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.0342

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 8
cts 9
cp 0.8889
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5.0342
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 67
    public function __construct($prefix)
12
    {
13 67
        $this->prefix = (string) $prefix;
14 67
    }
15
16 67
    public function getSubscribedEvents()
17
    {
18 67
        return array('loadClassMetadata');
19
    }
20
21 59
    public function loadClassMetadata(LoadClassMetadataEventArgs $args)
22
    {
23 59
        $classMetadata = $args->getClassMetadata();
24
25 59
        if (false !== strpos($classMetadata->namespace, 'Fi\CoreBundle')) {
26 59
            $classMetadata->setPrimaryTable(array('name' => $this->prefix.$classMetadata->getTableName()));
27
28 59
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
29 57
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY
30 57
                    && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])
31
                ) {
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 57
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName;
34
                }
35
            }
36
        }
37 59
    }
38
}
39