| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 14 | public function pref($key, $value = null, $type = 'string') |
|
| 30 | { |
||
| 31 | 14 | if (isset($value)) { |
|
| 32 | 10 | $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type), |
|
| 33 | 10 | 'type' => $type, ]); |
|
| 34 | |||
| 35 | 10 | Cache::put("{$this->slug}.'/'.{$key}", $value, 60); |
|
| 36 | 10 | return $value; |
|
| 37 | } |
||
| 38 | |||
| 39 | 14 | if($value = Cache::get("{$this->slug}.'/'.{$key}")) |
|
| 40 | { |
||
| 41 | 10 | return $value; |
|
| 42 | } |
||
| 43 | |||
| 44 | 5 | if ($pref = $this->preferences()->forKey($key)->first()) { |
|
| 45 | 1 | $value = $pref->value(); |
|
| 46 | 1 | $type = $pref->type(); |
|
| 47 | } else { |
||
| 48 | 4 | $default = Preference::getDefault($this, $key); |
|
| 49 | 4 | $value = $default->value(); |
|
| 50 | 4 | $type = $default->type(); |
|
| 51 | } |
||
| 52 | |||
| 53 | 5 | Cache::put("{$this->slug}.'/'.{$key}", $value, 60); |
|
| 54 | 5 | return $this->cast($value, $type); |
|
| 55 | } |
||
| 56 | |||
| 92 |
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
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). 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.