Completed
Push — master ( 8f1d2b...706484 )
by smiley
01:35
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/ClassLoader.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,8 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 				if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){
52 52
 					trigger_error($class.' does not implement '.$type);
53
-				}
54
-				elseif(!$reflectionClass->isSubclassOf($type)) {
53
+				} elseif(!$reflectionClass->isSubclassOf($type)) {
55 54
 					trigger_error($class.' does not inherit '.$type);
56 55
 				}
57 56
 
@@ -64,8 +63,7 @@  discard block
 block discarded – undo
64 63
 			}
65 64
 
66 65
 			return $object;
67
-		}
68
-		catch(Exception $e){
66
+		} catch(Exception $e){
69 67
 			throw new TraitException('ClassLoader: '.$e->getMessage());
70 68
 		}
71 69
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 use Exception, ReflectionClass;
16 16
 
17
-trait ClassLoader{
17
+trait ClassLoader {
18 18
 
19 19
 	/**
20 20
 	 * Instances an object of $class/$type with an arbitrary number of $params
@@ -27,31 +27,31 @@  discard block
 block discarded – undo
27 27
 	 * @return mixed of type $type
28 28
 	 * @throws \Exception
29 29
 	 */
30
-	public function loadClass(string $class, string $type = null, ...$params){
30
+	public function loadClass(string $class, string $type = null, ...$params) {
31 31
 		$type = $type === null ? $class : $type;
32 32
 
33
-		try{
33
+		try {
34 34
 			$reflectionClass = new ReflectionClass($class);
35 35
 			$reflectionType  = new ReflectionClass($type);
36 36
 
37
-			if($reflectionType->isTrait()){
37
+			if ($reflectionType->isTrait()) {
38 38
 				trigger_error($class.' cannot be an instance of trait '.$type);
39 39
 			}
40 40
 
41
-			if($reflectionClass->isAbstract()){
41
+			if ($reflectionClass->isAbstract()) {
42 42
 				trigger_error('cannot instance abstract class '.$class);
43 43
 			}
44 44
 
45
-			if($reflectionClass->isTrait()){
45
+			if ($reflectionClass->isTrait()) {
46 46
 				trigger_error('cannot instance trait '.$class);
47 47
 			}
48 48
 
49
-			if($class !== $type){
49
+			if ($class !== $type) {
50 50
 
51
-				if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){
51
+				if ($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)) {
52 52
 					trigger_error($class.' does not implement '.$type);
53 53
 				}
54
-				elseif(!$reflectionClass->isSubclassOf($type)) {
54
+				elseif (!$reflectionClass->isSubclassOf($type)) {
55 55
 					trigger_error($class.' does not inherit '.$type);
56 56
 				}
57 57
 
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 
60 60
 			$object = $reflectionClass->newInstanceArgs($params);
61 61
 
62
-			if(!$object instanceof $type){
62
+			if (!$object instanceof $type) {
63 63
 				trigger_error('how did u even get here?'); // @codeCoverageIgnore
64 64
 			}
65 65
 
66 66
 			return $object;
67 67
 		}
68
-		catch(Exception $e){
68
+		catch (Exception $e) {
69 69
 			throw new TraitException('ClassLoader: '.$e->getMessage());
70 70
 		}
71 71
 
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/Container.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * a generic container with magic getter and setter
17 17
  */
18
-trait Container{
18
+trait Container {
19 19
 
20 20
 	/**
21 21
 	 * @param array $properties
22 22
 	 */
23
-	public function __construct(array $properties = []){
23
+	public function __construct(array $properties = []) {
24 24
 
25
-		foreach($properties as $key => $value){
25
+		foreach ($properties as $key => $value) {
26 26
 			$this->__set($key, $value);
27 27
 		}
28 28
 
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @return mixed
35 35
 	 */
36
-	public function __get(string $property){
36
+	public function __get(string $property) {
37 37
 
38
-		if(property_exists($this, $property)){
38
+		if (property_exists($this, $property)) {
39 39
 			return $this->{$property};
40 40
 		}
41 41
 
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	 *
49 49
 	 * @return void
50 50
 	 */
51
-	public function __set(string $property, $value){
51
+	public function __set(string $property, $value) {
52 52
 
53
-		if(property_exists($this, $property)){
53
+		if (property_exists($this, $property)) {
54 54
 			$this->{$property} = $value;
55 55
 		}
56 56
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	public function __toArray():array {
63 63
 		$data = [];
64 64
 
65
-		foreach($this as $key => $value){
65
+		foreach ($this as $key => $value) {
66 66
 			$data[$key] = $value;
67 67
 		}
68 68
 
Please login to merge, or discard this patch.
src/Enumerable.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * @link http://api.prototypejs.org/language/Enumerable/
17 17
  */
18
-trait Enumerable{
18
+trait Enumerable {
19 19
 
20 20
 	/**
21 21
 	 * @var array
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return $this
47 47
 	 */
48
-	public function __each($callback){
48
+	public function __each($callback) {
49 49
 		$this->__map($callback);
50 50
 
51 51
 		return $this;
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function __map($callback):array {
64 64
 
65
-		if(!is_callable($callback)){
65
+		if (!is_callable($callback)) {
66 66
 			throw new TraitException('invalid callback');
67 67
 		}
68 68
 
69 69
 		$return = [];
70 70
 
71
-		foreach($this->array as $index => $element){
71
+		foreach ($this->array as $index => $element) {
72 72
 			$return[$index] = call_user_func_array($callback, [$element, $index]);
73 73
 		}
74 74
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return $this
82 82
 	 */
83
-	public function __reverse(){
83
+	public function __reverse() {
84 84
 		$this->array = array_reverse($this->array);
85 85
 		$this->offset = 0;
86 86
 
Please login to merge, or discard this patch.
src/DotEnv.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\Traits;
14 14
 
15
-class DotEnv{
15
+class DotEnv {
16 16
 	use Env;
17 17
 
18 18
 	/**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param string      $path
32 32
 	 * @param string|null $filename
33 33
 	 */
34
-	public function __construct(string $path, string $filename = null){
34
+	public function __construct(string $path, string $filename = null) {
35 35
 		$this->path     = $path;
36 36
 		$this->filename = $filename;
37 37
 	}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return bool|mixed
64 64
 	 */
65
-	public function get(string $var){
65
+	public function get(string $var) {
66 66
 		return $this->__getEnv($var);
67 67
 	}
68 68
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @return $this
74 74
 	 */
75
-	public function set(string $var, string $value){
75
+	public function set(string $var, string $value) {
76 76
 		return $this->__setEnv($var, $value);
77 77
 	}
78 78
 
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
@@ -56,8 +56,7 @@
 block discarded – undo
56 56
 
57 57
 		if(array_key_exists($var, $_ENV)){
58 58
 			return $_ENV[$var];
59
-		}
60
-		elseif(function_exists('getenv')){
59
+		} elseif(function_exists('getenv')){
61 60
 			if($e = getenv($var) !== false){
62 61
 				return $e;
63 62
 			}
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 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
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return $this
40 40
 	 */
41
-	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null){
41
+	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null) {
42 42
 		$overwrite = $overwrite !== null ? $overwrite : false;
43 43
 		$content   = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env'));
44 44
 
@@ -53,20 +53,20 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return bool|mixed
55 55
 	 */
56
-	protected function __getEnv(string $var){
56
+	protected function __getEnv(string $var) {
57 57
 		$var = strtoupper($var);
58 58
 
59
-		if(array_key_exists($var, $_ENV)){
59
+		if (array_key_exists($var, $_ENV)) {
60 60
 			return $_ENV[$var];
61 61
 		}
62
-		elseif(function_exists('getenv')){
63
-			if($e = getenv($var) !== false){
62
+		elseif (function_exists('getenv')) {
63
+			if ($e = getenv($var) !== false) {
64 64
 				return $e;
65 65
 			}
66 66
 		}
67 67
 		// @codeCoverageIgnoreStart
68
-		elseif(function_exists('apache_getenv')){
69
-			if($e = apache_getenv($var) !== false){
68
+		elseif (function_exists('apache_getenv')) {
69
+			if ($e = apache_getenv($var) !== false) {
70 70
 				return $e;
71 71
 			}
72 72
 		}
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 *
82 82
 	 * @return $this
83 83
 	 */
84
-	protected function __setEnv(string $var, string $value = null){
84
+	protected function __setEnv(string $var, string $value = null) {
85 85
 		$var   = strtoupper($var);
86 86
 		$value = $this->__parse($value);
87 87
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 		// a backup
93 93
 		$this->_ENV[$var] = $value;
94 94
 
95
-		if(function_exists('apache_setenv')){
95
+		if (function_exists('apache_setenv')) {
96 96
 			apache_setenv($var, $value);
97 97
 		}
98 98
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return $this
106 106
 	 */
107
-	protected function __unsetEnv(string $var){
107
+	protected function __unsetEnv(string $var) {
108 108
 		$var = strtoupper($var);
109 109
 
110 110
 		unset($_ENV[$var]);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return $this
121 121
 	 */
122
-	protected function __clearEnv(){
122
+	protected function __clearEnv() {
123 123
 		$_ENV       = [];
124 124
 		$this->_ENV = [];
125 125
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	private function __read(string $file):array{
136 136
 
137
-		if(!is_readable($file) || !is_file($file)){
137
+		if (!is_readable($file) || !is_file($file)) {
138 138
 			throw new TraitException('invalid file: '.$file);
139 139
 		}
140 140
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
145 145
 		ini_set('auto_detect_line_endings', $autodetect);
146 146
 
147
-		if(!is_array($lines) || empty($lines)){
147
+		if (!is_array($lines) || empty($lines)) {
148 148
 			throw new TraitException('error while reading file: '.$file);
149 149
 		}
150 150
 
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @return $this
159 159
 	 */
160
-	private function __load(array $data, bool $overwrite){
160
+	private function __load(array $data, bool $overwrite) {
161 161
 
162
-		foreach($data as $line){
162
+		foreach ($data as $line) {
163 163
 
164 164
 			// skip empty lines and comments
165
-			if(empty($line) || strpos($line, '#') === 0){
165
+			if (empty($line) || strpos($line, '#') === 0) {
166 166
 				continue;
167 167
 			}
168 168
 
169 169
 			$kv = array_map('trim', explode('=', $line, 2));
170 170
 
171 171
 			// skip empty and numeric keys, keys with spaces, existing keys that shall not be overwritten
172
-			if(empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)){
172
+			if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && $this->__getEnv($kv[0]) !== false)) {
173 173
 				continue;
174 174
 			}
175 175
 
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return string|null
186 186
 	 */
187
-	private function __parse(string $value = null){
187
+	private function __parse(string $value = null) {
188 188
 
189
-		if($value !== null){
189
+		if ($value !== null) {
190 190
 
191 191
 			$q = $value[0] ?? null;
192 192
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 			$value = implode(PHP_EOL, explode('\\n', $value));
201 201
 
202 202
 			// handle nested ${VARS}
203
-			if(strpos($value, '$') !== false){
204
-				$value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches){
203
+			if (strpos($value, '$') !== false) {
204
+				$value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches) {
205 205
 					return $this->__getEnv($matches[1]);
206 206
 				}, $value);
207 207
 			}
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
 	 * @return $this
218 218
 	 * @throws \chillerlan\Traits\TraitException
219 219
 	 */
220
-	private function __check(array $required = null){
220
+	private function __check(array $required = null) {
221 221
 
222
-		if($required === null || empty($required)){
222
+		if ($required === null || empty($required)) {
223 223
 			return $this;
224 224
 		}
225 225
 
226
-		foreach($required as $var){
227
-			if($this->__getEnv($var) === false || $this->__getEnv($var) === null){
226
+		foreach ($required as $var) {
227
+			if ($this->__getEnv($var) === false || $this->__getEnv($var) === null) {
228 228
 				throw new TraitException('required variable not set: '.strtoupper($var));
229 229
 			}
230 230
 		}
Please login to merge, or discard this patch.