Passed
Push — master ( 428f46...c925bb )
by Sebastian
02:32
created
src/Traits/Optionable.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
  */
27 27
 trait Traits_Optionable
28 28
 {
29
-   /**
30
-    * @var array
31
-    */
29
+    /**
30
+     * @var array
31
+     */
32 32
     protected $options;
33 33
     
34
-   /**
35
-    * Sets an option to the specified value. This can be any
36
-    * kind of variable type, including objects, as needed.
37
-    * 
38
-    * @param string $name
39
-    * @param mixed $default
40
-    * @return mixed
41
-    */
34
+    /**
35
+     * Sets an option to the specified value. This can be any
36
+     * kind of variable type, including objects, as needed.
37
+     * 
38
+     * @param string $name
39
+     * @param mixed $default
40
+     * @return mixed
41
+     */
42 42
     public function setOption(string $name, $value) : Interface_Optionable
43 43
     {
44 44
         if(!isset($this->options)) {
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
         return $this;
50 50
     }
51 51
     
52
-   /**
53
-    * Sets a collection of options at once, from an
54
-    * associative array.
55
-    * 
56
-    * @param array $options
57
-    * @return Interface_Optionable
58
-    */
52
+    /**
53
+     * Sets a collection of options at once, from an
54
+     * associative array.
55
+     * 
56
+     * @param array $options
57
+     * @return Interface_Optionable
58
+     */
59 59
     public function setOptions(array $options) : Interface_Optionable
60 60
     {
61 61
         foreach($options as $name => $value) {
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
         return $this;
66 66
     }
67 67
     
68
-   /**
69
-    * Retrieves an option's value.
70
-    * 
71
-    * NOTE: Use the specialized type getters to ensure an option
72
-    * contains the expected type (for ex. getArrayOption()). 
73
-    * 
74
-    * @param string $name
75
-    * @param mixed $default The default value to return if the option does not exist.
76
-    * @return mixed
77
-    */
68
+    /**
69
+     * Retrieves an option's value.
70
+     * 
71
+     * NOTE: Use the specialized type getters to ensure an option
72
+     * contains the expected type (for ex. getArrayOption()). 
73
+     * 
74
+     * @param string $name
75
+     * @param mixed $default The default value to return if the option does not exist.
76
+     * @return mixed
77
+     */
78 78
     public function getOption(string $name, $default=null)
79 79
     {
80 80
         if(!isset($this->options)) {
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
         return $default;
89 89
     }
90 90
     
91
-   /**
92
-    * Enforces that the option value is a string. Scalar 
93
-    * values are converted to string, and non-scalar values
94
-    * are converted to an empty string.
95
-    * 
96
-    * @param string $name
97
-    * @return string
98
-    */
91
+    /**
92
+     * Enforces that the option value is a string. Scalar 
93
+     * values are converted to string, and non-scalar values
94
+     * are converted to an empty string.
95
+     * 
96
+     * @param string $name
97
+     * @return string
98
+     */
99 99
     public function getStringOption(string $name) : string
100 100
     {
101 101
         $value = $this->getOption($name, false);
@@ -107,15 +107,15 @@  discard block
 block discarded – undo
107 107
         return '';
108 108
     }
109 109
     
110
-   /**
111
-    * Treats the option value as a boolean value: will return
112
-    * true if the value actually is a boolean true.
113
-    * 
114
-    * NOTE: boolean string representations are not accepted.
115
-    * 
116
-    * @param string $name
117
-    * @return bool
118
-    */
110
+    /**
111
+     * Treats the option value as a boolean value: will return
112
+     * true if the value actually is a boolean true.
113
+     * 
114
+     * NOTE: boolean string representations are not accepted.
115
+     * 
116
+     * @param string $name
117
+     * @return bool
118
+     */
119 119
     public function getBoolOption(string $name) : bool
120 120
     {
121 121
         if($this->getOption($name) === true) {
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
         return false;
126 126
     }
127 127
     
128
-   /**
129
-    * Treats an option as an array, and returns its value
130
-    * only if it contains an array - otherwise, an empty
131
-    * array is returned.
132
-    * 
133
-    * @param string $name
134
-    * @return array
135
-    */
128
+    /**
129
+     * Treats an option as an array, and returns its value
130
+     * only if it contains an array - otherwise, an empty
131
+     * array is returned.
132
+     * 
133
+     * @param string $name
134
+     * @return array
135
+     */
136 136
     public function getArrayOption(string $name) : array
137 137
     {
138 138
         $val = $this->getOption($name);
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
         return array();
144 144
     }
145 145
     
146
-   /**
147
-    * Checks whether the specified option exists - even
148
-    * if it has a NULL value.
149
-    * 
150
-    * @param string $name
151
-    * @return bool
152
-    */
146
+    /**
147
+     * Checks whether the specified option exists - even
148
+     * if it has a NULL value.
149
+     * 
150
+     * @param string $name
151
+     * @return bool
152
+     */
153 153
     public function hasOption(string $name) : bool
154 154
     {
155 155
         if(!isset($this->options)) {
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
         return array_key_exists($name, $this->options);
160 160
     }
161 161
     
162
-   /**
163
-    * Returns all options in one associative array.
164
-    * @return array
165
-    */
162
+    /**
163
+     * Returns all options in one associative array.
164
+     * @return array
165
+     */
166 166
     public function getOptions() : array
167 167
     {
168 168
         if(!isset($this->options)) {
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
         return $this->options;
173 173
     }
174 174
     
175
-   /**
176
-    * Checks whether the option's value is the one specified.
177
-    * 
178
-    * @param string $name
179
-    * @param mixed $value
180
-    * @return bool
181
-    */
175
+    /**
176
+     * Checks whether the option's value is the one specified.
177
+     * 
178
+     * @param string $name
179
+     * @param mixed $value
180
+     * @return bool
181
+     */
182 182
     public function isOption(string $name, $value) : bool
183 183
     {
184 184
         return $this->getOption($name) === $value;
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     */
42 42
     public function setOption(string $name, $value) : Interface_Optionable
43 43
     {
44
-        if(!isset($this->options)) {
44
+        if (!isset($this->options)) {
45 45
             $this->options = $this->getDefaultOptions();
46 46
         }
47 47
         
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     */
59 59
     public function setOptions(array $options) : Interface_Optionable
60 60
     {
61
-        foreach($options as $name => $value) {
61
+        foreach ($options as $name => $value) {
62 62
             $this->setOption($name, $value);
63 63
         }
64 64
         
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
     * @param mixed $default The default value to return if the option does not exist.
76 76
     * @return mixed
77 77
     */
78
-    public function getOption(string $name, $default=null)
78
+    public function getOption(string $name, $default = null)
79 79
     {
80
-        if(!isset($this->options)) {
80
+        if (!isset($this->options)) {
81 81
             $this->options = $this->getDefaultOptions();
82 82
         }
83 83
         
84
-        if(isset($this->options[$name])) {
84
+        if (isset($this->options[$name])) {
85 85
             return $this->options[$name];
86 86
         }
87 87
         
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     {
101 101
         $value = $this->getOption($name, false);
102 102
         
103
-        if(is_scalar($value)) {
103
+        if (is_scalar($value)) {
104 104
             return (string)$value;
105 105
         }
106 106
         
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     */
119 119
     public function getBoolOption(string $name) : bool
120 120
     {
121
-        if($this->getOption($name) === true) {
121
+        if ($this->getOption($name) === true) {
122 122
             return true;
123 123
         }
124 124
         
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     public function getArrayOption(string $name) : array
137 137
     {
138 138
         $val = $this->getOption($name);
139
-        if(is_array($val)) {
139
+        if (is_array($val)) {
140 140
             return $val;
141 141
         }
142 142
         
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
     */
153 153
     public function hasOption(string $name) : bool
154 154
     {
155
-        if(!isset($this->options)) {
155
+        if (!isset($this->options)) {
156 156
             $this->options = $this->getDefaultOptions();
157 157
         }
158 158
         
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     */
166 166
     public function getOptions() : array
167 167
     {
168
-        if(!isset($this->options)) {
168
+        if (!isset($this->options)) {
169 169
             $this->options = $this->getDefaultOptions();
170 170
         }
171 171
         
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 interface Interface_Optionable
201 201
 {
202 202
     function setOption(string $name, $value) : Interface_Optionable;
203
-    function getOption(string $name, $default=null);
203
+    function getOption(string $name, $default = null);
204 204
     function setOptions(array $options) : Interface_Optionable;
205 205
     function getOptions() : array;
206 206
     function isOption(string $name, $value) : bool;
Please login to merge, or discard this patch.