1 | <?php |
||
21 | class MySQLConverter |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $table = 'csv_data'; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $database = 'csv_data'; |
||
32 | |||
33 | /** |
||
34 | * MySQLConverter constructor. |
||
35 | * @param string $database |
||
36 | * @param string $table |
||
37 | */ |
||
38 | public function __construct(string $database = '', string $table = '') |
||
47 | |||
48 | /** |
||
49 | * @param Traversable $records |
||
50 | * @return string |
||
51 | */ |
||
52 | public function convert(Traversable $records): string |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | protected function generateUseStatement(): string |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | protected function generateDropStatement(): string |
||
77 | |||
78 | /** |
||
79 | * @param Traversable $records |
||
80 | * @return string |
||
81 | */ |
||
82 | protected function generateCreateStatement(Traversable $records): string |
||
87 | |||
88 | /** |
||
89 | * @param Traversable $records |
||
90 | * @return string |
||
91 | */ |
||
92 | protected function generateInsertStatement(Traversable $records): string |
||
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function getTableStr(): string |
||
105 | |||
106 | /** |
||
107 | * @param Traversable $records |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function prepareRecords(Traversable $records): string |
||
129 | |||
130 | |||
131 | /** |
||
132 | * @param Traversable $records |
||
133 | * @return string |
||
134 | */ |
||
135 | protected function prepareColumns(Traversable $records): string |
||
179 | } |
||
180 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: