Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

DenominationResource   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 31
c 1
b 0
f 0
dl 0
loc 49
ccs 0
cts 27
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B toArray() 0 41 6
1
<?php
2
3
namespace App\Http\Resources\DataTables;
4
5
use Illuminate\Http\Resources\Json\JsonResource;
6
7
/**
8
 * @property \App\Models\Denomination $resource
9
 */
10
class DenominationResource extends JsonResource
11
{
12
    /**
13
     * Transform the resource into an array.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @return array
17
     */
18
    public function toArray($request)
19
    {
20
        $typeBadge = sprintf(<<<'html'
21
            <span class="badge badge-%s">
22
                <i class="fa fa-%s"></i> %s
23
            </span>
24
        html,
25
            $this->resource->type->isCoin() ? 'danger' : 'success',
0 ignored issues
show
Bug introduced by
The method isCoin() does not exist on App\Enum\DenominationType. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            $this->resource->type->/** @scrutinizer ignore-call */ 
26
                                   isCoin() ? 'danger' : 'success',
Loading history...
26
            $this->resource->type->isCoin() ? 'coins' : 'money-bill',
27
            $this->resource->type->label
28
        );
29
30
        $elements = [];
31
32
        if ($request->user()->can('view', $this->resource)) {
33
            $elements[] = view('components.datatables.link-show', [
34
                'url' => route('admin.denomination.show', $this->resource),
35
            ])->render();
36
        }
37
38
        if ($request->user()->can('update', $this->resource)) {
39
            $elements[] = view('components.datatables.link-edit', [
40
                'url' => route('admin.denomination.edit', $this->resource),
41
            ])->render();
42
        }
43
44
        if ($request->user()->can('delete', $this->resource)) {
45
            $elements[] = view('components.datatables.link-destroy', [
46
                'url' => route('admin.denomination.destroy', $this->resource),
47
            ])->render();
48
        }
49
50
        return [
51
            'checkbox' => view('components.datatables.checkbox', [
52
                'value' => $this->resource->getKey(),
53
            ])->render(),
54
            'name' => $this->resource->name,
55
            'value' => $this->resource->value_rupiah,
56
            'type' => $typeBadge,
57
            'quantity_per_bundle' => $this->resource->quantity_per_bundle . ' ' . trans('bundle'),
0 ignored issues
show
Bug introduced by
Are you sure trans('bundle') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            'quantity_per_bundle' => $this->resource->quantity_per_bundle . ' ' . /** @scrutinizer ignore-type */ trans('bundle'),
Loading history...
58
            'action' => view('components.datatables.button-group', compact('elements'))->render(),
59
        ];
60
    }
61
}
62