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

RecordKey::setMyKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Record Key methods
4
 *
5
 * @author    Vítězslav Dvořák <[email protected]>
6
 * @copyright 2019 [email protected] (G)
7
 * 
8
 * @package EasePHP
9
 * 
10
 * PHP 7
11
 */
12
13
namespace Ease;
14
15
/**
16
 *
17
 * @author Vítězslav Dvořák <[email protected]>
18
 */
19
trait RecordKey
20
{
21
    /**
22
     * Key Column for Current Record
23
     *
24
     * @var string
25
     */
26
    public $keyColumn = 'id';
27
28
    /**
29
     * Gives you value of KEY Column
30
     *
31
     * @param array $data data z nichž se vrací hodnota klíče
32
     *
33
     * @return int key column value
34
     */
35
    public function getMyKey($data = null)
36
    {
37
        $key = null;
38
        if (is_null($data)) {
39
            $data = $this->getData();
0 ignored issues
show
Bug introduced by
It seems like getData() 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

39
            /** @scrutinizer ignore-call */ 
40
            $data = $this->getData();
Loading history...
40
        }
41
        if (isset($data) && isset($data[$this->keyColumn])) {
42
            $key = $data[$this->keyColumn];
43
        }
44
45
        return $key;
46
    }
47
48
    /**
49
     * Nastavuje hodnotu klíčového políčka pro SQL.
50
     *
51
     * @param int|string $myKeyValue
52
     *
53
     * @return bool
54
     */
55
    public function setMyKey($myKeyValue)
56
    {
57
        return $this->setDataValue($this->keyColumn, $myKeyValue);
0 ignored issues
show
Bug introduced by
It seems like setDataValue() 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

57
        return $this->/** @scrutinizer ignore-call */ setDataValue($this->keyColumn, $myKeyValue);
Loading history...
58
    }
59
60
    /**
61
     * Gives you Current KeyColumn Name
62
     *
63
     * @return string
64
     */
65
    public function getKeyColumn()
66
    {
67
        return $this->keyColumn;
68
    }
69
70
    /**
71
     * Nastaví jméno klíčového sloupečku v shopu.
72
     *
73
     * @param string $keyColumn
74
     */
75
    public function setkeyColumn($keyColumn)
76
    {
77
        $this->keyColumn = $keyColumn;
78
    }
79
}
80