RoutesWithFakeIds   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteKey() 0 4 1
A resolveRouteBinding() 0 10 2
1
<?php namespace Propaganistas\LaravelFakeId;
2
3
use Illuminate\Support\Facades\App;
4
use Exception;
5
6
trait RoutesWithFakeIds
7
{
8
    /**
9
     * Get the value of the model's route key.
10
     *
11
     * @return mixed
12
     */
13 9
    public function getRouteKey()
14
    {
15 9
        return App::make('fakeid')->encode($this->getKey());
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
16
    }
17
18
    /**
19
     * Retrieve model for route model binding
20
     *
21
     * @param  mixed  $value
22
     * @return \Illuminate\Database\Eloquent\Model|null
23
     */
24 9
    public function resolveRouteBinding($value)
25
    {
26
        try {
27 9
            $value = App::make('fakeid')->decode($value);
28 3
        } catch (Exception $e) {
29 3
            return null;
30
        }
31
32 6
        return $this->where($this->getRouteKeyName(), $value)->first();
0 ignored issues
show
Bug introduced by
The method getRouteKeyName() does not exist on Propaganistas\LaravelFakeId\RoutesWithFakeIds. Did you maybe mean getRouteKey()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
    }
34
}
35