Passed
Push — main ( 3ba23a...063f15 )
by Darío
43s queued 12s
created

PathMatchExpectation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 1
A from() 0 9 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 109
    public static function from(Expectation $expectation): callable
12
    {
13 109
        return function ($request) use ($expectation) {
14
            /** @var RequestInterface $request */
15 107
            if (!is_null($expectation->getPathRegex()) && !self::matches($expectation, $request)) {
16 1
                return new RejectedPromise('path does not match expectation');
17
            }
18
19 106
            return $request;
20
        };
21
    }
22
23 2
    private static function matches($expectation, $request): bool
24
    {
25 2
        return preg_match($expectation->getPathRegex(), $request->getUri()->getPath(), $matches);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match($expec...)->getPath(), $matches) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
26
    }
27
}
28