Completed
Push — master ( b768aa...b32f2f )
by Vítězslav
03:57
created

Stitky::setLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * FlexiPeeHP - Document Default Address support
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2018 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Add for Objects use with "firma" data column
13
 * @author Vítězslav Dvořák <[email protected]>
14
 */
15
trait Stitky
16
{
17
18
    /**
19
     * Get all labels for current record
20
     * 
21
     * @return array
22
     */
23
    public function getLabels()
24
    {
25
        return Stitek::listToArray($this->getDataValue('stitky'));
0 ignored issues
show
Bug introduced by
It seems like getDataValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        return Stitek::listToArray($this->/** @scrutinizer ignore-call */ getDataValue('stitky'));
Loading history...
26
    }
27
28
    /**
29
     * Set one of availble Labels for current record
30
     * 
31
     * @param string $label
32
     * 
33
     * @return boolean Operation success
34
     */
35
    public function setLabel($label)
36
    {
37
        $this->insertToFlexiBee(['id' => $this->getRecordID(), 'stitky' => $label]);
0 ignored issues
show
Bug introduced by
It seems like insertToFlexiBee() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

37
        $this->/** @scrutinizer ignore-call */ 
38
               insertToFlexiBee(['id' => $this->getRecordID(), 'stitky' => $label]);
Loading history...
Bug introduced by
It seems like getRecordID() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

37
        $this->insertToFlexiBee(['id' => $this->/** @scrutinizer ignore-call */ getRecordID(), 'stitky' => $label]);
Loading history...
38
        return $this->lastResultCode == 201;
39
    }
40
41
    /**
42
     * UnSet Label for Current Object record
43
     *
44
     * @param string     $label
45
     * @param FlexiBeeRW $this
46
     *
47
     * @return boolean   success result ?
48
     */
49
    public function unsetLabel($label)
50
    {
51
        $result = true;
52
        $labels = self::getLabels($this);
0 ignored issues
show
Unused Code introduced by
The call to FlexiPeeHP\Stitky::getLabels() has too many arguments starting with $this. ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-call */ 
53
        $labels = self::getLabels($this);

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...
Bug Best Practice introduced by
The method FlexiPeeHP\Stitky::getLabels() is not static, but was called statically. ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-call */ 
53
        $labels = self::getLabels($this);
Loading history...
53
        if (array_key_exists($label, $labels)) {
54
            unset($labels[$label]);
55
            $this->insertToFlexiBee(['id' => $this->getMyKey(), 'stitky@removeAll' => 'true',
0 ignored issues
show
Bug introduced by
It seems like getMyKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

55
            $this->insertToFlexiBee(['id' => $this->/** @scrutinizer ignore-call */ getMyKey(), 'stitky@removeAll' => 'true',
Loading history...
56
                'stitky' => $labels]);
57
            $result = ($this->lastResponseCode == 201);
58
        }
59
        return $result;
60
    }
61
62
    /**
63
     * UnSet all Labels for Current Object record
64
     *
65
     * @return boolean   success result ?
66
     */
67
    public function unsetLabels()
68
    {
69
        $this->insertToFlexiBee(['id' => $this->getMyKey(), 'stitky@removeAll' => 'true']);
70
        return $this->lastResponseCode == 201;
71
    }
72
}
73