Test Failed
Push — master ( 3cff38...891bf3 )
by Vítězslav
02:41
created

Stitek::listToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt štítku.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Štítek
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/stitek/properties Vlastnosti evidence
15
 */
16
class Stitek extends FlexiBeeRW
17
{
18
    /**
19
     * Evidence Path for vsb supported by label
20
     *
21
     * @var array
22
     */
23
    static public $vsbToEvidencePath = [
24
        'vsbAdr' => 'adresar', // Adresář
25
        'vsbSkl' => 'sklad', // Sklad
26
        'vsbPhl' => 'pohledavka', // Pohledávky
27
        'vsbZav' => 'zavazek', // Závazky
28
        'vsbObp' => 'objednavka-prijata', // Objednávky přijaté
29
        'vsbNav' => 'objednavka-vydana', // Nabídky vydané
30
        'vsbPpp' => 'poptavka-prijata', // Poptávky přijaté
31
        'vsbObv' => 'objednavka-vydana', // Objednávky vydané
32
        'vsbNap' => 'nabidka-prijata', // Nabídky přijaté
33
        'vsbPpv' => 'poptavka-vydana', // Poptávky vydané
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
34
//        'vsbMzd' => 'mzda', // Mzdy
35
//        'vsbCis' => 'ciselnik', // Číselníky
36
    ];
37
38
    /**
39
     * Evidence užitá objektem.
40
     *
41
     * @var string
42
     */
43
    public $evidence = 'stitek';
44
45
    /**
46
     * Obtain labels for current record
47
     *
48
     * @param FlexiBeeRO $object data source
49
     * @return array labels
50
     */
51
    public static function getLabels($object)
52
    {
53
        $labels    = null;
54
        $labelsRaw = $object->getDataValue('stitky');
55
56
        if (strlen($labelsRaw)) {
57
            $labels = is_array($labelsRaw) ? $labelsRaw : self::listToArray($labelsRaw);
58
        }
59
        return $labels;
60
    }
61
62
    /**
63
     * Convert coma-separated list to array
64
     *
65
     * @param string $listRaw
66
     * @return array
67
     */
68
    public static function listToArray($listRaw)
69
    {
70
        if (strstr($listRaw, ',')) {
71
            $list = explode(',', $listRaw);
72
        } else {
73
            $list = [$listRaw];
74
        }
75
        return $list;
76
    }
77
78
    /**
79
     * Obtain list of availble labels for given object
80
     *
81
     * @param FlexiBeeRO $object
82
     * @return array
83
     */
84
    public static function getAvailbleLabels($object)
85
    {
86
        $labels         = [];
87
        $evidenceBackup = $object->getEvidence();
88
        $object->setEvidence('stitek');
89
        $pathToVsb      = array_flip(self::$vsbToEvidencePath);
90
91
        if (array_key_exists($evidenceBackup, $pathToVsb)) {
92
            $labelsRaw = $object->getColumnsFromFlexiBee(['kod', 'nazev'],
93
                [$pathToVsb[$evidenceBackup] => true], 'nazev');
94
            if (count($labelsRaw)) {
95
                foreach ($labelsRaw as $labelInfo) {
96
                    $labels[$labelInfo['kod']] = $labelInfo['nazev'];
97
                }
98
            }
99
        }
100
101
        $object->setEvidence($evidenceBackup);
102
        return $labels;
103
    }
104
105
}
106