Passed
Push — master ( f6f1d0...ed56e2 )
by Andrea
69:42 queued 61:17
created

TablePrefixSubscriber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 27
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSubscribedEvents() 0 3 1
B loadClassMetadata() 0 13 5
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
                ) {
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 38
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName;
34
                }
35
            }
36
        }
37 40
    }
38
}
39