Passed
Push — feature/support-path-match-exp... ( fcb893 )
by Darío
07:20
created

PathMatchExpectation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A from() 0 11 3
1
<?php
2
3
namespace EasyHttp\MockBuilder\Expectations;
4
5
use EasyHttp\MockBuilder\Expectation;
6
use GuzzleHttp\Promise\RejectedPromise;
7
use Psr\Http\Message\RequestInterface;
8
9
class PathMatchExpectation
10
{
11 98
    public static function from(Expectation $expectation): callable
12
    {
13 98
        return function ($request) use ($expectation) {
14 97
            if ($regex = $expectation->getPathRegex()) {
15
                /** @var RequestInterface $request */
16 1
                if (!preg_match($regex, $request->getUri()->getPath(), $matches)) {
17
                    return new RejectedPromise('path does not match expectation');
18
                }
19
            }
20
21 97
            return $request;
22 98
        };
23
    }
24
}
25