Passed
Branch master (c65ffc)
by Dāvis
03:08
created

TranslationMappingListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadClassMetadata() 0 14 4
1
<?php
2
3
namespace Sludio\HelperBundle\Translatable\Listener;
4
5
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
6
7
class TranslationMappingListener
8
{
9
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
10
    {
11
        global $kernel;
12
13
        if ('AppCache' === get_class($kernel)) {
14
            $kernel = $kernel->getKernel();
15
        }
16
17
        $classMetadata = $eventArgs->getClassMetadata();
18
        $oldName = $classMetadata->getTableName();
19
        $param = $kernel->getContainer()->getParameter('sludio_helper.translatable.table');
20
        if ($oldName === 'sludio_helper_translation' && $param !== $oldName) {
21
            $table['name'] = $param;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$table was never initialized. Although not strictly required by PHP, it is generally a good practice to add $table = array(); before regardless.
Loading history...
22
            $classMetadata->setPrimaryTable($table);
23
        }
24
    }
25
}
26