| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function getOptions() |
||
| 14 | { |
||
| 15 | if ($this->options instanceof \Closure) { |
||
| 16 | $options = ($this->options)(); |
||
| 17 | } elseif ($this->isOptionsModel()) { |
||
| 18 | $options = $this->getOptionsFromModel(); |
||
| 19 | } elseif (is_array($this->options)) { |
||
| 20 | $options = $this->options; |
||
| 21 | } else { |
||
| 22 | throw new InvalidArgumentException( |
||
| 23 | sprintf( |
||
| 24 | "The %s element[%s] options must be return array(key=>value)", |
||
| 25 | $this->getType(), |
||
|
|
|||
| 26 | $this->getName() |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | return collect($options)->mapWithKeys(function ($value, $key) { |
||
| 32 | return [ |
||
| 33 | $key => [ |
||
| 34 | 'label' => $value, |
||
| 35 | 'value' => (string) $key, |
||
| 36 | ], |
||
| 37 | ]; |
||
| 38 | })->values(); |
||
| 39 | } |
||
| 40 | |||
| 53 |
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.