Conditions | 4 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public static function fromResponse(Response $response): self |
||
14 | { |
||
15 | $certificate = ''; |
||
16 | $fullchain = ''; |
||
17 | |||
18 | if (preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $response->getBody(), $matches)) { |
||
19 | $certificate = $matches[0][0]; |
||
20 | |||
21 | if (count($matches[0]) > 1) { |
||
22 | $fullchain = $matches[0][0] . "\n"; |
||
23 | |||
24 | for ($i = 1; $i < count($matches[0]); $i++) { |
||
|
|||
25 | $fullchain .= $matches[0][$i] . "\n"; |
||
26 | } |
||
27 | } |
||
28 | } |
||
29 | |||
30 | return new self(compact('certificate', 'fullchain')); |
||
31 | } |
||
33 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: