HasValuePresenter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 36
ccs 0
cts 9
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPresenter() 0 6 3
A callPresenter() 0 3 1
A presenterMethod() 0 3 1
1
<?php
2
3
namespace Terranet\Administrator\Field\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model 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...
6
use Illuminate\Support\Str;
7
use Terranet\Presentable\PresentableInterface;
8
9
trait HasValuePresenter
10
{
11
    /**
12
     * Check if a model has field's presenter.
13
     *
14
     * @param Model $model
15
     * @param string $field
16
     *
17
     * @return null|callable
18
     */
19
    public function hasPresenter(Model $model, string $field): ?callable
20
    {
21
        return $model instanceof PresentableInterface
22
        && method_exists($model->present(), $method = $this->presenterMethod($field))
23
            ? [$model->present(), $method]
24
            : null;
25
    }
26
27
    /**
28
     * @param callable $presenter
29
     *
30
     * @return mixed
31
     */
32
    public function callPresenter(callable $presenter)
33
    {
34
        return \call_user_func_array($presenter, [$this->value()]);
0 ignored issues
show
Bug introduced by
It seems like value() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( 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 \call_user_func_array($presenter, [$this->/** @scrutinizer ignore-call */ value()]);
Loading history...
35
    }
36
37
    /**
38
     * @param string $fieldName
39
     *
40
     * @return string
41
     */
42
    public function presenterMethod(string $fieldName): string
43
    {
44
        return 'admin'.Str::title(Str::camel($fieldName));
45
    }
46
}
47