Passed
Push — main ( 99b119...3ba23a )
by Darío
56s queued 12s
created

PathIsExpectation::from()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 1
nop 1
crap 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 PathIsExpectation implements ExpectationMatcher
11
{
12 109
    public static function from(Expectation $expectation): callable
13
    {
14 109
        return function ($request) use ($expectation) {
15 108
            if ($path = $expectation->getPath()) {
16
                /** @var RequestInterface $request */
17 4
                if ($request->getUri()->getPath() !== $path) {
18 1
                    return new RejectedPromise('path does not match expectation');
19
                }
20
            }
21
22 107
            return $request;
23
        };
24
    }
25
}
26