Variable   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isExists() 0 4 1
A sanitize() 0 9 2
A validate() 0 11 4
1
<?php
2
/**
3
 * Variable entity class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Models
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Models;
10
11
use InvalidArgumentException;
12
use EBloodBank as EBB;
13
14
/**
15
 * Variable entity class
16
 *
17
 * @since 1.0
18
 *
19
 * @Entity(repositoryClass="EBloodBank\Models\VariableRepository")
20
 * @Table(name="variable")
21
 */
22
class Variable extends Entity
23
{
24
    /**
25
     * @var   string
26
     * @since 1.0
27
     *
28
     * @Id
29
     * @Column(type="string", name="variable_name")
30
     */
31
    protected $name;
32
33
    /**
34
     * @var   string
35
     * @since 1.0
36
     *
37
     * @Column(type="string", name="variable_value", nullable=true)
38
     */
39
    protected $value;
40
41
    /**
42
     * @return bool
43
     * @since  1.0
44
     */
45
    public function isExists()
46
    {
47
        $id = (int) $this->get('id');
48
        return ! empty($id);
49
    }
50
51
    /**
52
     * @return mixed
53
     * @since  1.0
54
     * @static
55
     */
56
    public static function sanitize($key, $value)
57
    {
58
        switch ($key) {
59
            case 'name':
60
                $value = EBB\sanitizeTitle($value);
0 ignored issues
show
Bug introduced by
The function sanitizeTitle was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

60
                $value = /** @scrutinizer ignore-call */ EBB\sanitizeTitle($value);
Loading history...
61
                break;
62
        }
63
64
        return $value;
65
    }
66
67
    /**
68
     * @throws \InvalidArgumentException
69
     * @return bool
70
     * @since  1.0
71
     * @static
72
     */
73
    public static function validate($key, $value)
74
    {
75
        switch ($key) {
76
            case 'name':
77
                if (! is_string($value) || empty($value)) {
78
                    throw new InvalidArgumentException(__('Invalid variable name.'));
79
                }
80
                break;
81
        }
82
83
        return true;
84
    }
85
}
86