HeaderIsNotExpectation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A from() 0 13 4
1
<?php
2
3
namespace EasyHttp\MockBuilder\Expectations;
4
5
use EasyHttp\MockBuilder\Contracts\ExpectationMatcher;
6
use EasyHttp\MockBuilder\Expectation;
7
use EasyHttp\MockBuilder\Helpers\GuzzleHeaderParser;
8
use GuzzleHttp\Promise\RejectedPromise;
9
use Psr\Http\Message\RequestInterface;
10
11
class HeaderIsNotExpectation implements ExpectationMatcher
12
{
13 121
    public static function from(Expectation $expectation): callable
14
    {
15 121
        return function ($request) use ($expectation) {
16
            /** @var RequestInterface $request */
17 77
            $headers = GuzzleHeaderParser::parse($request->getHeaders());
18
19 77
            foreach ($expectation->rejectedHeadersIterator() as $header => $value) {
20 10
                if (array_key_exists($header, $headers) && $headers[$header] === $value) {
21 7
                    return new RejectedPromise('header \'' . $header . '\' is same from expectation');
22
                }
23
            }
24
25 72
            return $request;
26 121
        };
27
    }
28
}
29