Completed
Push — master ( 5c14c5...9a3118 )
by Nate
01:49
created

JsonRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
1
<?php
2
3
/**
4
 * REST Middleware
5
 *
6
 * @package    Force
7
 * @author     Flipbox Factory <[email protected]>
8
 * @copyright  2010-2016 Flipbox Digital Limited
9
 * @license    https://flipboxfactory.com/software/craft/force/license
10
 * @version    Release: 1.3.0
11
 * @link       https://github.com/FlipboxFactory/Force
12
 * @since      Class available since Release 1.0.0
13
 */
14
15
namespace Flipbox\Relay\HubSpot\Middleware;
16
17
use Flipbox\Http\Stream\Factory as StreamFactory;
18
use Flipbox\Relay\Middleware\AbstractMiddleware;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Flipbox\Relay\HubSpot\Mi...ware\AbstractMiddleware.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use Psr\Http\Message\RequestInterface;
20
use Psr\Http\Message\ResponseInterface;
21
22
class JsonRequest extends AbstractMiddleware
23
{
24
    /**
25
     * @var array
26
     */
27
    public $payload;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function __invoke(
33
        RequestInterface $request,
34
        ResponseInterface $response,
35
        callable $next = null
36
    ) {
37
        if ($this->payload !== null) {
38
            $request = $request->withBody(
39
                StreamFactory::create(
40
                    json_encode($this->payload)
41
                )
42
            );
43
        }
44
45
        return $next($request, $response);
46
    }
47
}
48