Conditions | 5 |
Paths | 4 |
Total Lines | 36 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
24 | public function __invoke(\Elgg\Request $request): ResponseBuilder { |
||
25 | $contact = elgg_get_config('security_txt_contact'); |
||
26 | $expires = elgg_get_config('security_txt_expires'); |
||
27 | if (empty($contact) || empty($expires)) { |
||
28 | throw new EntityNotFoundException(); |
||
29 | } |
||
30 | |||
31 | $lines = [ |
||
32 | "Contact: {$contact}", |
||
33 | 'Expires: ' . Values::normalizeTime($expires)->format(DATE_ATOM), |
||
34 | ]; |
||
35 | |||
36 | $fields = [ |
||
37 | 'encryption' => 'Encryption', |
||
38 | 'acknowledgments' => 'Acknowledgments', |
||
39 | 'language' => 'Preferred-Languages', |
||
40 | 'canonical' => 'Canonical', |
||
41 | 'policy' => 'Policy', |
||
42 | 'hiring' => 'Hiring', |
||
43 | 'csaf' => 'CSAF', |
||
44 | ]; |
||
45 | foreach ($fields as $name => $output) { |
||
46 | $value = elgg_get_config("security_txt_{$name}"); |
||
47 | if (empty($value)) { |
||
48 | continue; |
||
49 | } |
||
50 | |||
51 | $lines[] = "{$output}: {$value}"; |
||
52 | } |
||
53 | |||
54 | $response = elgg_ok_response(implode(PHP_EOL, $lines)); |
||
55 | $response->setHeaders([ |
||
56 | 'Content-Type' => 'text/plain; charset=utf-8', |
||
57 | ]); |
||
58 | |||
59 | return $response; |
||
60 | } |
||
62 |