Passed
Push — master ( d8c79d...e65f91 )
by Arman
02:51 queued 12s
created

User::getFieldValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.8.0
13
 */
14
15
namespace Quantum\Libraries\Auth;
16
17
/**
18
 * Class User
19
 * @package Quantum\Libraries\Auth
20
 */
21
class User
22
{
23
24
    /**
25
     * @var array
26
     */
27
    private $data = [];
28
29
    /**
30
     * Set Data
31
     * @param array $data
32
     * @return $this
33
     */
34
    public function setData(array $data): self
35
    {
36
        $this->data = $data;
37
        return $this;
38
    }
39
40
    /**
41
     * Get Data
42
     * @return array
43
     */
44
    public function getData(): array
45
    {
46
        return $this->data;
47
    }
48
49
    /**
50
     * Get Fields
51
     * @return array
52
     */
53
    public function getFields(): array
54
    {
55
        return array_keys($this->data);
56
    }
57
58
    /**
59
     * Set Fields
60
     * @param array $schema
61
     * @return $this
62
     */
63
    public function setFields(array $schema): self
64
    {
65
        foreach ($schema as $field) {
66
            if (isset($field['name'])) {
67
                $this->data[$field['name']] = '';
68
            }
69
        }
70
71
        return $this;
72
    }
73
74
    /**
75
     * Get Field Value
76
     * @param string $field
77
     * @return string|null
78
     */
79
    public function getFieldValue(string $field): ?string
80
    {
81
        return $this->hasField($field) ? $this->data[$field] : null;
82
    }
83
84
    /**
85
     * Set Fields Value
86
     * @param string $field
87
     * @param string|null $value
88
     * @return $this
89
     */
90
    public function setFieldValue(string $field, ?string $value): self
91
    {
92
        $this->data[$field] = $value;
93
        return $this;
94
    }
95
96
    /**
97
     * Has Field
98
     * @param string $field
99
     * @return bool
100
     */
101
    public function hasField(string $field): bool
102
    {
103
        return key_exists($field, $this->data);
104
    }
105
106
    /**
107
     * Gets the user property
108
     * @param string $property
109
     * @return mixed
110
     */
111
    public function __get(string $property)
112
    {
113
        return $this->getFieldValue($property);
114
    }
115
116
}
117