1 | <?php namespace Modules\Translation\Repositories\File; |
||
7 | class FileTranslationRepository implements FileTranslationRepositoryInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var Filesystem |
||
11 | */ |
||
12 | private $finder; |
||
13 | /** |
||
14 | * @var LoaderInterface |
||
15 | */ |
||
16 | private $loader; |
||
17 | |||
18 | public function __construct(Filesystem $finder, LoaderInterface $loader) |
||
23 | |||
24 | /** |
||
25 | * Get all the translations for all modules on disk |
||
26 | * @return array |
||
27 | */ |
||
28 | public function all() |
||
47 | |||
48 | /** |
||
49 | * Get all of the names of the Translations files from an array of Paths. |
||
50 | * Returns [ 'translationkeyprefix' => 'filepath' ] |
||
51 | * @param array $paths |
||
52 | * @return array |
||
53 | */ |
||
54 | protected function getTranslationFilenamesFromPaths(array $paths) |
||
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: