ActivityTransformer::transform()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.584
cc 3
nc 4
nop 1
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