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\Display; |
||
4 | |||
5 | use Modules\Tag\Contracts\TaggableInterface; |
||
6 | use Modules\Tag\Repositories\TagRepository; |
||
7 | |||
8 | class TagWidget |
||
9 | { |
||
10 | /** |
||
11 | * @var TagRepository |
||
12 | */ |
||
13 | private $tag; |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $namespace; |
||
18 | /** |
||
19 | * @var TaggableInterface|null |
||
20 | */ |
||
21 | private $entity; |
||
22 | /** |
||
23 | * @var string|null |
||
24 | */ |
||
25 | private $view; |
||
26 | |||
27 | public function __construct(TagRepository $tag) |
||
28 | { |
||
29 | $this->tag = $tag; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param $arguments |
||
34 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
35 | */ |
||
36 | public function show($arguments) |
||
37 | { |
||
38 | $this->extractArguments($arguments); |
||
39 | |||
40 | $view = $this->view ?: 'tag::admin.fields.tags'; |
||
41 | |||
42 | $availableTags = $this->tag->allForNamespace($this->namespace); |
||
43 | |||
44 | $tags = $this->getTags(); |
||
45 | |||
46 | return view($view, compact('availableTags', 'tags')); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Extract the possible arguments as class properties |
||
51 | * @param array $arguments |
||
52 | */ |
||
53 | private function extractArguments(array $arguments) |
||
54 | { |
||
55 | $this->namespace = array_get($arguments, 0); |
||
56 | $this->entity = array_get($arguments, 1); |
||
57 | $this->view = array_get($arguments, 2); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get the available tags, if an entity is available from that |
||
62 | * @return array |
||
63 | */ |
||
64 | private function getTags() |
||
65 | { |
||
66 | if ($this->entity === null) { |
||
67 | return request()->old('tags', []); |
||
68 | } |
||
69 | |||
70 | return request()->old('tags', $this->entity->tags->lists('slug')->toArray()); |
||
0 ignored issues
–
show
|
|||
71 | } |
||
72 | } |
||
73 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: