Status301   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 34
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A consolidate() 0 29 3
1
<?php namespace Comodojo\Dispatcher\Response\Preprocessor;
2
3
use \Comodojo\Dispatcher\Response\Model as Response;
4
use \Exception;
5
6
/**
7
 * Status: Moved Permanently
8
 *
9
 * @package     Comodojo Dispatcher
10
 * @author      Marco Giovinazzi <[email protected]>
11
 * @license     MIT
12
 *
13
 * LICENSE:
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
class Status301 extends Status200 {
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function consolidate(Response $response) {
30
31
        $location = $response->getLocation()->get();
32
33
        if (empty($location)) {
34
            throw new Exception("Invalid location, cannot redirect");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Invalid location, cannot redirect does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
35
        }
36
37
        $response->getHeaders()->set("Location", $location);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Location does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
38
39
        $content = $response->getContent();
40
41
        if (empty($content->get())) {
42
43
            $content->set(sprintf('<!DOCTYPE html>
44
<html>
45
    <head>
46
        <meta charset="UTF-8" />
47
        <meta http-equiv="refresh" content="1;url=%1$s" />
48
        <title>Redirecting to %1$s</title>
49
    </head>
50
    <body>
51
        Redirecting to <a href="%1$s">%1$s</a>.
52
    </body>
53
</html>', htmlspecialchars($location, ENT_QUOTES, 'UTF-8')));
54
55
        }
56
57
        parent::consolidate();
0 ignored issues
show
Bug introduced by
The call to Comodojo\Dispatcher\Resp...tatus200::consolidate() has too few arguments starting with response. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        parent::/** @scrutinizer ignore-call */ 
58
                consolidate();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
58
59
    }
60
61
}
62