BaseAdmin::setContentTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\AbstractAdmin;
6
7
abstract class BaseAdmin extends AbstractAdmin
8
{
9
    protected $realLocales;
10
    protected $cmsTypes;
11
    protected $blockTypes;
12
    protected $cmsEntityTypes;
13
14
    protected function getRealLocales()
15
    {
16
        if (!empty($this->realLocales)) {
17
            return $this->realLocales;
18
        }
19
20
        $container = $this->getConfigurationPool()->getContainer();
21
22
        if ($container->hasParameter('lunetics_locale.allowed_locales')) {
23
            $locales = $container->getParameter('lunetics_locale.allowed_locales');
24
            foreach ($locales as $val) {
25
                $this->realLocales[$val] = $val;
26
            }
27
        } else {
28
            $locale = $container->getParameter('default_locale');
29
            $this->realLocales[$locale] = $locale;
30
        }
31
32
        return $this->realLocales;
33
    }
34
35 View Code Duplication
    public function getBlockTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        if (!empty($this->blockTypes)) {
38
            return $this->blockTypes;
39
        }
40
41
        $container = $this->getConfigurationPool()->getContainer();
42
        $types = $container->getParameter('alpixel_cms.blocks');
43
        $this->blockTypes = $types;
44
        foreach ($this->blockTypes as $key => $array) {
45
            if ($instanceAdmin = $this->getConfigurationPool()->getAdminByClass($array['class'])) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $instanceAdmin is correct as $this->getConfigurationP...yClass($array['class']) (which targets Sonata\AdminBundle\Admin\Pool::getAdminByClass()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
46
                $this->blockTypes[$key]['admin'] = $instanceAdmin;
47
            }
48
        }
49
50
        return $this->blockTypes;
51
    }
52
53 View Code Duplication
    public function getCMSTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        if (!empty($this->cmsTypes)) {
56
            return $this->cmsTypes;
57
        }
58
59
        $container = $this->getConfigurationPool()->getContainer();
60
        $types = $container->getParameter('alpixel_cms.content_types');
61
        $this->cmsTypes = $types;
62
        foreach ($this->cmsTypes as $key => $array) {
63
            if ($instanceAdmin = $this->getConfigurationPool()->getAdminByClass($array['class'])) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $instanceAdmin is correct as $this->getConfigurationP...yClass($array['class']) (which targets Sonata\AdminBundle\Admin\Pool::getAdminByClass()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64
                $this->cmsTypes[$key]['admin'] = $instanceAdmin;
65
            }
66
        }
67
68
        return $this->cmsTypes;
69
    }
70
71
    protected function getCMSEntityTypes()
72
    {
73
        if (!empty($this->cmsEntityTypes)) {
74
            return $this->cmsEntityTypes;
75
        }
76
77
        $cmsTypes = $this->getCMSTypes();
78
        $this->cmsEntityTypes = [];
79
        foreach ($cmsTypes as $key => $array) {
80
            $type = lcfirst(substr($array['class'], (strrpos($array['class'], '\\') + 1), strlen($array['class'])));
81
            $this->cmsEntityTypes[$type] = $array['title'];
82
        }
83
84
        return $this->cmsEntityTypes;
85
    }
86
87
    public function setContentTypes($contentTypes)
88
    {
89
        $this->cmsTypes = $contentTypes;
90
    }
91
92
    public function getContentTypes()
93
    {
94
        return $this->cmsTypes;
95
    }
96
}
97