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

ActivityTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 21 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 ActivityTransformer extends TransformerAbstract
13
{
14
    use Escaper;
15
16
    /**
17
     * @return array
18
     */
19
    public function transform(Log $log): array
20
    {
21
        $subject = $log->subject_type;
22
        $subjects = str_plural($subject);
23
        $route = Route::has("adminarea.{$subjects}.edit") ? route("adminarea.{$subjects}.edit", [$subject => $log->subject]) : null;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 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...
24
25
        if ($log->subject) {
26
            $subjectName = ucfirst($subject).': '.($log->subject->username ?? $log->subject->name ?? $log->subject->name);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 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...
27
        } else {
28
            $subjectName = ucfirst($subject).': Not Found!';
29
        }
30
31
        return $this->escape([
32
            'id' => (int) $log->getKey(),
33
            'description' => (string) $log->description,
34
            'subject' => $subjectName,
35
            'subject_route' => $route,
36
            'properties' => (object) $log->properties,
37
            'created_at' => (string) $log->created_at,
38
        ]);
39
    }
40
}
41