EloquentPresenter::getQualifiedTitleName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Services\Breadcrumbs;
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
7
class EloquentPresenter
8
{
9
    /**
10
     * @var Model
11
     */
12
    protected $eloquent;
13
14
    public function __construct($eloquent)
15
    {
16
        $this->eloquent = $eloquent;
17
    }
18
19
    public function present()
20
    {
21
        if (!($field = $this->getQualifiedTitleName())) {
22
            $field = $this->eloquent->getRouteKeyName();
23
        }
24
25
        return (string) $this->eloquent->getAttribute($field);
26
    }
27
28
    protected function getQualifiedTitleName()
29
    {
30
        foreach (['title', 'name', 'username', 'nickname'] as $column) {
31
            if (array_key_exists($column, $this->eloquent->toArray())) {
32
                return $column;
33
            }
34
        }
35
36
        return null;
37
    }
38
}
39