Passed
Push — master ( a74354...254a60 )
by Andrea
18:29 queued 11s
created

Tabella   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Test Coverage

Coverage 89.66%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 77
dl 0
loc 134
ccs 52
cts 58
cp 0.8966
rs 10
c 1
b 0
f 0
wmc 18

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaginetotali() 0 3 1
A getTraduzionefiltri() 0 3 1
A getRighetotali() 0 3 1
A getRigheperpagina() 0 3 1
A getPaginacorrente() 0 3 1
A getMaxOrdine() 0 3 1
A __construct() 0 39 4
A setMaxOrdine() 0 4 2
A getTabellaParameter() 0 10 2
A calcolaPagineTotali() 0 7 3
A getConfigurazionecolonnetabella() 0 3 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Tabella;
4
5
use Cdf\BiCoreBundle\Service\Permessi\PermessiManager;
6
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils;
7
use Cdf\BiCoreBundle\Utils\Entity\ModelUtils;
8
use Cdf\BiCoreBundle\Utils\Api\ApiUtils;
9
use Doctrine\ORM\EntityManager;
10
use Symfony\Component\Security\Core\Security;
11
use \Doctrine\Bundle\DoctrineBundle\Registry;
12
13
/**
14
 * @property EntityManager                        $em
15
 * @property PermessiManager $permessi
16
 * @property Security          $user
17
 */
18
19
/**
20
 * @SuppressWarnings(PHPMD.TooManyFields)
21
 */
22
class Tabella
23
{
24
    use TabellaQueryTrait,
0 ignored issues
show
Bug introduced by
The trait Cdf\BiCoreBundle\Utils\Tabella\TabellaQueryTrait requires the property $reflFields which is not provided by Cdf\BiCoreBundle\Utils\Tabella\Tabella.
Loading history...
25
        TabellaOpzioniTrait,
26
        TabellaDecoderTrait;
27
28
    protected $parametri;
29
    protected $colonnedatabase;
30
    protected $opzionitabellacore;
31
    protected $configurazionecolonnetabella;
32
    protected $entityname;
33
    protected $tablename;
34
    protected $modellocolonne;
35
    protected $paginacorrente;
36
    protected $righeperpagina;
37
    protected $estraituttirecords;
38
    protected $prefiltri;
39
    protected $filtri;
40
    protected $wheremanuale;
41
    protected $colonneordinamento;
42
    protected $permessi;
43
    protected $records;
44
    protected $paginetotali;
45
    protected $righetotali;
46
    protected $traduzionefiltri;
47
    protected $maxordine = 0;
48
    protected $em;
49
    protected $user;
50
    protected $apiController;
51
    protected $apiCollection;
52
    protected $apiBook;
53
54 12
    public function __construct(Registry $doctrine, array $parametri)
55
    {
56 12
        $this->parametri = $parametri;
57 12
        if (isset($this->parametri['em'])) {
58 12
            $this->em = $doctrine->getManager(ParametriTabella::getParameter($this->parametri['em']));
59
        } else {
60
            $this->em = $doctrine->getManager();
61
        }
62
63 12
        $this->tablename = $this->getTabellaParameter('tablename');
64 12
        $this->entityname = $this->getTabellaParameter('entityclass');
65 12
        $this->entityname = str_replace('FiBiCoreBundle', 'BiCoreBundle', $this->entityname);
66 12
        $this->permessi = json_decode($this->getTabellaParameter('permessi'));
67 12
        $this->modellocolonne = json_decode($this->getTabellaParameter('modellocolonne', '{}'), true);
68 12
        $this->paginacorrente = $this->getTabellaParameter('paginacorrente');
69 12
        $this->paginetotali = $this->getTabellaParameter('paginetotali');
70 12
        $this->righeperpagina = $this->getTabellaParameter('righeperpagina', 15);
71
72 12
        $this->estraituttirecords = '1' === $this->getTabellaParameter('estraituttirecords', 0) ? true : false;
73 12
        $this->colonneordinamento = json_decode($this->getTabellaParameter('colonneordinamento', '{}'), true);
74 12
        $this->prefiltri = json_decode($this->getTabellaParameter('prefiltri', '{}'), true);
75 12
        $this->filtri = json_decode($this->getTabellaParameter('filtri', '{}'), true);
76 12
        $this->wheremanuale = $this->getTabellaParameter('wheremanuale', null);
77 12
        $this->user = $this->parametri['user'];
78
79 12
        if (!isset($this->parametri['isapi'])) {
80 12
            $utils = new EntityUtils($this->em, $this->entityname);
0 ignored issues
show
Unused Code introduced by
The call to Cdf\BiCoreBundle\Utils\E...ityUtils::__construct() has too many arguments starting with $this->entityname. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
            $utils = /** @scrutinizer ignore-call */ new EntityUtils($this->em, $this->entityname);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
81 12
            $this->colonnedatabase = $utils->getEntityColumns($this->entityname);
82
        } else {
83
            $this->apiController = $this->getTabellaParameter('apicontroller');
84
            $this->apiCollection = $this->getTabellaParameter('apicollection');
85
            $this->apiBook = new ApiUtils($this->apiCollection);
86
            //in this moment is not set for API
87
            $modelUtils = new ModelUtils();
88
            $this->colonnedatabase = $modelUtils->getEntityColumns($this->entityname);
89
        }
90
      
91 12
        $this->opzionitabellacore = $this->getOpzionitabellaFromCore();
92 12
        $this->configurazionecolonnetabella = $this->getAllOpzioniTabella();
93 12
    }
94
95 12
    private function getTabellaParameter($name, $default = null)
96
    {
97 12
        $risposta = null;
98 12
        if (isset($this->parametri[$name])) {
99 12
            $risposta = ParametriTabella::getParameter($this->parametri[$name]);
100
        } else {
101 12
            $risposta = $default;
102
        }
103
104 12
        return $risposta;
105
    }
106
107 12
    public function calcolaPagineTotali($limit)
108
    {
109 12
        if (0 == $this->righetotali) {
110 1
            return 1;
111
        }
112
        /* calcola in mumero di pagine totali necessarie */
113 12
        return ceil($this->righetotali / (0 == $limit ? 1 : $limit));
114
    }
115
116 12
    public function getPaginacorrente()
117
    {
118 12
        return $this->paginacorrente;
119
    }
120
121 7
    public function getPaginetotali()
122
    {
123 7
        return $this->paginetotali;
124
    }
125
126 12
    public function getRigheperpagina()
127
    {
128 12
        return $this->righeperpagina;
129
    }
130
131 12
    public function getRighetotali()
132
    {
133 12
        return $this->righetotali;
134
    }
135
136 7
    public function getTraduzionefiltri()
137
    {
138 7
        return $this->traduzionefiltri;
139
    }
140
141 10
    public function getConfigurazionecolonnetabella()
142
    {
143 10
        return $this->configurazionecolonnetabella;
144
    }
145
146 12
    protected function setMaxOrdine($ordinecorrente)
147
    {
148 12
        if ($ordinecorrente > $this->maxordine) {
149 12
            $this->maxordine = $ordinecorrente;
150
        }
151 12
    }
152
153 12
    protected function getMaxOrdine()
154
    {
155 12
        return $this->maxordine;
156
    }
157
}
158