Completed
Pull Request — master (#1)
by Michael
02:12
created

ObjectOptions::options()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Iatstuti\SimpleMenu\Traits;
4
5
/**
6
 * Trait to handle retrieving all or a specific option.
7
 *
8
 * @package    Iatstuti\SimpleMenu
9
 * @copyright  2016 IATSTUTI
10
 * @author     Michael Dyrynda <[email protected]>
11
 */
12
trait ObjectOptions
13
{
14
15
    /**
16
     * Return this menu's options, or a single option as specified.
17
     *
18
     * @param  null $key
19
     *
20
     * @return array
21
     */
22
    public function options($key = null)
23
    {
24
        if (! is_null($key) && array_key_exists($key, $this->options)) {
25
            return $this->options[$key];
1 ignored issue
show
Bug introduced by
The property options does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
        }
27
28
        return $this->options;
29
    }
30
31
}
32