PatientBuilder   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 57
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 4 1
A map() 0 13 4
A name() 0 5 1
A pesel() 0 5 1
A dataKategoryzacji() 0 5 1
1
<?php
2
namespace Hospitalplugin\Entities;
3
4
use Hospitalplugin\Entities\Patient;
5
6
class PatientBuilder
7
{
8
9
    private $patient = NULL;
10
11
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        $this->patient = new Patient(0);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a object<Hospitalplugin\Entities\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
14
    }
15
16
    function name($name)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
    {
18
        $this->patient->setName($name);
19
        return $this;
20
    }
21
    
22
    function pesel($pesel)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
    {
24
        $this->patient->setPesel($pesel);
25
        return $this;
26
    }
27
    
28
    function dataKategoryzacji($dataKategoryzacji)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
    {
30
        $this->patient->setDataKategoryzacji($dataKategoryzacji);
31
        return $this;
32
    }
33
    
34
    function build()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
35
    {
36
        return $this->patient;
37
    }
38
39
    /**
40
     * Maps properities of an $obj to $patient by calling setter of each property.
41
     * 
42
     * E.g. value of $obj->prop will become $patient->prop by calling $patient->setProp
43
     * 
44
     * @param unknown $patient
45
     * @param unknown $obj
46
     * @return unknown
47
     */
48
    public static function map($patient, $obj)
49
    {
50
        foreach (get_object_vars($obj) as $key => $value) {
51
            if ($value instanceof \stdClass && property_exists($value, 'date')) {
52
                $value = new \DateTime($value->date);
53
            }
54
            call_user_func(array(
55
                $patient,
56
                'set' . ucwords($key)
57
            ), $value);
58
        }
59
        return $patient;
60
    }
61
    
62
}