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; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.