Completed
Push — master ( 0e1003...1276c7 )
by Abdelrahman
61:46 queued 59:06
created

LogTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
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 Rinvex\Support\Traits\Escaper;
9
use Illuminate\Support\Facades\Route;
10
use League\Fractal\TransformerAbstract;
11
12
class LogTransformer extends TransformerAbstract
13
{
14
    use Escaper;
15
16
    /**
17
     * @return array
18
     */
19
    public function transform(Log $log): array
20
    {
21
        $causer_route = '';
22
23
        if ($log->causer) {
24
            $class = explode('\\', get_class($log->causer));
25
            $singleResource = lower_case(end($class));
26
            $pluralResource = str_plural(lower_case(end($class)));
27
            $causer = ucfirst($singleResource).': '.($log->causer->username ?? $log->causer->name ?? $log->causer->slug);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
28
            $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...
29
        } else {
30
            $causer = 'System';
31
        }
32
33
        return $this->escape([
34
            'id' => (int) $log->getKey(),
35
            'description' => (string) $log->description,
36
            'causer' => $causer,
37
            'causer_route' => $causer_route,
38
            'properties' => (object) $log->properties,
39
            'created_at' => (string) $log->created_at,
40
        ]);
41
    }
42
}
43