ParsedBody::toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Psr7Unitesting\ServerRequest;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr7Unitesting\Utils\KeyValueConstraintTrait;
7
8 View Code Duplication
class ParsedBody extends AbstractConstraint
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    use KeyValueConstraintTrait;
11
12
    public function toString()
13
    {
14
        return sprintf('has the value "%s" equals to "%s" in the parsed body', $this->key, $this->expected);
15
    }
16
17
    protected function runMatches(ServerRequestInterface $request)
18
    {
19
        $body = $request->getParsedBody();
20
21
        return isset($body[$this->key]) && ($body[$this->key] == $this->expected);
22
    }
23
24
    protected function additionalFailureDescription($request)
25
    {
26
        $body = $request->getParsedBody();
27
28
        if (!isset($body[$this->key])) {
29
            return sprintf('No value "%s" found', $this->key);
30
        }
31
32
        return sprintf('"%s" returned', $body[$this->key]);
33
    }
34
}
35