| Conditions | 20 |
| Paths | 432 |
| Total Lines | 55 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 124 | public function generate(): Writer |
||
| 125 | { |
||
| 126 | if ($this->debug) |
||
| 127 | $time = microtime(true); |
||
| 128 | |||
| 129 | if ($this->comments) |
||
| 130 | $this->comment('Our security address'); |
||
| 131 | |||
| 132 | if (empty($this->contacts)) |
||
| 133 | throw new \Exception('One (or more) contacts must be defined.'); |
||
| 134 | |||
| 135 | foreach ($this->contacts as $contact) |
||
| 136 | $this->line('Contact: ' . trim($contact)); |
||
| 137 | |||
| 138 | if (!empty($this->encryption)) { |
||
| 139 | if ($this->comments) |
||
| 140 | $this->spacer() |
||
| 141 | ->comment('Our PGP key'); |
||
| 142 | |||
| 143 | $this->line('Encryption: ' . trim($this->encryption)); |
||
| 144 | } |
||
| 145 | |||
| 146 | if (!empty($this->disclosure)) { |
||
| 147 | if ($this->comments) |
||
| 148 | $this->spacer() |
||
| 149 | ->comment('Our disclosure policy'); |
||
| 150 | |||
| 151 | $this->line('Disclosure: ' . trim(ucfirst($this->disclosure))); |
||
| 152 | } |
||
| 153 | |||
| 154 | if (!empty($this->acknowledgement)) { |
||
| 155 | if ($this->comments) |
||
| 156 | $this->spacer() |
||
| 157 | ->comment('Our public acknowledgement'); |
||
| 158 | |||
| 159 | $this->line('Acknowledgement: ' . trim($this->acknowledgement)); |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($this->debug) |
||
| 163 | $this->spacer() |
||
| 164 | ->comment() |
||
| 165 | ->comment( |
||
| 166 | 'Generated by "' . (defined('LARAVEL_SECURITY_TXT_VERSION') ? 'laravel' : 'php') . '-security-txt"' . |
||
| 167 | (defined('LARAVEL_SECURITY_TXT_VERSION') ? ' v' . LARAVEL_SECURITY_TXT_VERSION : (defined('PHP_SECURITY_TXT_VERSION') ? ' v' . PHP_SECURITY_TXT_VERSION : '')) . |
||
|
|
|||
| 168 | ' (https://github.com/austinheap/' . (defined('LARAVEL_SECURITY_TXT_VERSION') ? 'laravel' : 'php') . '-security-txt' . (defined('LARAVEL_SECURITY_TXT_VERSION') ? '/releases/tag/v' . LARAVEL_SECURITY_TXT_VERSION : (defined('PHP_SECURITY_TXT_VERSION') ? '/releases/tag/v' . PHP_SECURITY_TXT_VERSION : '')) . ')') |
||
| 169 | ->comment( |
||
| 170 | 'using "php-security-txt"' . (defined('PHP_SECURITY_TXT_VERSION') ? ' v' . PHP_SECURITY_TXT_VERSION : '') . |
||
| 171 | ' (https://github.com/austinheap/php-security-txt' . (defined('PHP_SECURITY_TXT_VERSION') ? '/releases/tag/v' . PHP_SECURITY_TXT_VERSION : '') . ')') |
||
| 172 | ->comment('in ' . round((microtime(true) - $time) * 1000, 6) . ' seconds on ' . now() . '.') |
||
| 173 | ->comment() |
||
| 174 | ->spacer(); |
||
| 175 | |||
| 176 | $output = implode(PHP_EOL, $this->lines); |
||
| 177 | |||
| 178 | return $this->setText($output); |
||
| 179 | } |
||
| 182 |