Completed
Pull Request — develop (#26)
by Abdelrahman
01:26
created

HashidsTrait::resolveRouteBinding()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Support\Traits;
6
7
use Vinkla\Hashids\Facades\Hashids;
8
9
trait HashidsTrait
10
{
11
    /**
12
     * Get the value of the model's route key.
13
     *
14
     * @return mixed
15
     */
16
    public function getRouteKey()
17
    {
18
        $obscure = property_exists($this,'obscure') && is_array($this->obscure) ? $this->obscure : config('cortex.foundation.obscure');
19
20
        return in_array(request()->route('accessarea'), $obscure['areas'])
21
            ? Hashids::encode($this->getAttribute($this->getKeyName()), random_int(1, 999))
22
            ? Hashids::encode($this->getAttribute($this->getKeyName()), $obscure['rotate'] ? random_int(1, 999) : 1)
23
24
            : $this->getAttribute($this->getRouteKeyName());
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ';'
Loading history...
25
    }
26
27
    /**
28
     * Retrieve the model for a bound value.
29
     *
30
     * @param mixed $value
31
     *
32
     * @return \Illuminate\Database\Eloquent\Model|null
33
     */
34
    public function resolveRouteBinding($value)
35
    {
36
        $obscure = property_exists($this,'obscure') && is_array($this->obscure) ? $this->obscure : config('cortex.foundation.obscure');
37
38
        return in_array(request()->route('accessarea'), $obscure['areas'])
39
            ? $this->where($this->getKeyName(), optional(Hashids::decode($value))[0])->first()
40
            : $this->where($this->getRouteKeyName(), $value)->first();
41
    }
42
}
43