BehatMatcher::normolizeValue()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 13.125

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 7
cts 14
cp 0.5
rs 8.5386
c 0
b 0
f 0
cc 7
nc 7
nop 1
crap 13.125
1
<?php
2
3
namespace SmartGamma\Behat\PactExtension\Infrastructure\Interaction;
4
5
use PhpPact\Consumer\Matcher\Matcher;
6
7
class BehatMatcher implements MatcherInterface
8
{
9
    /**
10
     * @var Matcher
11
     */
12
    private $pactMatcher;
13
14 8
    public function __construct(Matcher $matcher)
15
    {
16 8
        $this->pactMatcher = $matcher;
17
    }
18
19
    /**
20
     * @param $value
21
     *
22
     * @return array
23
     * @throws \Exception
24
     */
25 1
    public function like($value)
26
    {
27 1
        return $this->pactMatcher->like($this->normolizeValue($value));
28
    }
29
30
    /**
31
     * @param $value
32
     *
33
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string|null|double|integer|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
34
     */
35 1
    public function exact($value)
36
    {
37 1
        return $this->normolizeValue($value);
38
    }
39
40
    /**
41
     * @param string $value
42
     *
43
     * @return array
44
     * @throws \Exception
45
     */
46 1
    public function dateTimeISO8601(string $value)
47
    {
48 1
        return $this->pactMatcher->dateTimeISO8601($value);
49
    }
50
51
    /**
52
     * @param string $value
53
     *
54
     * @return array
55
     * @throws \Exception
56
     */
57 1
    public function boolean(string $value)
58
    {
59 1
        return $this->pactMatcher->boolean();
60
    }
61
62
    /**
63
     * @param string $value
64
     *
65
     * @return array
66
     * @throws \Exception
67
     */
68 1
    public function integer(string $value)
69
    {
70 1
        return $this->pactMatcher->integer((int)$value);
71
    }
72
73
    /**
74
     * @param string $value
75
     *
76
     * @return array
77
     * @throws \Exception
78
     */
79 1
    public function uuid(string $value)
80
    {
81 1
        return $this->pactMatcher->uuid($value);
82
    }
83
84
    /**
85
     * @param array $object
86
     *
87
     * @return array
88
     */
89 1
    public function eachLike(array $object)
90
    {
91 1
        return $this->pactMatcher->eachLike($object);
92
    }
93
94
    /**
95
     * @param string $string
96
     *
97
     * @return bool | float | int | null | string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null|double|integer|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
98
     */
99 2
    private function normolizeValue(string $string)
100
    {
101 2
        if (empty($string)) {
102
            return '';
103
        }
104
105 2
        if ('null' === $string) {
106
            return null;
107
        }
108
109 2
        if (!preg_match('/[^0-9.]+/', $string)) {
110
            if (preg_match('/[.]+/', $string)) {
111
                return (float)$string;
112
            }
113
114
            return (int)$string;
115
        }
116
117 2
        if ('true' === $string) {
118
            return true;
119
        }
120
121 2
        if ('false' === $string) {
122
            return false;
123
        }
124
125 2
        return (string)$string;
126
    }
127
}
128