Processor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 54
c 0
b 0
f 0
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 18 2
A __construct() 0 13 1
A parse() 0 10 1
1
<?php namespace Comodojo\Dispatcher\Output;
2
3
use \Comodojo\Dispatcher\Components\AbstractModel;
4
use \Comodojo\Dispatcher\Request\Model as Request;
5
use \Comodojo\Dispatcher\Response\Model as Response;
6
use \Comodojo\Dispatcher\Traits\RequestTrait;
7
use \Comodojo\Dispatcher\Traits\ResponseTrait;
8
use \Comodojo\Dispatcher\Components\HttpStatusCodes;
9
use \Comodojo\Foundation\Base\Configuration;
10
use \Psr\Log\LoggerInterface;
11
use \Exception;
12
13
/**
14
 * @package     Comodojo Dispatcher
15
 * @author      Marco Giovinazzi <[email protected]>
16
 * @author      Marco Castiello <[email protected]>
17
 * @license     MIT
18
 *
19
 * LICENSE:
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 */
29
30
//
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
// @WARNING: some method's preprocessor missing
32
//
33
//         _______
34
//        j_______j
35
//       /_______/_\
36
//       |Missing| |
37
//       |  ___  | |
38
//       | !418! | |
39
//       | !___! | |
40
//       |_______|,'
41
//
42
43
class Processor extends AbstractModel {
44
45
    use RequestTrait;
46
    use ResponseTrait;
47
48
    protected $codes;
49
50 4
    public function __construct(
51
        Configuration $configuration,
52
        LoggerInterface $logger,
53
        Request $request,
54
        Response $response
55
    ) {
56
57 4
        parent::__construct($configuration, $logger);
58
59 4
        $this->setResponse($response);
60 4
        $this->setRequest($request);
61
62 4
        $this->codes = new HttpStatusCodes();
63
64 4
    }
65
66 4
    public function send() {
67
68 4
        $response = $this->getResponse();
69 4
        $request = $this->getRequest();
70
71 4
        $status = $response->getStatus()->get();
72
73 4
        if (!$this->codes->exists($status)) throw new Exception("Invalid HTTP status code in response");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Invalid HTTP status code in response 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...
74
75 4
        $message = $this->codes->getMessage($status);
76
77 4
        $response->getHeaders()->send();
78
79 4
        header(sprintf('HTTP/%s %s %s', (string)$request->getVersion(), $status, $message), true, $status);
80
81 4
        $response->getCookies()->save();
82
83 4
        return $response->getContent()->get();
84
85
    }
86
87 4
    public static function parse(
88
        Configuration $configuration,
89
        LoggerInterface $logger,
90
        Request $request,
91
        Response $response
92
    ) {
93
94 4
        $processor = new Processor($configuration, $logger, $request, $response);
95
96 4
        return $processor->send();
97
98
    }
99
100
}
101