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

ActivityTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 16 2
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 ActivityTransformer 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
        $class = explode('\\', get_class($log->subject));
19
        $subject = lower_case(end($class));
20
        $subjects = str_plural(lower_case(end($class)));
21
        $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...
22
23
        return [
24
            'id' => (int) $log->id,
25
            'description' => (string) $log->description,
26
            'subject' => ucfirst($subject).': '.($log->subject->username ?? $log->subject->name ?? $log->subject->title ?? $log->subject->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...
27
            'subject_route' => $route,
28
            'properties' => (object) $log->properties,
29
            'created_at' => (string) $log->created_at,
30
        ];
31
    }
32
}
33