Passed
Branch master (c82b8d)
by Henri
02:42 queued 01:24
created

User   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 14
c 1
b 0
f 1
dl 0
loc 31
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A __construct() 0 5 1
A getVars() 0 7 2
A __set() 0 3 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