Passed
Push — master ( 06fadb...21c0e7 )
by Thomas
04:14 queued 01:30
created

LeftAndMain_HTTPResponse::cloneFrom()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace LeKoala\Admini;
4
5
use SilverStripe\Control\HTTPResponse;
6
7
/**
8
 * Allow overriding finished state for faux redirects.
9
 */
10
class LeftAndMain_HTTPResponse extends HTTPResponse
11
{
12
13
    protected $isFinished = false;
14
15
    public function isFinished()
16
    {
17
        return (parent::isFinished() || $this->isFinished);
18
    }
19
20
    public function setIsFinished($bool)
21
    {
22
        $this->isFinished = $bool;
23
    }
24
25
    public static function cloneFrom(HTTPResponse $response): LeftAndMain_HTTPResponse
26
    {
27
        $newResponse = new LeftAndMain_HTTPResponse(
28
            $response->getBody(),
29
            $response->getStatusCode(),
30
            $response->getStatusDescription()
31
        );
32
        foreach ($response->getHeaders() as $k => $v) {
33
            $newResponse->addHeader($k, $v);
34
        }
35
        foreach ($response->getHeaders() as $k => $v) {
36
            $newResponse->addHeader($k, $v);
37
        }
38
        return $newResponse;
39
    }
40
}
41