Test Failed
Push — master ( e1e8a5...f6f865 )
by Vítězslav
03:08
created

SkladovyPohybPolozka   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A addSerialNumber() 0 15 4
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt položky skladového pohybu.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2018 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Položka skladového pohybu
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/skladovy-pohyb-polozka/properties
15
 */
16
class SkladovyPohybPolozka extends FlexiBeeRW
17
{
18
    /**
19
     * Evidence užitá objektem.
20
     *
21
     * @var string
22
     */
23
    public $evidence = 'skladovy-pohyb-polozka';
24
25
    /**
26
     * Add Items Serial Number
27
     * 
28
     * @param type $number
29
     * @param type $isMain
30
     * 
31
     * @return boolean Success
32
     */
33
    public function addSerialNumber($number, $isMain = false)
34
    {
35
        $numberBranch['kod'] = $number;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$numberBranch was never initialized. Although not strictly required by PHP, it is generally a good practice to add $numberBranch = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
36
        $crrentSerialNumbers = $this->getDataValue('vyrobniCislaPrijata');
37
        if ($isMain) {
38
            if (!empty($crrentSerialNumbers)) {
39
                foreach (array_keys($crrentSerialNumbers) as $serialNumberID) {
40
                    unset($this->data['vyrobniCislaPrijata'][$serialNumberID]['vyrobnicislohlav']);
41
                }
42
            }
43
            $numberBranch['vyrobnicislohlav'] = 1;
44
        }
45
        $this->setDataValue('mnozMj', count($crrentSerialNumbers) + 1);
46
        return $this->addArrayToBranch($numberBranch, 'vyrobniCislaPrijata');
47
    }
48
}
49