Completed
Push — wip-platform ( 03cba6...2999ab )
by
unknown
05:53 queued 02:49
created

Actions::removeActions()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 24
nc 11
nop 0
1
<?php
2
3
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Admin\Traits;
13
14
use Sonata\AdminBundle\Datagrid\ListMapper;
15
16
trait Actions
17
{
18
    protected function addActions()
19
    {
20
        $actionKey = '_actions';
21
        $mapperClass = ListMapper::class;
22
        $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...
23
24
        foreach ($this->getCurrentComposition() as $class) {
0 ignored issues
show
Bug introduced by
It seems like getCurrentComposition() 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...
25
            if (isset($blast[$class][$mapperClass])) {
26
                $config = $blast[$class][$mapperClass];
27
28 View Code Duplication
                if (isset($blast['all'][$mapperClass])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29
                    $config = array_merge_recursive(
30
                    $config,
31
                    $blast['all'][$mapperClass]
32
                );
33
                }
34
35
                if (isset($config['add'][$actionKey])) {
36
                    $listFields = $this->getListFieldDescriptions();
0 ignored issues
show
Bug introduced by
It seems like getListFieldDescriptions() 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...
37
38
                    if (isset($listFields['_action'])) {
39
                        $conf = $listFields['_action'];
40
                        $options = $conf->getOptions();
41
                        $actions = $options['actions'];
42
43
                        foreach ($config['add'][$actionKey] as $key => $action) {
44
                            $actions[$key] = $action;
45
                        }
46
47
                        $options['actions'] = $actions;
48
                        $conf->setOptions($options);
49
                        $listFields['_action'] = $conf;
50
                    }
51
                }
52
            }
53
        }
54
    }
55
56
    protected function removeActions()
57
    {
58
        $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...
59
60
        foreach ($this->getCurrentComposition() as $class) {
0 ignored issues
show
Bug introduced by
It seems like getCurrentComposition() 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...
61
            if (!isset($blast[$class][ListMapper::class])) {
62
                continue;
63
            }
64
65
            $listFields = $this->getListFieldDescriptions();
0 ignored issues
show
Bug introduced by
It seems like getListFieldDescriptions() 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...
66
            if (!isset($listFields['_action'])) {
67
                continue;
68
            }
69
70
            $config = $blast[$class][ListMapper::class];
71
            if (isset($blast['all'][ListMapper::class])) {
72
                $config = array_merge_recursive(
73
                    $config,
74
                    $blast['all'][ListMapper::class]
75
                );
76
            }
77
            if (!isset($config['remove']['_actions'])) {
78
                continue;
79
            }
80
81
            $conf = $listFields['_action'];
82
            $options = $conf->getOptions();
83
            $actions = $options['actions'];
84
85
            foreach ($config['remove']['_actions'] as $action) {
86
                if (isset($actions[$action])) {
87
                    unset($actions[$action]);
88
                }
89
            }
90
91
            $options['actions'] = $actions;
92
            $conf->setOptions($options);
93
            $listFields['_action'] = $conf;
94
        }
95
    }
96
}
97