Test Failed
Push — master ( 965da0...97ed9f )
by Vítězslav
04:38
created

Sand::isSerialized()   C

Complexity

Conditions 12
Paths 16

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 18
c 1
b 0
f 0
nc 16
nop 1
dl 0
loc 22
ccs 0
cts 18
cp 0
crap 156
rs 6.9666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Zakladni objekt urceny k rodicovstvi pokročilým objektum.
4
 *
5
 * @author    Vitex <[email protected]>
6
 * @copyright 2009-2019 [email protected] (G)
7
 */
8
9
namespace Ease;
10
11
/**
12
 * Zakladni objekt urceny k rodicovstvi vsem pouzivanym objektum.
13
 *
14
 * @author    Vitex <[email protected]>
15
 * @copyright 2009-2012 [email protected] (G)
16
 */
17
class Sand extends Molecule
18
{
19
    /**
20
     * Default Language Code.
21
     *
22
     * @var string
23
     */
24
    public $langCode = null;
25
26
    /**
27
     * Common object data holder.
28
     *
29
     * @var array
30
     */
31
    public $data = null;
32
33
//    /**
34
//     * Obsahuje všechna pole souhrně považovaná za identitu. Toto pole je plněno
35
//     * v metodě SaveObjectIdentity {volá se automaticky v EaseSand::__construct()}.
36
//     *
37
//     * @var array
38
//     */
39
//    public $identity = [];
40
//
41
//    /**
42
//     * Původní identita sloužící jako záloha k zrekonstruování počátečního stavu objektu.
43
//     *
44
//     * @var array
45
//     */
46
//    public $initialIdentity = [];
47
//
48
//    /**
49
//     * Tyto sloupecky jsou uchovavany pri operacich s identitou objektu.
50
//     * 
51
//     * @deprecated since version 2.0
52
//     *
53
//     * @var array
54
//     */
55
//    public $identityColumns = ['ObjectName',
56
//        'keyColumn',
57
//        'myTable',
58
//        'MyIDSColumn',
59
//        'MyRefIDColumn',
60
//        'myCreateColumn',
61
//        'myLastModifiedColumn',];
62
//    /**
63
//     * Synchronizační sloupeček. napr products_ids.
64
//     *
65
//     * @var string
66
//     */
67
//    public $myIDSColumn = null;
68
//
69
//    /**
70
//     * Sloupeček obsahující datum vložení záznamu do shopu.
71
//     *
72
//     * @var string
73
//     */
74
//    public $myCreateColumn = null;
75
//
76
//    /**
77
//     * Slopecek obsahujici datum poslení modifikace záznamu do shopu.
78
//     *
79
//     * @var string
80
//     */
81
//    public $myLastModifiedColumn = null;
82
83
    /**
84
     * Objekt pro logování.
85
     *
86
     * @var Logger\Regent
87
     */
88
    public $logger = null;
89
90
    /**
91
     * Odkaz na vlastnící objekt.
92
     *
93
     * @var Sand|mixed object
94
     */
95
    public $parentObject = null;
96
97
    /**
98
     * Sdílený objekt frameworku.
99
     *
100
     * @var Shared
101
     */
102
    public $easeShared = null;
103
104
//    /**
105
//     * Prapředek všech objektů.
106
//     */
107
//    public function __construct()
108
//    {
109
//        parent::__construct();
110
//        $this->initialIdentity = $this->saveObjectIdentity();
111
//    }
112
113
    /**
114
     * Přidá zprávu do sdíleného zásobníku p$this->getLogger()ro zobrazení uživateli.
115
     *
116
     * @param string $message  Text zprávy
117
     * @param string $type     Fronta zpráv (warning|info|error|success)
118
     *
119
     * @return 
120
     */
121
    public function addStatusMessage($message, $type = 'info')
122
    {
123
        return Shared::singleton()->takeMessage(new Logger\Message($message,
0 ignored issues
show
Bug introduced by
Are you sure the usage of Ease\Shared::singleton()...ype, get_class($this))) targeting Ease\Shared::takeMessage() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
124
                    $type, get_class($this)));
0 ignored issues
show
Bug introduced by
get_class($this) of type string is incompatible with the type Ease\Atom expected by parameter $caller of Ease\Logger\Message::__construct(). ( Ignorable by Annotation )

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

124
                    $type, /** @scrutinizer ignore-type */ get_class($this)));
Loading history...
125
    }
126
    
127
    /**
128
     * Předá zprávy.
129
     *
130
     * @return array
131
     */
132
    public function getStatusMessages()
133
    {
134
        return Shared::singleton()->getStatusMessages();
135
    }
136
137
    /**
138
     * Vymaže zprávy.
139
     */
140
    public function cleanMessages()
141
    {
142
        return Shared::singleton()->cleanMessages();
0 ignored issues
show
Bug introduced by
Are you sure the usage of Ease\Shared::singleton()->cleanMessages() targeting Ease\Atom::cleanMessages() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
143
    }
