Completed
Push — wip-platform ( 1036f7...1dee5f )
by
unknown
06:03
created

Base::configureListFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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 Blast\Bundle\CoreBundle\Admin\CoreAdmin;
16
use Blast\Bundle\CoreBundle\DataSource\Iterator;
17
use Sonata\AdminBundle\Datagrid\DatagridMapper;
18
use Sonata\AdminBundle\Datagrid\ListMapper;
19
use Sonata\AdminBundle\Form\FormMapper;
20
use Sonata\AdminBundle\Show\ShowMapper;
21
22
trait Base
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $exportFields = [];
28
29
    /**
30
     * @param DatagridMapper $mapper
31
     */
32
    protected function configureDatagridFilters(DatagridMapper $mapper)
33
    {
34
        CoreAdmin::configureDatagridFilters($mapper);
0 ignored issues
show
Bug introduced by
The method configureDatagridFilters() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
35
    }
36
37
    /**
38
     * @param ListMapper $mapper
39
     */
40
    protected function configureListFields(ListMapper $mapper)
41
    {
42
        CoreAdmin::configureListFields($mapper);
0 ignored issues
show
Bug introduced by
The method configureListFields() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
43
    }
44
45
    /**
46
     * @param FormMapper $mapper
47
     */
48
    protected function configureFormFields(FormMapper $mapper)
49
    {
50
        CoreAdmin::configureFormFields($mapper);
0 ignored issues
show
Bug introduced by
The method configureFormFields() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
51
    }
52
53
    /**
54
     * @param ShowMapper $mapper
55
     */
56
    protected function configureShowFields(ShowMapper $mapper)
57
    {
58
        CoreAdmin::configureShowFields($mapper);
0 ignored issues
show
Bug introduced by
The method configureShowFields() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     **/
64
    public function getBatchActions()
65
    {
66
        $actions = [];
67
68
        if ($this->isGranted('DELETE')) {
0 ignored issues
show
Bug introduced by
It seems like isGranted() 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...
69
            $actions['delete'] = array(
70
               'label'              => 'action_delete',
71
               'translation_domain' => 'SonataAdminBundle',
72
               'ask_confirmation'   => true,
73
           );
74
        }
75
76
        return $this->handleBatchActions($actions);
0 ignored issues
show
Bug introduced by
It seems like handleBatchActions() 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...
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     **/
82
    public function getExportFormats()
83
    {
84
        $formats = [];
85
        foreach (parent::getExportFormats() as $format) {
86
            $formats[$format] = [];
87
        }
88
89
        return array_keys($this->addPresetExportFormats($formats));
0 ignored issues
show
Bug introduced by
It seems like addPresetExportFormats() 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...
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function getExportFields()
96
    {
97
        // prerequisites
98
        $fields = parent::getExportFields();
0 ignored issues
show
Unused Code introduced by
$fields 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...
99
        $this->getExportFormats();
100
101
        // nothing to add
102
        if (!$this->exportFields) {
103
            return parent::getExportFields();
104
        }
105
106
        // nothing specific to add
107
        if (!($this->getConfigurationPool()->getContainer()->get('request')->get('format')
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...
108
            && isset($this->exportFields[$this->getConfigurationPool()->getContainer()->get('request')->get('format')]))) {
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...
109
            return parent::getExportFields();
110
        }
111
112
        // specificities for this format
113
        return $this->exportFields[$this->getConfigurationPool()->getContainer()->get('request')->get('format')];
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...
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function getDataSourceIterator()
120
    {
121
        $datagrid = $this->getDatagrid();
0 ignored issues
show
Bug introduced by
It seems like getDatagrid() 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...
122
        $datagrid->buildPager();
123
124
        return new Iterator($datagrid->getQuery()->getQuery(), $this->getExportFields());
125
    }
126
}
127