Completed
Push — develop ( a1ec0f...2972ec )
by Abdelrahman
01:29
created

LogTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 23 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Transformers;
6
7
use Cortex\Foundation\Models\Log;
8
use Illuminate\Support\Facades\Route;
9
use League\Fractal\TransformerAbstract;
10
11
class LogTransformer extends TransformerAbstract
12
{
13
    /**
14
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,integer|string|null>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
15
     */
16
    public function transform(Log $log)
17
    {
18
        $causer_route = '';
19
20
        if ($log->causer) {
21
            $class = explode('\\', get_class($log->causer));
22
            $singleResource = lower_case(end($class));
23
            $pluralResource = str_plural(lower_case(end($class)));
24
            $causer = ucfirst($singleResource).': '.($log->causer->username ?? $log->causer->name ?? $log->causer->title ?? $log->causer->slug);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
25
            $causer_route = Route::has("adminarea.{$pluralResource}.edit") ? route("adminarea.{$pluralResource}.edit", [$singleResource => $log->causer]) : null;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 161 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
26
        } else {
27
            $causer = 'System';
28
        }
29
30
        return [
31
            'id' => (int) $log->id,
32
            'description' => (string) $log->description,
33
            'causer' => $causer,
34
            'causer_route' => $causer_route,
35
            'properties' => (object) $log->properties,
36
            'created_at' => (string) $log->created_at,
37
        ];
38
    }
39
}
40