144
//    /**
145
//     * Nastaví novou identitu objektu.
146
//     *
147
//     * @deprecated since version 0.1
148
//     * 
149
//     * @param array $newIdentity
150
//     */
151
//    public function setObjectIdentity($newIdentity)
152
//    {
153
//        $changes = 0;
154
//        $this->saveObjectIdentity();
155
//        foreach ($this->identityColumns as $column) {
156
//            if (isset($newIdentity[$column])) {
157
//                $this->$column = $newIdentity[$column];
158
//                ++$changes;
159
//            }
160
//        }
161
//
162
//        return $changes;
163
//    }
164
//
165
//    /**
166
//     * Uloží identitu objektu do pole $this->identity.
167
//     *
168
//     * @deprecated since version 0.1
169
//     * 
170
//     * @return array pole s identitou
171
//     */
172
//    public function saveObjectIdentity()
173
//    {
174
//        foreach ($this->identityColumns as $column) {
175
//            if (isset($this->$column)) {
176
//                $this->identity[$column] = $this->$column;
177
//            }
178
//        }
179
//
180
//        return $this->identity;
181
//    }
182
//
183
//    /**
184
//     * Obnoví uloženou identitu objektu.
185
//     * 
186
//     * @deprecated since version 0.1
187
//     *
188
//     * @param array $identity pole s identitou např. array('myTable'=>'user');
189
//     */
190
//    public function restoreObjectIdentity($identity = null)
191
//    {
192
//        if (is_null($identity)) {
193
//            foreach ($this->identityColumns as $column) {
194
//                if (isset($this->identity[$column])) {
195
//                    $this->$column = $this->identity[$column];
196
//                }
197
//            }
198
//        } else {
199
//            foreach ($identity as $column) {
200
//                if (isset($this->identity[$column])) {
201
//                    $this->$column = $this->identity[$column];
202
//                }
203
//            }
204
//        }
205
//    }
206
//
207
//    /**
208
//     * Obnoví poslední použitou identitu.
209
//     * 
210
//     * @deprecated since version 0.1
211
//     */
212
//    public function resetObjectIdentity()
213
//    {
214
//        $this->identity = $this->initialIdentity;
215
//        $this->restoreObjectIdentity();
216
//    }
217
218
    /**
219
     * Vynuluje všechny pole vlastností objektu.
220
     */
221
    public function dataReset()
222
    {
223
        $this->data = [];
224
    }
225
226
    /**
227
     * Načte $data do polí objektu.
228
     *
229
     * @param array $data  asociativní pole dat
230
     * @param bool  $reset vyprazdnit pole před naplněním ?
231
     *
232
     * @return int počet načtených položek
233
     */
234
    public function setData($data, $reset = false)
235
    {
236
        $ret = null;
237
        if (!empty($data) && is_array($data) && count($data)) {
238
            if ($reset) {
239
                $this->dataReset();
240
            }
241
            if (is_array($this->data)) {
0 ignored issues
show
introduced by
The condition is_array($this->data) is always true.
Loading history...
242
                $this->data = array_merge($this->data, $data);
243
            } else {
244
                $this->data = $data;
245
            }
246
            $ret = count($data);
247
        }
248
249
        return $ret;
250
    }
251
252
    /**
253
     * Vrací celé pole dat objektu.
254
     *
255
     * @return array
256
     */
257
    public function getData()
258
    {
259
        return $this->data;
260
    }
261
262
    /**
263
     * Vrací počet položek dat objektu.
264
     *
265
     * @return int
266
     */
267
    public function getDataCount()
268
    {
269
        return count($this->data);
270
    }
271
272
    /**
273
     * Vrací hodnotu z pole dat pro MySQL.
274
     *
275
     * @param string $columnName název hodnoty/sloupečku
276
     *
277
     * @return mixed
278
     */
279
    public function getDataValue($columnName)
280
    {
281
        if (isset($this->data[$columnName])) {
282
            return $this->data[$columnName];
283
        }
284
285
        return;
286
    }
287
288
    /**
289
     * Nastaví hodnotu poli objektu.
290
     *
291
     * @param string $columnName název datové kolonky
292
     * @param mixed  $value      hodnota dat
293
     *
294
     * @return bool Success
295
     */
296
    public function setDataValue($columnName, $value)
297
    {
298
        $this->data[$columnName] = $value;
299
300
        return true;
301
    }
302
303
    /**
304
     * Odstrani polozku z pole dat pro MySQL.
305
     *
306
     * @param string $columnName název klíče k vymazání
307
     *
308
     * @return bool success
309
     */
310
    public function unsetDataValue($columnName)
311
    {
312
        if (array_key_exists($columnName, $this->data)) {
313
            unset($this->data[$columnName]);
314
315
            return true;
316
        }
317
318
        return false;
319
    }
320
321
    /**
322
     * Převezme data do aktuálního pole dat.
323
     *
324
     * @param array $data asociativní pole dat
325
     *
326
     * @return int
327
     */
328
    public function takeData($data)
329
    {
330
        if (is_array($this->data) && is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) is always true.
Loading history...
331
            $this->data = array_merge($this->data, $data);
332
        } else {
333
            $this->data = $data;
334
        }
335
336
        return empty($data) ? null : count($data);
337
    }
338
339
340
}
341