Completed
Push — master ( 020990...9dfb7f )
by Benjamin
02:17
created

BaseAdmin   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRealLocales() 0 20 4
A getCMSTypes() 0 15 3
A getCMSEntityTypes() 0 15 3
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\Admin;
6
7
class BaseAdmin extends Admin
8
{
9
    protected $realLocales;
10
    protected $cmsTypes;
11
    protected $cmsEntityTypes;
12
13
    protected function getRealLocales()
14
    {
15
        if (!empty($this->realLocales)) {
16
            return $this->realLocales;
17
        }
18
19
        $container = $this->getConfigurationPool()->getContainer();
20
        $realLocales = [];
0 ignored issues
show
Unused Code introduced by
$realLocales is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
        if ($container->hasParameter('lunetics_locale.allowed_locales')) {
22
            $locales = $container->getParameter('lunetics_locale.allowed_locales');
23
            foreach ($locales as $val) {
24
                $this->realLocales[$val] = $val;
25
            }
26
        } else {
27
            $locale = $container->getParameter('default_locale');
28
            $this->realLocales[$locale] = $locale;
29
        }
30
31
        return $this->realLocales;
32
    }
33
34
    protected function getCMSTypes()
35
    {
36
        if (!empty($this->cmsTypes)) {
37
            return $this->cmsTypes;
38
        }
39
40
        $container = $this->getConfigurationPool()->getContainer();
41
        $types = $container->getParameter('alpixel_cms.content_types');
42
        $this->cmsTypes = [];
43
        foreach ($types as $key => $array) {
44
            $this->cmsTypes[$array['class']] = $array['title'];
45
        }
46
47
        return $this->cmsTypes;
48
    }
49
50
    protected function getCMSEntityTypes()
51
    {
52
        if (!empty($this->cmsEntityTypes)) {
53
            return $this->cmsEntityTypes;
54
        }
55
56
        $cmsTypes = $this->getCMSTypes();
57
        $this->cmsEntityTypes = [];
58
        foreach ($cmsTypes as $class => $title) {
59
            $type = lcfirst(substr($class, (strrpos($class, '\\') + 1), strlen($class)));
60
            $this->cmsEntityTypes[$type] = $title;
61
        }
62
63
        return $this->cmsEntityTypes;
64
    }
65
}
66