PathIsExpectation::from()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
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 121
    public static function from(Expectation $expectation): callable
13
    {
14 121
        return function ($request) use ($expectation) {
15
            /** @var RequestInterface $request */
16 119
            if (!is_null($expectation->getPath()) && $request->getUri()->getPath() !== $expectation->getPath()) {
17 1
                return new RejectedPromise('path \'' . $request->getUri()->getPath() . '\' does not match expectation');
18
            }
19
20 118
            return $request;
21 121
        };
22
    }
23
}
24