AdminMethodsShow::show()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 10
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 15
rs 9.9332
1
<?php
2
3
namespace Larrock\Core\Traits;
4
5
use Cache;
6
use LarrockCategory;
0 ignored issues
show
Bug introduced by
The type LarrockCategory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Larrock\Core\Component;
8
9
trait AdminMethodsShow
10
{
11
    /** @var Component */
12
    protected $config;
13
14
    /**
15
     * Показ подразделов/материалов раздела внутри компонента.
16
     *
17
     * @param int   $id     ID раздела
18
     * @return \View
19
     */
20
    public function show($id)
21
    {
22
        $data['app_category'] = LarrockCategory::getConfig();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
23
        $cache_key = sha1('AdminMethodsShowCategory'.$id.$this->config->getModelName());
24
        $data['category'] = Cache::rememberForever($cache_key, function () use ($id) {
25
            return LarrockCategory::getModel()->whereId($id)->with(['getChild', 'getParent'])->firstOrFail();
26
        });
27
        $cache_key = sha1('AdminMethodsShowData'.$id.$this->config->getModelName());
28
        $data['data'] = Cache::rememberForever($cache_key, function () use ($id) {
29
            return $this->config->getModel()->whereHas('getCategory', function ($q) use ($id) {
30
                $q->where('category.id', '=', $id);
31
            })->get();
32
        });
33
34
        return view('larrock::admin.admin-builder.categories', $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('larrock::ad...der.categories', $data) returns the type array<string,mixed> which is incompatible with the documented return type View.
Loading history...
Unused Code introduced by
The call to view() has too many arguments starting with $data. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        return /** @scrutinizer ignore-call */ view('larrock::admin.admin-builder.categories', $data);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
35
    }
36
}
37