Completed
Push — wip-platform ( 1b7118...2b724b )
by
unknown
03:32
created

Templates::fixTemplates()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 6
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\Bundle\CoreBundle\Admin\Traits;
14
15
use Sonata\AdminBundle\Show\ShowMapper;
16
use Sonata\AdminBundle\Datagrid\ListMapper;
17
18
trait Templates
19
{
20
    /**
21
     * @param type $mapper
22
     *
23
     * @return type
24
     */
25
    protected function fixTemplates($mapper)
26
    {
27
        $blast = $this->getConfigurationPool()->getContainer()->getParameter('blast');
0 ignored issues
show
Bug introduced by
It seems like getConfigurationPool() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
        if (!isset($blast['configuration']) && isset($blast['configuration']['templates'])) {
29
            return $this;
30
        }
31
32
        $mapping = [
33
            'ShowMapper' => 'show',
34
            'ListMapper' => 'list',
35
        ];
36
        $rc = new \ReflectionClass($mapper);
37
        if (!isset($mapping[$rc->getShortName()])) {
38
            return $this;
39
        }
40
41
        $mapType = $mapping[$rc->getShortName()];
42
        if (!isset($blast['configuration']['templates'][$mapType])) {
43
            return $this;
44
        }
45
46
        // get back the new templates
47
        $templates = $blast['configuration']['templates'][$mapType];
48
49
        // checks if something has to be done
50
        foreach ($this->{$mapType . 'FieldDescriptions'} as $fd) {
51
            if (isset($templates[$fd->getType()])) {
52
                $fd->setTemplate($templates[$fd->getType()]);
53
            }
54
        }
55
56
        return $this;
57
    }
58
}
59