Completed
Push — master ( 003b5e...76542b )
by Woody
38:06 queued 22:13
created

ContentHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 1
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
isApplicableMimeType() 0 1 ?
getParsedBody() 0 1 ?
1
<?php
2
namespace Equip\Handler;
3
4
use Psr\Http\Message\ResponseInterface;
5
use Psr\Http\Message\ServerRequestInterface;
6
7
abstract class ContentHandler
8
{
9
    /**
10
     * Parses request bodies based on content type.
11
     *
12
     * @param ServerRequestInterface $request
13
     * @param ResponseInterface $response
14
     * @param callable $next
15
     *
16
     * @return Response
17
     */
18 5
    public function __invoke(
19
        ServerRequestInterface $request,
20
        ResponseInterface $response,
21
        callable $next
22
    ) {
23 5
        $mime = strtolower($request->getHeaderLine('Content-Type'));
24
25 5
        if ($this->isApplicableMimeType($mime) && !$request->getParsedBody()) {
26 3
            $body = (string) $request->getBody();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
27 3
            $parsed = $this->getParsedBody($body);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
28 2
            $request = $request->withParsedBody($parsed);
29
        }
30
31 4
        return $next($request, $response);
32
    }
33
34
    /**
35
     * Check if the content type is appropriate for handling.
36
     *
37
     * @param string $mime
38
     *
39
     * @return boolean
40
     */
41
    abstract protected function isApplicableMimeType($mime);
42
43
    /**
44
     * Parse the request body.
45
     *
46
     * @param string $body
47
     *
48
     * @return mixed
49
     */
50
    abstract protected function getParsedBody($body);
51
}
52