Passed
Push — master ( 86c140...b20c93 )
by Andrea
21:21 queued 20s
created

TablePrefixSubscriber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B loadClassMetadata() 0 13 5
A getSubscribedEvents() 0 3 1
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 64
    public function __construct($prefix)
12
    {
13 64
        $this->prefix = (string) $prefix;
14 64
    }
15
16 64
    public function getSubscribedEvents()
17
    {
18 64
        return array('loadClassMetadata');
19
    }
20
21 56
    public function loadClassMetadata(LoadClassMetadataEventArgs $args)
22
    {
23 56
        $classMetadata = $args->getClassMetadata();
24
25 56
        if (false !== strpos($classMetadata->namespace, 'Fi\CoreBundle')) {
26 56
            $classMetadata->setPrimaryTable(array('name' => $this->prefix.$classMetadata->getTableName()));
27
28 56
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
29 54
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY
30 54
                    && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])
31 54
                ) {
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 56
            }
36 56
        }
37 56
    }
38
}
39