Passed
Push — master ( 849c31...8f1d2b )
by smiley
01:37
created
src/Env.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  *
20 20
  * @link https://github.com/vlucas/phpdotenv
21 21
  */
22
-trait Env{
22
+trait Env {
23 23
 
24 24
 	/**
25 25
 	 * a backup environment in case everything goes downhill
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @return $this
38 38
 	 */
39
-	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null){
39
+	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null) {
40 40
 		$overwrite = $overwrite !== null ? $overwrite : false;
41 41
 		$content   = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env'));
42 42
 
@@ -51,20 +51,20 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return bool|mixed
53 53
 	 */
54
-	protected function __getEnv(string $var){
54
+	protected function __getEnv(string $var) {
55 55
 		$var = strtoupper($var);
56 56
 
57
-		if(array_key_exists($var, $_ENV)){
57
+		if (array_key_exists($var, $_ENV)) {
58 58
 			return $_ENV[$var];
59 59
 		}
60
-		elseif(function_exists('getenv')){
61
-			if($e = getenv($var) !== false){
60
+		elseif (function_exists('getenv')) {
61
+			if ($e = getenv($var) !== false) {
62 62
 				return $e;
63 63
 			}
64 64
 		}
65 65
 		// @codeCoverageIgnoreStart
66
-		elseif(function_exists('apache_getenv')){
67
-			if($e = apache_getenv($var) !== false){
66
+		elseif (function_exists('apache_getenv')) {
67
+			if ($e = apache_getenv($var) !== false) {
68 68
 				return $e;
69 69
 			}
70 70
 		}
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @return $this
81 81
 	 */
82
-	protected function __setEnv(string $var, string $value = null){
82
+	protected function __setEnv(string $var, string $value = null) {
83 83
 		$var   = strtoupper($var);
84 84
 		$value = $this->__parse($value);
85 85
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		// a backup
91 91
 		$this->_ENV[$var] = $value;
92 92
 
93
-		if(function_exists('apache_setenv')){
93
+		if (function_exists('apache_setenv')) {
94 94
 			apache_setenv($var, $value);
95 95
 		}
96 96
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @return $this
104 104
 	 */
105
-	protected function __unsetEnv(string $var){
105
+	protected function __unsetEnv(string $var) {
106 106
 		$var = strtoupper($var);
107 107
 
108 108
 		unset($_ENV[$var]);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return $this
119 119
 	 */
120
-	protected function __clearEnv(){
120
+	protected function __clearEnv() {
121 121
 		$_ENV       = [];
122 122
 		$this->_ENV = [];
123 123
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	private function __read(string $file):array{
134 134
 
135
-		if(!is_readable($file) || !is_file($file)){
135
+		if (!is_readable($file) || !is_file($file)) {
136 136
 			throw new TraitException('invalid file: '.$file);
137 137
 		}
138 138
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
143 143
 		ini_set('auto_detect_line_endings', $autodetect);
144 144
 
145
-		if(!is_array($lines) || empty($lines)){
145
+		if (!is_array($lines) || empty($lines)) {
146 146
 			throw new TraitException('error while reading file: '.$file);
147 147
 		}
148 148
 
@@ -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 && array_key_exists($kv[0], $_ENV))){
172
+			if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && array_key_exists($kv[0], $_ENV))) {
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) || $this->__getEnv($var) === null){
226
+		foreach ($required as $var) {
227
+			if (!$this->__getEnv($var) || $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.
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.