| @@ -5,7 +5,7 @@ discard block | ||
| 5 | 5 | * @author Austin Heap <[email protected]> | 
| 6 | 6 | * @version v0.4.0 | 
| 7 | 7 | */ | 
| 8 | -declare(strict_types=1); | |
| 8 | +declare(strict_types = 1); | |
| 9 | 9 | |
| 10 | 10 | namespace AustinHeap\Security\Txt; | 
| 11 | 11 | |
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 | * | 
| 48 | 48 | * @var array | 
| 49 | 49 | */ | 
| 50 | - protected $logEntries = []; | |
| 50 | + protected $logEntries = [ ]; | |
| 51 | 51 | |
| 52 | 52 | /** | 
| 53 | 53 | * Enable built-in cache. | 
| @@ -90,16 +90,16 @@ discard block | ||
| 90 | 90 | public static function buildWriterDefaultKeys() | 
| 91 | 91 |      { | 
| 92 | 92 | return [ | 
| 93 | - 'security-txt.enabled' => ['validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true], | |
| 94 | - 'security-txt.debug' => ['validator' => 'is_bool', 'setter' => 'setDebug'], | |
| 95 | - 'security-txt.cache' => ['validator' => 'is_bool', 'setter' => 'setCache', 'self' => true], | |
| 96 | - 'security-txt.cache-time' => ['validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true], | |
| 97 | - 'security-txt.cache-key' => ['validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true], | |
| 98 | - 'security-txt.comments' => ['validator' => 'is_bool', 'setter' => 'setComments'], | |
| 99 | - 'security-txt.contacts' => ['validator' => 'is_array', 'setter' => 'addContacts'], | |
| 100 | - 'security-txt.encryption' => ['validator' => 'is_string', 'setter' => 'setEncryption'], | |
| 101 | - 'security-txt.disclosure' => ['validator' => 'is_string', 'setter' => 'setDisclosure'], | |
| 102 | - 'security-txt.acknowledgement' => ['validator' => 'is_string', 'setter' => 'setAcknowledgement'], | |
| 93 | + 'security-txt.enabled' => [ 'validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true ], | |
| 94 | + 'security-txt.debug' => [ 'validator' => 'is_bool', 'setter' => 'setDebug' ], | |
| 95 | + 'security-txt.cache' => [ 'validator' => 'is_bool', 'setter' => 'setCache', 'self' => true ], | |
| 96 | + 'security-txt.cache-time' => [ 'validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true ], | |
| 97 | + 'security-txt.cache-key' => [ 'validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true ], | |
| 98 | + 'security-txt.comments' => [ 'validator' => 'is_bool', 'setter' => 'setComments' ], | |
| 99 | + 'security-txt.contacts' => [ 'validator' => 'is_array', 'setter' => 'addContacts' ], | |
| 100 | + 'security-txt.encryption' => [ 'validator' => 'is_string', 'setter' => 'setEncryption' ], | |
| 101 | + 'security-txt.disclosure' => [ 'validator' => 'is_string', 'setter' => 'setDisclosure' ], | |
| 102 | + 'security-txt.acknowledgement' => [ 'validator' => 'is_string', 'setter' => 'setAcknowledgement' ], | |
| 103 | 103 | ]; | 
| 104 | 104 | } | 
| 105 | 105 | |
| @@ -118,28 +118,28 @@ discard block | ||
| 118 | 118 | |
| 119 | 119 |          foreach ($keys as $key => $mapping) { | 
| 120 | 120 |              if (is_null(config($key, null))) { | 
| 121 | -                $this->addLogEntry('"'.__CLASS__.'" cannot process null value for key "'.$key.'".', 'debug'); | |
| 121 | +                $this->addLogEntry('"' . __CLASS__ . '" cannot process null value for key "' . $key . '".', 'debug'); | |
| 122 | 122 | continue; | 
| 123 | -            } elseif (! function_exists($mapping['validator'])) { | |
| 124 | -                $this->addLogEntry('"'.__CLASS__.'" cannot find "validator" function named "'.$mapping['validator'].'".', 'warning'); | |
| 123 | +            } elseif (!function_exists($mapping[ 'validator' ])) { | |
| 124 | +                $this->addLogEntry('"' . __CLASS__ . '" cannot find "validator" function named "' . $mapping[ 'validator' ] . '".', 'warning'); | |
| 125 | 125 | continue; | 
| 126 | -            } elseif (! $mapping['validator'](config($key))) { | |
| 127 | -                $this->addLogEntry('"'.__CLASS__.'" failed the "validator" function named "'.$mapping['validator'].'".', 'warning'); | |
| 126 | +            } elseif (!$mapping[ 'validator' ](config($key))) { | |
| 127 | +                $this->addLogEntry('"' . __CLASS__ . '" failed the "validator" function named "' . $mapping[ 'validator' ] . '".', 'warning'); | |
| 128 | 128 | continue; | 
| 129 | -            } elseif (array_key_exists('self', $mapping) && is_bool($mapping['self']) && $mapping['self'] === true) { | |
| 130 | -                if (! method_exists($this, $mapping['setter'])) { | |
| 131 | -                    $this->addLogEntry('"'.__CLASS__.'" cannot find mapping "setter" method on object "'.get_class($this).'" named "'.$mapping['setter'].'".', 'error'); | |
| 129 | +            } elseif (array_key_exists('self', $mapping) && is_bool($mapping[ 'self' ]) && $mapping[ 'self' ] === true) { | |
| 130 | +                if (!method_exists($this, $mapping[ 'setter' ])) { | |
| 131 | +                    $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); | |
| 132 | 132 | continue; | 
| 133 | 133 | } | 
| 134 | 134 | |
| 135 | -                $this->{$mapping['setter']}(config($key)); | |
| 135 | +                $this->{$mapping[ 'setter' ]}(config($key)); | |
| 136 | 136 |              } else { | 
| 137 | -                if (! method_exists($this->writer, $mapping['setter'])) { | |
| 138 | -                    $this->addLogEntry('"'.__CLASS__.'" cannot find mapping "setter" method on object "'.get_class($this->writer).'" named "'.$mapping['setter'].'".', 'error'); | |
| 137 | +                if (!method_exists($this->writer, $mapping[ 'setter' ])) { | |
| 138 | +                    $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this->writer) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); | |
| 139 | 139 | continue; | 
| 140 | 140 | } | 
| 141 | 141 | |
| 142 | -                $this->writer->{$mapping['setter']}(config($key)); | |
| 142 | +                $this->writer->{$mapping[ 'setter' ]}(config($key)); | |
| 143 | 143 | } | 
| 144 | 144 | } | 
| 145 | 145 | |
| @@ -158,7 +158,7 @@ discard block | ||
| 158 | 158 |      { | 
| 159 | 159 | Log::$level($text); | 
| 160 | 160 | |
| 161 | - $this->logEntries[] = ['text' => $text, 'level' => $level]; | |
| 161 | + $this->logEntries[ ] = [ 'text' => $text, 'level' => $level ]; | |
| 162 | 162 | |
| 163 | 163 | return $this; | 
| 164 | 164 | } | 
| @@ -180,7 +180,7 @@ discard block | ||
| 180 | 180 | */ | 
| 181 | 181 | public function clearLogEntries(): self | 
| 182 | 182 |      { | 
| 183 | - $this->logEntries = []; | |
| 183 | + $this->logEntries = [ ]; | |
| 184 | 184 | |
| 185 | 185 | return $this; | 
| 186 | 186 | } | 
| @@ -195,7 +195,7 @@ discard block | ||
| 195 | 195 |          if ($this->cache) { | 
| 196 | 196 | $text = cache($this->cacheKey, null); | 
| 197 | 197 | |
| 198 | -            if (! is_null($text)) { | |
| 198 | +            if (!is_null($text)) { | |
| 199 | 199 | return $text; | 
| 200 | 200 | } | 
| 201 | 201 | } | 
| @@ -205,12 +205,12 @@ discard block | ||
| 205 | 205 | ->getText(); | 
| 206 | 206 | |
| 207 | 207 |          if ($this->writer->getDebug()) { | 
| 208 | - $text .= '# Cache is '.($this->cache ? 'enabled with key "'.$this->cacheKey.'"' : 'disabled').'.'.PHP_EOL. | |
| 209 | - '#'.PHP_EOL; | |
| 208 | + $text .= '# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . | |
| 209 | + '#' . PHP_EOL; | |
| 210 | 210 | } | 
| 211 | 211 | |
| 212 | 212 |          if ($this->cache) { | 
| 213 | - cache([$this->cacheKey => $text], now()->addMinutes($this->cacheTime)); | |
| 213 | + cache([ $this->cacheKey => $text ], now()->addMinutes($this->cacheTime)); | |
| 214 | 214 | } | 
| 215 | 215 | |
| 216 | 216 | return empty($text) ? '' : $text; | 
| @@ -371,7 +371,7 @@ discard block | ||
| 371 | 371 | */ | 
| 372 | 372 | public function hasWriter(): bool | 
| 373 | 373 |      { | 
| 374 | - return ! is_null($this->writer); | |
| 374 | + return !is_null($this->writer); | |
| 375 | 375 | } | 
| 376 | 376 | |
| 377 | 377 | /** | 
| @@ -381,7 +381,7 @@ discard block | ||
| 381 | 381 | */ | 
| 382 | 382 | public function getWriter(): Writer | 
| 383 | 383 |      { | 
| 384 | -        if (! $this->hasWriter()) { | |
| 384 | +        if (!$this->hasWriter()) { | |
| 385 | 385 |              throw new Exception('Writer not set.'); | 
| 386 | 386 | } | 
| 387 | 387 | |