Passed
Push — master ( 9d2f0c...c82b8d )
by Henri
01:28
created

User::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
require 'Address.php';
4
5
class User{
6
    public string $name = 'Henri Azevedo';
7
    public array $values = [1 => 'param1'];
8
    public Address $address;
9
10
    public array $data = [];
11
12
    public function __construct()
13
    {
14
        $this->address = new Address();
15
        $this->data = ['email'];
16
        $this->email = '[email protected]';
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
    }
18
19
    public function getVars(): array
20
    {
21
        $vars = [];
22
        foreach($this->data as $var => $value){
23
            $vars[$var] = $value;
24
        }
25
        return $vars;
26
    }
27
28
    public function __set(string $field, $value)
29
    {
30
        $this->data[$field] = $value;
31
    }
32
33
    public function __get(string $field)
34
    {
35
        return $this->data[$field];
36
    }
37
        
38
}
39