1 | <?php |
||
35 | class Yaml extends AbstractFileParser |
||
36 | { |
||
37 | /** |
||
38 | * Loads a YAML/YML file as an array. |
||
39 | * |
||
40 | * @param string $path File path |
||
41 | * |
||
42 | * @throws ParseException If there is an error parsing YAML/YML file |
||
43 | * |
||
44 | * @return array|object|stdClass The parsed data |
||
45 | * |
||
46 | * @since 0.1.0 |
||
47 | */ |
||
48 | 6 | public function parse($path) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | * |
||
71 | * @return array Supported extensions |
||
72 | * |
||
73 | * @since 0.1.0 |
||
74 | */ |
||
75 | 3 | public function getSupportedFileExtensions() |
|
79 | |||
80 | /** |
||
81 | * Loads in the given file and parses it. |
||
82 | * |
||
83 | * @param string $file File to load |
||
84 | * |
||
85 | * @return string|array|stdClass The parsed file data |
||
86 | * |
||
87 | * @since 0.2.4 |
||
88 | * @codeCoverageIgnore |
||
89 | */ |
||
90 | protected function loadFile($file = null) |
||
101 | |||
102 | /** |
||
103 | * Returns the formatted configuration file contents. |
||
104 | * |
||
105 | * @param array $contents configuration array |
||
106 | * |
||
107 | * @return string formatted configuration file contents |
||
108 | * |
||
109 | * @since 0.2.4 |
||
110 | * @codeCoverageIgnore |
||
111 | */ |
||
112 | protected function exportFormat($contents = null) |
||
122 | |||
123 | /** |
||
124 | * __toString. |
||
125 | * |
||
126 | * @return string |
||
127 | * @since 0.1.2 |
||
128 | * @codeCoverageIgnore |
||
129 | */ |
||
130 | public function __toString() |
||
134 | } |
||
135 | |||
137 |
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 sub-classes 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 parent class: