Completed
Push — wip-platform ( f9e163...53fa26 )
by
unknown
02:09
created

Base::configureShowFields()   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
 *
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 Blast\Bundle\CoreBundle\Admin\CoreAdmin;
15
use Blast\Bundle\CoreBundle\DataSource\Iterator;
16
use Sonata\AdminBundle\Datagrid\DatagridMapper;
17
use Sonata\AdminBundle\Datagrid\ListMapper;
18
use Sonata\AdminBundle\Form\FormMapper;
19
use Sonata\AdminBundle\Show\ShowMapper;
20
21
trait Base
22
{
23
    /**
24
     * @var array
25
     */
26
    protected $exportFields = [];
27
28
    /**
29
     * @param DatagridMapper $mapper
30
     */
31
    protected function configureDatagridFilters(DatagridMapper $mapper)
32
    {
33
        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...
34
    }
35
36
    /**
37
     * @param ListMapper $mapper
38
     */
39
    protected function configureListFields(ListMapper $mapper)
40
    {
41
        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...
42
    }
43
44
    /**
45
     * @param FormMapper $mapper
46
     */
47
    protected function configureFormFields(FormMapper $mapper)
48
    {
49
        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...
50
    }
51
52
    /**
53
     * @param ShowMapper $mapper
54
     */
55
    protected function configureShowFields(ShowMapper $mapper)
56
    {
57
        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...
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     **/
63
    public function getBatchActions()
64
    {
65
        $actions = [];
66
67
        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...
68
            $actions['delete'] = array(
69
               'label'              => 'action_delete',
70
               'translation_domain' => 'SonataAdminBundle',
71
               'ask_confirmation'   => true,
72
           );
73
        }
74
75
        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...
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     **/
81
    public function getExportFormats()
82
    {
83
        $formats = [];
84
        foreach (parent::getExportFormats() as $format) {
85
            $formats[$format] = [];
86
        }
87
88
        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...
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getExportFields()
95
    {
96
        // prerequisites
97
        $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...
98
        $this->getExportFormats();
99
100
        // nothing to add
101
        if (!$this->exportFields) {
102
            return parent::getExportFields();
103
        }
104
105
        $request = $this->getConfigurationPool()->getContainer()->get('request_stack')->getMasterRequest();
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...
106
107
        // nothing specific to add
108
        if (!($request->get('format')
109
            && isset($this->exportFields[$request->get('format')]))) {
110
            return parent::getExportFields();
111
        }
112
113
        // specificities for this format
114
        return $this->exportFields[$request->get('format')];
115
    }
116
117
    // /**
118
    //  * {@inheritdoc}
119
    //  */
120
    // public function getDataSourceIterator()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
    // {
122
    //     $datagrid = $this->getDatagrid();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
123
    //     $datagrid->buildPager();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
124
    //
125
    //     return $this->getModelManager()->getDataSourceIterator($datagrid, $this->getExportFields());
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
    //     // return new Iterator($datagrid->getQuery()->getQuery(), $this->getExportFields());
127
    // }
128
}
129