Passed
Push — master ( 3646da...aa9f24 )
by Andrea
16:20
created

TableSchemaSubscriber   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 32%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 38
ccs 8
cts 25
cp 0.32
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A __construct() 0 3 1
B loadClassMetadata() 0 24 7
1
<?php
2
3
namespace Cdf\BiCoreBundle\Subscriber;
4
5
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
6
use Doctrine\ORM\Mapping\ClassMetadataInfo;
7
use Doctrine\ORM\Id\SequenceGenerator;
8
9
class TableSchemaSubscriber implements \Doctrine\Common\EventSubscriber
10
{
11
    private $schemaprefix;
12
13 51
    public function __construct($schemaprefix)
14
    {
15 51
        $this->schemaprefix = $schemaprefix;
16 51
    }
17
18 51
    public function getSubscribedEvents()
19
    {
20 51
        return array('loadClassMetadata');
21
    }
22
23 37
    public function loadClassMetadata(LoadClassMetadataEventArgs $args)
24
    {
25 37
        $tableschema = $this->schemaprefix;
26 37
        if ('' != $tableschema) {
27
            $classMetadata = $args->getClassMetadata();
28
29
            $classMetadata->setPrimaryTable(array('name' => $tableschema.'.'.$classMetadata->getTableName()));
30
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
31
                if (isset($classMetadata->associationMappings[$fieldName]['joinTable']) && ClassMetadataInfo::MANY_TO_MANY == $mapping['type']) {
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'] = $tableschema.'.'.$mappedTableName;
34
                }
35
            }
36
            if ($classMetadata->isIdGeneratorSequence()) {
37
                $newDefinition = $classMetadata->sequenceGeneratorDefinition;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 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...
38
                $newDefinition['sequenceName'] = $newDefinition['sequenceName'];
39
                $classMetadata->setSequenceGeneratorDefinition($newDefinition);
40
                $em = $args->getEntityManager();
41
                if (isset($classMetadata->idGenerator)) {
42
                    $sequncename = $em->getConfiguration()->getQuoteStrategy()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
43
                            ->getSequenceName($newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform());
44
                    $allocationSize = $newDefinition['allocationSize'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
45
                    $sequenceGenerator = new SequenceGenerator($sequncename, $allocationSize);
46
                    $classMetadata->setIdGenerator($sequenceGenerator);
47
                }
48
            }
49
        }
50 37
    }
51
}
52