GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ea3f3a...d850a4 )
by Marceau
02:11
created

FieldWithOptions::beforeSave()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Akibatech\Crud\Traits;
4
use Akibatech\Crud\Exceptions\InvalidModelException;
5
6
/**
7
 * Class FieldWithOptions
8
 *
9
 * @package Akibatech\Crud\Traits
10
 */
11
trait FieldWithOptions
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $options;
17
18
    /**
19
     * @var mixed
20
     */
21
    protected $default_option = null;
22
23
    /**
24
     * @param   array $options
25
     * @param   mixed $default The default value. It's a key from given options.
26
     * @return  self
27
     */
28
    public function withOptions($options = [], $default = null)
29
    {
30
        $this->options = $options;
31
32
        $this->addRule('in:' . implode(',', $this->getOptionsKeys()));
0 ignored issues
show
Bug introduced by
It seems like addRule() 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
        if (!is_null($default))
35
        {
36
            if (!array_key_exists($default, $options))
37
            {
38
                throw new InvalidModelException("$default option does not exist in given options.");
39
            }
40
41
            $this->default_option = $default;
42
        }
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param   mixed $identifier
49
     * @return  bool
50
     */
51
    public function hasOption($identifier)
52
    {
53
        return array_key_exists($identifier, $this->getOptions());
54
    }
55
56
    /**
57
     * @param   void
58
     * @return  array
59
     */
60
    public function getOptions()
61
    {
62
        return $this->options;
63
    }
64
65
    /**
66
     * @param   void
67
     * @return  array
68
     */
69
    public function getOptionsKeys()
70
    {
71
        return array_keys($this->options);
72
    }
73
74
    /**
75
     * @param   void
76
     * @return  string|null
77
     */
78
    public function getOption($identifier)
79
    {
80
        return $this->hasOption($identifier) ? $this->options[$identifier] : null;
81
    }
82
83
    /**
84
     * @param   void
85
     * @return  mixed
86
     */
87
    public function getDefaultOption()
88
    {
89
        return $this->default_option;
90
    }
91
92
    /**
93
     * @param   void
94
     * @return  string|null
95
     */
96
    public function getTableValue()
97
    {
98
        return $this->getOption($this->getValue());
0 ignored issues
show
Bug introduced by
It seems like getValue() 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...
99
    }
100
101
    /**
102
     * @param   void
103
     * @return  self
104
     */
105
    public function beforeSave()
106
    {
107
        if (is_null($this->getValue()) && !is_null($this->default_option))
0 ignored issues
show
Bug introduced by
It seems like getValue() 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...
108
        {
109
            $this->newValue($this->default_option);
0 ignored issues
show
Bug introduced by
It seems like newValue() 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...
110
        }
111
112
        return $this;
113
    }
114
}
115