Passed
Push — master ( 795c19...52755b )
by smiley
01:38
created
src/Env.php 1 patch
Spacing   +25 added lines, -25 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
 	 * @param string      $path
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return $this
31 31
 	 */
32
-	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null){
32
+	protected function __loadEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null) {
33 33
 		$overwrite = $overwrite !== null ? $overwrite : false;
34 34
 		$content   = $this->__read(rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.($filename ?? '.env'));
35 35
 
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return bool|mixed
46 46
 	 */
47
-	protected function __getEnv(string $var){
47
+	protected function __getEnv(string $var) {
48 48
 		$var = strtoupper($var);
49 49
 
50
-		if(array_key_exists($var, $_ENV)){
50
+		if (array_key_exists($var, $_ENV)) {
51 51
 			return $_ENV[$var];
52 52
 		}
53 53
 
54 54
 		$val = getenv($var);
55 55
 
56
-		if($val !== false){
56
+		if ($val !== false) {
57 57
 			return $val;
58 58
 		}
59 59
 
60
-		if(function_exists('apache_getenv')){
60
+		if (function_exists('apache_getenv')) {
61 61
 			$val = apache_getenv($var);
62 62
 
63
-			if($val !== false){
63
+			if ($val !== false) {
64 64
 				return $val;
65 65
  			}
66 66
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return $this
77 77
 	 */
78
-	protected function __setEnv(string $var, string $value = null){
78
+	protected function __setEnv(string $var, string $value = null) {
79 79
 		$var   = strtoupper($var);
80 80
 		$value = $this->__parse($value);
81 81
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		$_ENV[$var] = $value;
84 84
 		putenv($var.'='.$value);
85 85
 
86
-		if(function_exists('apache_setenv')){
86
+		if (function_exists('apache_setenv')) {
87 87
 			apache_setenv($var, $value);
88 88
 		}
89 89
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 *
96 96
 	 * @return $this
97 97
 	 */
98
-	protected function __unsetEnv(string $var){
98
+	protected function __unsetEnv(string $var) {
99 99
 		$var = strtoupper($var);
100 100
 
101 101
 		unset($_ENV[$var]);
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return $this
111 111
 	 */
112
-	protected function __clearEnv(){
112
+	protected function __clearEnv() {
113 113
 		$_ENV = [];
114 114
 
115 115
 		return $this;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 */
124 124
 	private function __read(string $file):array{
125 125
 
126
-		if(!is_readable($file) || !is_file($file)){
126
+		if (!is_readable($file) || !is_file($file)) {
127 127
 			throw new TraitException('invalid file: '.$file);
128 128
 		}
129 129
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
134 134
 		ini_set('auto_detect_line_endings', $autodetect);
135 135
 
136
-		if(!is_array($lines) || empty($lines)){
136
+		if (!is_array($lines) || empty($lines)) {
137 137
 			throw new TraitException('error while reading file: '.$file);
138 138
 		}
139 139
 
@@ -148,19 +148,19 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return $this
150 150
 	 */
151
-	private function __load(array $data, bool $overwrite){
151
+	private function __load(array $data, bool $overwrite) {
152 152
 
153
-		foreach($data as $line){
153
+		foreach ($data as $line) {
154 154
 
155 155
 			// skip empty lines and comments
156
-			if(empty($line) || strpos($line, '#') === 0){
156
+			if (empty($line) || strpos($line, '#') === 0) {
157 157
 				continue;
158 158
 			}
159 159
 
160 160
 			$kv = array_map('trim', explode('=', $line, 2));
161 161
 
162 162
 			// skip empty and numeric keys, keys with spaces, existing keys that shall not be overwritten
163
-			if(empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && array_key_exists($kv[0], $_ENV))){
163
+			if (empty($kv[0]) || is_numeric($kv[0]) || strpos($kv[0], ' ') !== false || (!$overwrite && array_key_exists($kv[0], $_ENV))) {
164 164
 				continue;
165 165
 			}
166 166
 
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 	 *
176 176
 	 * @return string|null
177 177
 	 */
178
-	private function __parse(string $value = null){
178
+	private function __parse(string $value = null) {
179 179
 
180
-		if($value !== null){
180
+		if ($value !== null) {
181 181
 
182 182
 			$q = $value[0] ?? null;
183 183
 
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 			$value = implode(PHP_EOL, explode('\\n', $value));
192 192
 
193 193
 			// handle nested ${VARS}
194
-			if(strpos($value, '$') !== false){
195
-				$value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches){
194
+			if (strpos($value, '$') !== false) {
195
+				$value = preg_replace_callback('/\${([_a-z\d]+)}/i', function($matches) {
196 196
 					return $this->__getEnv($matches[1]);
197 197
 				}, $value);
198 198
 			}
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 	 * @return $this
209 209
 	 * @throws \chillerlan\Traits\TraitException
210 210
 	 */
211
-	private function __check(array $required = null){
211
+	private function __check(array $required = null) {
212 212
 
213
-		if($required === null || empty($required)){
213
+		if ($required === null || empty($required)) {
214 214
 			return $this;
215 215
 		}
216 216
 
217
-		foreach($required as $var){
218
-			if(!$this->__getEnv($var) || $this->__getEnv($var) === null){
217
+		foreach ($required as $var) {
218
+			if (!$this->__getEnv($var) || $this->__getEnv($var) === null) {
219 219
 				throw new TraitException('required variable not set: '.strtoupper($var));
220 220
 			}
221 221
 		}
Please login to merge, or discard this patch.