These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Modules\Tag\Repositories\Cache; |
||
4 | |||
5 | use Modules\Core\Repositories\Cache\BaseCacheDecorator; |
||
6 | use Modules\Tag\Repositories\TagRepository; |
||
7 | |||
8 | class CacheTagDecorator extends BaseCacheDecorator implements TagRepository |
||
9 | { |
||
10 | public function __construct(TagRepository $tag) |
||
11 | { |
||
12 | parent::__construct(); |
||
13 | $this->entityName = 'tag.tags'; |
||
14 | $this->repository = $tag; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Get all the tags in the given namespace |
||
19 | * @param string $namespace |
||
20 | * @return \Illuminate\Database\Eloquent\Collection |
||
21 | */ |
||
22 | public function allForNamespace($namespace) |
||
23 | { |
||
24 | return $this->cache |
||
25 | ->tags($this->entityName, 'global') |
||
26 | ->remember("{$this->locale}.{$this->entityName}.allForNamespace.{$namespace}", $this->cacheTime, |
||
27 | function () use ($namespace) { |
||
28 | return $this->repository->allForNamespace($namespace); |
||
1 ignored issue
–
show
|
|||
29 | } |
||
30 | ); |
||
31 | } |
||
32 | } |
||
33 |
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: