MethodIsExpectation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A from() 0 9 3
1
<?php
2
3
namespace EasyHttp\MockBuilder\Expectations;
4
5
use EasyHttp\MockBuilder\Contracts\ExpectationMatcher;
6
use EasyHttp\MockBuilder\Expectation;
7
use GuzzleHttp\Promise\RejectedPromise;
8
use Psr\Http\Message\RequestInterface;
9
10
class MethodIsExpectation implements ExpectationMatcher
11
{
12 121
    public static function from(Expectation $expectation): callable
13
    {
14 121
        return function ($request) use ($expectation) {
15
            /** @var RequestInterface $request */
16 121
            if (!is_null($expectation->getMethod()) && $request->getMethod() !== $expectation->getMethod()) {
17 2
                return new RejectedPromise('method \'' . $request->getMethod() . '\' does not match expectation');
18
            }
19
20 119
            return $request;
21 121
        };
22
    }
23
}
24