Passed
Pull Request — main (#28)
by Tan
02:41
created

UserTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 2
Metric Value
wmc 4
eloc 17
c 3
b 2
f 2
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A searchableAs() 0 3 1
A toSearchableArray() 0 17 3
1
<?php
2
3
namespace CSlant\Blog\Core\Models\Traits;
4
5
use CSlant\Blog\Core\Models\User;
6
use CSlant\Blog\ElasticScout\Modules\Traits\SearchableAs;
0 ignored issues
show
Bug introduced by
The type CSlant\Blog\ElasticScout...les\Traits\SearchableAs 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 Illuminate\Support\Facades\Log;
8
use Laravel\Scout\Searchable;
9
10
/**
11
 * Trait UserTrait
12
 * @package CSlant\Blog\Core\Models\Traits
13
 * @mixin SearchableAs
14
 *
15
 * @method string userSearchableAs() see \CSlant\Blog\ElasticScout\Modules\Traits\SearchableAs::userSearchableAs()
16
 */
17
trait UserTrait
18
{
19
    use Searchable;
20
    use SearchableAs;
21
22
    public function searchableAs(): string
23
    {
24
        return $this->userSearchableAs();
25
    }
26
27
    public function toSearchableArray(): array
28
    {
29
        Log::info("UserTrait::toSearchableArray(), Es User: " . $this->getKey());
30
31
        /** @var User $this */
32
        return [
33
            'id' => $this->id,
34
            'email' => $this->email,
35
            'email_lowercase' => strtolower($this->email),
36
            'created_at' => $this->created_at,
37
            'updated_at' => $this->updated_at,
38
            'first_name' => $this->first_name,
39
            'last_name' => $this->last_name,
40
            'username' => $this->username,
41
            'permissions' => $this->permissions,
42
            'avatar' => $this->avatar ? $this->avatar->name : null,
43
            'avatar_url' => $this->avatar ? $this->avatar->url : null,
44
        ];
45
    }
46
}
47