1 | <?php |
||
10 | class Moo_EditableFieldGroup extends DataObject |
||
11 | { |
||
12 | private static $db = [ |
||
13 | 'Title' => 'Varchar(255)', |
||
14 | ]; |
||
15 | |||
16 | private static $many_many = [ |
||
17 | 'Fields' => 'Moo_EditableField', |
||
18 | ]; |
||
19 | |||
20 | private static $many_many_extraFields = [ |
||
21 | 'Fields' => [ |
||
22 | 'Sort' => 'Int', |
||
23 | ], |
||
24 | ]; |
||
25 | |||
26 | private static $default_sort = '"Title"'; |
||
27 | |||
28 | private static $singular_name = 'Group'; |
||
29 | |||
30 | private static $plural_name = 'Groups'; |
||
31 | |||
32 | /** |
||
33 | * Make sure the title is required field. |
||
34 | * |
||
35 | * @return RequiredFields |
||
36 | */ |
||
37 | 1 | public function getCMSValidator() |
|
41 | |||
42 | /** |
||
43 | * Returns form fields for adding/editing the data object. |
||
44 | * |
||
45 | * @return FieldList |
||
46 | */ |
||
47 | 1 | public function getCMSFields() |
|
73 | } |
||
74 |
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: