Passed
Push — master ( 5198fb...6eb156 )
by Thierry
02:34
created

UploadResponse::getErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Response;
4
5
use function addslashes;
6
use function array_reduce;
7
use function json_encode;
8
9
class UploadResponse implements ResponseInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UploadResponse
Loading history...
10
{
11
    use Traits\CommandTrait;
12
13
    /**
14
     * The path to the uploaded file
15
     *
16
     * @var string
17
     */
18
    private $sUploadedFile = '';
19
20
    /**
21
     * The error message
22
     *
23
     * @var string
24
     */
25
    private $sErrorMessage = '';
26
27
    /**
28
     * The debug messages
29
     *
30
     * @var array
31
     */
32
    private $aDebugMessages = [];
33
34
    public function __construct(string $sUploadedFile, string $sErrorMessage = '')
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
35
    {
36
        $this->sUploadedFile = $sUploadedFile;
37
        $this->sErrorMessage = $sErrorMessage;
38
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
    /**
41
     * @inheritDoc
42
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
43
    public function getContentType(): string
44
    {
45
        return 'text/html';
46
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
47
48
    /**
49
     * Get the path to the uploaded file
50
     *
51
     * @return string
52
     */
53
    public function getUploadedFile(): string
54
    {
55
        return $this->sUploadedFile;
56
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
57
58
    /**
59
     * Get the error message
60
     *
61
     * @return string
62
     */
63
    public function getErrorMessage(): string
64
    {
65
        return $this->sErrorMessage;
66
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
67
68
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sMessage should have a doc-comment as per coding-style.
Loading history...
69
     * @inheritDoc
70
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
71
    public function debug(string $sMessage): ResponseInterface
72
    {
73
        $this->aDebugMessages[] = $sMessage;
74
        return $this;
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
76
77
    /**
78
     * @inheritDoc
79
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
80
    public function getOutput(): string
81
    {
82
        $sResult = json_encode(($this->sUploadedFile) ?
0 ignored issues
show
Coding Style introduced by
Expected 1 space after "?"; newline found
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
83
            ['code' => 'success', 'upl' => $this->sUploadedFile] :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
84
            ['code' => 'error', 'msg' => $this->sErrorMessage]) . ';';
85
        $sConsoleLog = array_reduce($this->aDebugMessages, function($sJsLog, $sMessage) {
86
            return "$sJsLog\n\t" . 'console.log("' . addslashes($sMessage) . '");';
87
        }, '');
88
89
        return '
90
<!DOCTYPE html>
91
<html>
92
<body>
93
<h1>HTTP Upload for Jaxon</h1>
94
</body>
95
<script>
96
    res = ' . $sResult . $sConsoleLog . '
97
</script>
98
</html>
99
';
100
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
101
}
102