Obfuscatable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 24
ccs 10
cts 11
cp 0.9091
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteKey() 0 5 1
A resolveRouteBinding() 0 10 2
A scopeForHash() 0 3 1
1
<?php
2
3
namespace ApiChef\Obfuscate;
4
5
use Illuminate\Database\Eloquent\ModelNotFoundException;
6
use Illuminate\Support\Facades\App;
7
use Jenssegers\Optimus\Optimus;
8
9
trait Obfuscatable
10
{
11 3
    public function resolveRouteBinding($value, $field = null)
12
    {
13 3
        $value = App::make(Optimus::class)->decode($value);
14 3
        $model = $this->where($field ?? $this->getRouteKeyName(), $value)->first();
0 ignored issues
show
Bug introduced by
It seems like where() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

14
        $model = $this->/** @scrutinizer ignore-call */ where($field ?? $this->getRouteKeyName(), $value)->first();
Loading history...
Bug introduced by
The method getRouteKeyName() does not exist on ApiChef\Obfuscate\Obfuscatable. Did you maybe mean getRouteKey()? ( Ignorable by Annotation )

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

14
        $model = $this->where($field ?? $this->/** @scrutinizer ignore-call */ getRouteKeyName(), $value)->first();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
15
16 3
        if (! is_null($model)) {
17 3
            return $model;
18
        }
19
20
        throw new ModelNotFoundException();
21
    }
22
23 15
    public function getRouteKey()
24
    {
25 15
        $value = $this->getAttribute($this->getRouteKeyName());
0 ignored issues
show
Bug introduced by
It seems like getAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-call */ 
26
        $value = $this->getAttribute($this->getRouteKeyName());
Loading history...
26
27 15
        return App::make(Optimus::class)->encode($value);
28
    }
29
30 3
    public function scopeForHash($query, $hash)
31
    {
32 3
        return $query->where('id', App::make(Optimus::class)->decode($hash));
33
    }
34
}
35