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

TablePrefixSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 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