ActivityTransformer   A
last analyzed

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);
0 ignored issues
show
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
23
        $route = Route::has("adminarea.{$subjects}.edit") ? route("adminarea.{$subjects}.edit", [$subject => $log->subject]) : null;
24
25
        if ($log->subject) {
26
            $subjectName = ucfirst($subject).': '.($log->subject->username ?? $log->subject->name ?? $log->subject->name);
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