LogTransformer::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 9.552
cc 3
nc 3
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 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)));
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...
27
            $causer = ucfirst($singleResource).': '.($log->causer->username ?? $log->causer->name ?? $log->causer->slug);
28
            $causer_route = Route::has("adminarea.{$pluralResource}.edit") ? route("adminarea.{$pluralResource}.edit", [$singleResource => $log->causer]) : null;
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