Completed
Push — master ( d039a4...8016f7 )
by Mahmoud
03:07
created

Transformer::ifAdmin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace App\Port\Transformer\Abstracts;
4
5
use App\Containers\Authentication\Tasks\GetAuthenticatedUserTask;
6
use Illuminate\Support\Facades\App;
7
use League\Fractal\TransformerAbstract as FractalTransformerAbstract;
8
9
/**
10
 * Class Transformer.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
abstract class Transformer extends FractalTransformerAbstract
15
{
16
17
    /**
18
     * @return  mixed
19
     */
20
    public function user()
21
    {
22
        return App::make(GetAuthenticatedUserTask::class)->run();
23
    }
24
25
    /**
26
     * @param $adminResponse
27
     * @param $clientResponse
28
     *
29
     * @return  array
30
     */
31
    public function ifAdmin($adminResponse, $clientResponse)
32
    {
33
        if ($this->user()->hasAdminRole()) {
34
            return array_merge($clientResponse, $adminResponse);
35
        }
36
37
        return $clientResponse;
38
    }
39
40
}
41