Passed
Push — master ( 053261...02560c )
by smiley
01:38
created
src/TraitException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,4 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\Traits;
14 14
 
15
-class TraitException extends \Exception{}
15
+class TraitException extends \Exception {}
Please login to merge, or discard this patch.
src/Magic.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * A Container that turns methods into magic properties
17 17
  */
18
-trait Magic{
18
+trait Magic {
19 19
 
20 20
 	/**
21 21
 	 * @param string $name
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	private function set(string $name, $value) {
57 57
 		$method = 'magic_set_'.$name;
58 58
 
59
-		if(method_exists($this, $method)){
59
+		if (method_exists($this, $method)) {
60 60
 			$this->$method($value);
61 61
 		}
62 62
 
Please login to merge, or discard this patch.
src/Interfaces/IteratorTrait.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @link http://php.net/manual/class.traversable.php
20 20
  */
21
-trait IteratorTrait{
21
+trait IteratorTrait {
22 22
 
23 23
 	/**
24 24
 	 * @var array
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @link  http://php.net/manual/iterator.current.php
35 35
 	 * @inheritdoc
36 36
 	 */
37
-	public function current(){
37
+	public function current() {
38 38
 		return $this->array[$this->offset] ?? null;
39 39
 	}
40 40
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @link  http://php.net/manual/iterator.next.php
43 43
 	 * @inheritdoc
44 44
 	 */
45
-	public function next(){
45
+	public function next() {
46 46
 		$this->offset++;
47 47
 	}
48 48
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @link  http://php.net/manual/iterator.key.php
51 51
 	 * @inheritdoc
52 52
 	 */
53
-	public function key(){
53
+	public function key() {
54 54
 		return $this->offset;
55 55
 	}
56 56
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @link  http://php.net/manual/iterator.rewind.php
67 67
 	 * @inheritdoc
68 68
 	 */
69
-	public function rewind(){
69
+	public function rewind() {
70 70
 		$this->offset = 0;
71 71
 	}
72 72
 
Please login to merge, or discard this patch.
src/Interfaces/SerializableTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  *
18 18
  * @link http://php.net/manual/class.serializable.php
19 19
  */
20
-trait SerializableTrait{
20
+trait SerializableTrait {
21 21
 
22 22
 	/**
23 23
 	 * @var array
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @link  http://php.net/manual/serializable.unserialize.php
37 37
 	 * @inheritdoc
38 38
 	 */
39
-	public function unserialize($serialized){
39
+	public function unserialize($serialized) {
40 40
 		$this->array = unserialize($serialized);
41 41
 	}
42 42
 
Please login to merge, or discard this patch.
src/SPL/CountableTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
  *
18 18
  * @link http://php.net/manual/class.countable.php
19 19
  */
20
-trait CountableTrait{
20
+trait CountableTrait {
21 21
 
22 22
 	/**
23 23
 	 * @var array
Please login to merge, or discard this patch.
src/SPL/SeekableIteratorTrait.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,19 +21,19 @@
 block discarded – undo
21 21
  *
22 22
  * @link http://php.net/manual/class.seekableiterator.php
23 23
  */
24
-trait SeekableIteratorTrait{
24
+trait SeekableIteratorTrait {
25 25
 	use IteratorTrait;
26 26
 
27 27
 	/**
28 28
 	 * @link  http://php.net/manual/seekableiterator.seek.php
29 29
 	 * @inheritdoc
30 30
 	 */
31
-	public function seek($pos){
31
+	public function seek($pos) {
32 32
 		$this->rewind();
33 33
 
34
-		for( ; $this->offset < $pos; ){
34
+		for (; $this->offset < $pos;) {
35 35
 
36
-			if(!next($this->array)) {
36
+			if (!next($this->array)) {
37 37
 				throw new OutOfBoundsException('invalid seek position: '.$pos);
38 38
 			}
39 39
 
Please login to merge, or discard this patch.
src/ArrayHelpers/ByteArrayDispenser.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 /**
19 19
  *
20 20
  */
21
-class ByteArrayDispenser{
21
+class ByteArrayDispenser {
22 22
 
23 23
 	/**
24 24
 	 * @var string
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function fromIntSize(int $size):ByteArray{
44 44
 
45
-		if(!$this->isAllowedInt($size)){
45
+		if (!$this->isAllowedInt($size)) {
46 46
 			throw new TraitException('invalid size');
47 47
 		}
48 48
 
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	public function fromArray($array, $save_indexes = null):ByteArray{
60 60
 
61
-		try{
61
+		try {
62 62
 			$out = $this->fromIntSize(count($array));
63 63
 
64 64
 			$array = ($save_indexes ?? true) ? $array : array_values($array);
65 65
 
66
-			foreach($array as $k => $v){
66
+			foreach ($array as $k => $v) {
67 67
 				$out[$k] = $v;
68 68
 			}
69 69
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		}
72 72
 		// this can be anything
73 73
 		// @codeCoverageIgnoreStart
74
-		catch(Exception $e){
74
+		catch (Exception $e) {
75 75
 			throw new TraitException($e->getMessage());
76 76
 		}
77 77
 		// @codeCoverageIgnoreEnd
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public function fromArrayFill(int $len, $fill = null):ByteArray{
90 90
 
91
-		if(!$this->isAllowedInt($len)){
91
+		if (!$this->isAllowedInt($len)) {
92 92
 			throw new TraitException('invalid length');
93 93
 		}
94 94
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	public function fromHex(string $hex):ByteArray{
125 125
 		$hex = preg_replace('/[\s\r\n\t ]/', '', $hex);
126 126
 
127
-		if(!$this->isAllowedHex($hex)){
127
+		if (!$this->isAllowedHex($hex)) {
128 128
 			throw new TraitException('invalid hex string');
129 129
 		}
130 130
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	public function fromJSON(string $json):ByteArray{
152 152
 		$json = trim($json);
153 153
 
154
-		if(!$this->isAllowedJSON($json)){
154
+		if (!$this->isAllowedJSON($json)) {
155 155
 			throw new TraitException('invalid JSON array');
156 156
 		}
157 157
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	public function fromBase64(string $base64):ByteArray{
179 179
 		$base64 = trim($base64);
180 180
 
181
-		if(!$this->isAllowedBase64($base64)){
181
+		if (!$this->isAllowedBase64($base64)) {
182 182
 			throw new TraitException('invalid base64 string');
183 183
 		}
184 184
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	public function fromBin(string $bin):ByteArray{
206 206
 		$bin = trim($bin);
207 207
 
208
-		if(!$this->isAllowedBin($bin)){
208
+		if (!$this->isAllowedBin($bin)) {
209 209
 			throw new TraitException('invalid binary string');
210 210
 		}
211 211
 
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 	 */
221 221
 	public function guessFrom($data):ByteArray{
222 222
 
223
-		if($data instanceof Traversable){
223
+		if ($data instanceof Traversable) {
224 224
 			return $this->fromArray(iterator_to_array($data));
225 225
 		}
226 226
 
227
-		if(is_array($data)){
227
+		if (is_array($data)) {
228 228
 			return $this->fromArray($data);
229 229
 		}
230 230
 
231
-		if(is_string($data)){
231
+		if (is_string($data)) {
232 232
 
233
-			foreach(['Bin', 'Hex', 'JSON', 'Base64'] as $type){
233
+			foreach (['Bin', 'Hex', 'JSON', 'Base64'] as $type) {
234 234
 
235
-				if(call_user_func_array([$this, 'isAllowed'.$type], [$data]) === true){
235
+				if (call_user_func_array([$this, 'isAllowed'.$type], [$data]) === true) {
236 236
 					return call_user_func_array([$this, 'from'.$type], [$data]);
237 237
 				}
238 238
 
Please login to merge, or discard this patch.
src/ArrayHelpers/DotArray.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * @link https://github.com/laravel/framework/blob/5.4/src/Illuminate/Support/Arr.php
17 17
  */
18
-trait DotArray{
18
+trait DotArray {
19 19
 
20 20
 	/**
21 21
 	 * @var array
@@ -30,17 +30,17 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return mixed returns $array[$key], $default otherwise.
32 32
 	 */
33
-	public function get(string $dotKey, $default = null){
33
+	public function get(string $dotKey, $default = null) {
34 34
 
35
-		if(isset($this->array[$dotKey])){
35
+		if (isset($this->array[$dotKey])) {
36 36
 			return $this->array[$dotKey];
37 37
 		}
38 38
 
39 39
 		$array = &$this->array;
40 40
 
41
-		foreach(explode('.', $dotKey) as $segment){
41
+		foreach (explode('.', $dotKey) as $segment) {
42 42
 
43
-			if(!is_array($array) || !array_key_exists($segment, $array)){
43
+			if (!is_array($array) || !array_key_exists($segment, $array)) {
44 44
 				return $default;
45 45
 			}
46 46
 
@@ -59,19 +59,19 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function in(string $dotKey):bool{
61 61
 
62
-		if(empty($this->array)){
62
+		if (empty($this->array)) {
63 63
 			return false;
64 64
 		}
65 65
 
66
-		if(array_key_exists($dotKey, $this->array)){
66
+		if (array_key_exists($dotKey, $this->array)) {
67 67
 			return true;
68 68
 		}
69 69
 
70 70
 		$array = &$this->array;
71 71
 
72
-		foreach(explode('.', $dotKey) as $segment){
72
+		foreach (explode('.', $dotKey) as $segment) {
73 73
 
74
-			if(!is_array($array) || !array_key_exists($segment, $array)){
74
+			if (!is_array($array) || !array_key_exists($segment, $array)) {
75 75
 				return false;
76 76
 			}
77 77
 
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return \chillerlan\Traits\ArrayHelpers\DotArray
93 93
 	 */
94
-	public function set(string $dotKey, $value){
94
+	public function set(string $dotKey, $value) {
95 95
 
96
-		if(empty($dotKey)){
96
+		if (empty($dotKey)) {
97 97
 			$this->array = $value;
98 98
 
99 99
 			return $this;
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
 		$array = &$this->array;
103 103
 		$keys = explode('.', $dotKey);
104 104
 
105
-		while(count($keys) > 1){
105
+		while (count($keys) > 1) {
106 106
 			$dotKey = array_shift($keys);
107 107
 
108 108
 			// If the key doesn't exist at this depth, we will just create an empty array
109 109
 			// to hold the next value, allowing us to create the arrays to hold final
110 110
 			// values at the correct depth. Then we'll keep digging into the array.
111
-			if(!isset($array[$dotKey]) || !is_array($array[$dotKey])){
111
+			if (!isset($array[$dotKey]) || !is_array($array[$dotKey])) {
112 112
 				$array[$dotKey] = [];
113 113
 			}
114 114
 
Please login to merge, or discard this patch.
src/Env.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,8 +70,7 @@
 block discarded – undo
70 70
 
71 71
 			if(array_key_exists($var, $_ENV)){
72 72
 				$env = $_ENV[$var];
73
-			}
74
-			elseif(function_exists('getenv')){
73
+			} elseif(function_exists('getenv')){
75 74
 				$env = getenv($var);
76 75
 			}
77 76
 			// @codeCoverageIgnoreStart
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  * @link http://php.net/variables-order
22 22
  *
23 23
  */
24
-trait Env{
24
+trait Env {
25 25
 
26 26
 	/**
27 27
 	 * a backup environment in case everything goes downhill
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @return $this
49 49
 	 */
50
-	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null, bool $global = null){
50
+	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null, bool $global = null) {
51 51
 		$this->_global = $global ?? false;
52 52
 		$content       = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env'));
53 53
 
@@ -62,20 +62,20 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return bool|mixed
64 64
 	 */
65
-	protected function __getEnv(string $var){
65
+	protected function __getEnv(string $var) {
66 66
 		$var = strtoupper($var);
67 67
 		$env = null;
68 68
 
69
-		if($this->_global === true){
69
+		if ($this->_global === true) {
70 70
 
71
-			if(array_key_exists($var, $_ENV)){
71
+			if (array_key_exists($var, $_ENV)) {
72 72
 				$env = $_ENV[$var];
73 73
 			}
74
-			elseif(function_exists('getenv')){
74
+			elseif (function_exists('getenv')) {
75 75
 				$env = getenv($var);
76 76
 			}
77 77
 			// @codeCoverageIgnoreStart
78
-			elseif(function_exists('apache_getenv')){
78
+			elseif (function_exists('apache_getenv')) {
79 79
 				$env = apache_getenv($var);
80 80
 			}
81 81
 			// @codeCoverageIgnoreEnd
@@ -91,18 +91,18 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return $this
93 93
 	 */
94
-	protected function __setEnv(string $var, string $value = null){
94
+	protected function __setEnv(string $var, string $value = null) {
95 95
 		$var   = strtoupper($var);
96 96
 		$value = $this->__parse($value);
97 97
 
98
-		if($this->_global === true){
98
+		if ($this->_global === true) {
99 99
 			putenv($var.'='.$value);
100 100
 
101 101
 			// fill $_ENV explicitly, assuming variables_order="GPCS" (production)
102 102
 			$_ENV[$var] = $value;
103 103
 
104 104
 			// @codeCoverageIgnoreStart
105
-			if(function_exists('apache_setenv')){
105
+			if (function_exists('apache_setenv')) {
106 106
 				apache_setenv($var, $value);
107 107
 			}
108 108
 			// @codeCoverageIgnoreEnd
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @return $this
136 136
 	 */
137
-	protected function __unsetEnv(string $var){
137
+	protected function __unsetEnv(string $var) {
138 138
 		$var = strtoupper($var);
139 139
 
140
-		if($this->_global === true){
140
+		if ($this->_global === true) {
141 141
 			unset($_ENV[$var]);
142 142
 			putenv($var);
143 143
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @return $this
154 154
 	 */
155
-	protected function __clearEnv(){
155
+	protected function __clearEnv() {
156 156
 
157
-		if($this->_global === true){
157
+		if ($this->_global === true) {
158 158
 			$_ENV = [];
159 159
 		}
160 160
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 */
172 172
 	private function __read(string $file):array{
173 173
 
174
-		if(!is_readable($file) || !is_file($file)){
174
+		if (!is_readable($file) || !is_file($file)) {
175 175
 			throw new TraitException('invalid file: '.$file);
176 176
 		}
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
182 182
 		ini_set('auto_detect_line_endings', $autodetect);
183 183
 
184
-		if(!is_array($lines) || empty($lines)){
184
+		if (!is_array($lines) || empty($lines)) {
185 185
 			throw new TraitException('error while reading file: '.$file);
186 186
 		}
187 187
 
@@ -194,19 +194,19 @@  discard block
 block discarded – undo
194 194
 	 *
195 195
 	 * @return $this
196 196
 	 */
197
-	private function __load(array $data, bool $overwrite){
197
+	private function __load(array $data, bool $overwrite) {
198 198
 
199
-		foreach($data as $line){
199
+		foreach ($data as $line) {
200 200
 
201 201
 			// skip empty lines and comments
202
-			if(empty($line) || strpos($line, '#') === 0){
202
+			if (empty($line) || strpos($line, '#') === 0) {
203 203
 				continue;
204 204
 			}
205 205
 
206 206
 			$kv = array_map('trim', explode('=', $line, 2));
207 207
 
208 208
 			// skip empty and numeric keys, keys with spaces, existing keys that shall not be overwritten
209
-			if(empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)){
209
+			if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)) {
210 210
 				continue;
211 211
 			}
212 212
 
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @return string|null
223 223
 	 */
224
-	private function __parse(string $value = null){
224
+	private function __parse(string $value = null) {
225 225
 
226
-		if($value !== null){
226
+		if ($value !== null) {
227 227
 
228 228
 			$q = $value[0] ?? null;
229 229
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 			$value = implode(PHP_EOL, explode('\\n', $value));
238 238
 
239 239
 			// handle nested ${VARS}
240
-			if(strpos($value, '$') !== false){
241
-				$value = preg_replace_callback('/\${(?<var>[_a-z\d]+)}/i', function($matches){
240
+			if (strpos($value, '$') !== false) {
241
+				$value = preg_replace_callback('/\${(?<var>[_a-z\d]+)}/i', function($matches) {
242 242
 					return $this->__getEnv($matches['var']);
243 243
 				}, $value);
244 244
 			}
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
 	 * @return $this
255 255
 	 * @throws \chillerlan\Traits\TraitException
256 256
 	 */
257
-	private function __check(array $required = null){
257
+	private function __check(array $required = null) {
258 258
 
259
-		if($required === null || empty($required)){
259
+		if ($required === null || empty($required)) {
260 260
 			return $this;
261 261
 		}
262 262
 
263
-		foreach($required as $var){
264
-			if(!$this->__issetEnv($var)){
263
+		foreach ($required as $var) {
264
+			if (!$this->__issetEnv($var)) {
265 265
 				throw new TraitException('required variable not set: '.strtoupper($var));
266 266
 			}
267 267
 		}
Please login to merge, or discard this patch.