Completed
Push — feature/pilot_information ( 13ff1e...cc067b )
by Laurent
01:46
created

PilotForm::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 50
rs 9.0909
c 0
b 0
f 0
1
<?php
2
3
4
namespace FlightLog\Http\Web\Form;
5
6
7
use FlightLog\Application\Damage\Command\CreateDamageCommand;
8
use FlightLog\Application\Pilot\Command\CreateUpdatePilotInformationCommand;
9
use flightlog\form\Csrf;
10
use flightlog\form\Form;
11
use flightlog\form\FormInterface;
12
use flightlog\form\Hidden;
13
use flightlog\form\Input;
14
use flightlog\form\InputCheckBox;
15
use flightlog\form\InputDate;
16
use flightlog\form\Number;
17
use flightlog\form\UserSelect;
18
19
final class PilotForm extends Form
20
{
21
22
    /**
23
     * @param string $name
24
     * @param \DoliDB $db
25
     */
26
    public function __construct($name, \DoliDB $db)
27
    {
28
        parent::__construct($name, FormInterface::METHOD_POST);
29
30
        $this->add(new Hidden('pilot_id'));
31
        $this->add(new Csrf('token'));
32
33
34
        $this->add(new Input('pilot_licence_number'));
35
        $this->add(new Input('training_pilot_licence_number'));
36
37
        $this->add(new InputDate('last_training_flight_date'));
38
39
        $this->add(new InputCheckBox('is_pilot_class_a'));
40
        $this->add(new InputCheckBox('is_pilot_class_b'));
41
        $this->add(new InputCheckBox('is_pilot_class_c'));
42
        $this->add(new InputCheckBox('is_pilot_class_d'));
43
44
        $this->add(new InputCheckBox('is_pilot_gaz'));
45
46
        $this->add(new InputCheckBox('is_medical_owner'));
47
        $this->add(new InputDate('end_medical_date'));
48
        $this->add(new InputDate('start_medical_date'));
49
50
        $this->add(new InputCheckBox('has_qualif_static'));
51
        $this->add(new InputCheckBox('has_qualif_night'));
52
        $this->add(new InputCheckBox('has_qualif_pro'));
53
54
        $this->add(new InputDate('last_opc_date'));
55
        $this->add(new InputDate('last_pro_refresh_date'));
56
57
        $this->add(new InputCheckBox('has_qualif_instructor'));
58
        $this->add(new InputDate('last_instructor_refresh_date'));
59
60
        $this->add(new InputCheckBox('has_qualif_examinator'));
61
        $this->add(new InputDate('last_examinator_refresh_date'));
62
63
        $this->add(new InputCheckBox('has_radio'));
64
        $this->add(new Input('radio_licence_number'));
65
        $this->add(new InputDate('radio_licence_date'));
66
67
        $this->add(new InputCheckBox('has_training_first_help'));
68
        $this->add(new InputDate('last_training_first_help_date'));
69
        $this->add(new Input('certification_number_training_first_help'));
70
71
        $this->add(new InputCheckBox('has_training_fire'));
72
        $this->add(new InputDate('last_training_fire_date'));
73
        $this->add(new Input('certification_number_training_fire'));
74
75
    }
76
77
    /**
78
     * @return CreateUpdatePilotInformationCommand|\stdClass|null
79
     */
80
    public function getObject()
81
    {
82
        /** @var CreateUpdatePilotInformationCommand $obj */
83
        $obj = parent::getObject();
84
        return $obj;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $obj; (FlightLog\Application\Pi...PilotInformationCommand) is incompatible with the return type declared by the interface flightlog\form\FormInterface::getObject of type stdClass.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
85
    }
86
}