Code Duplication    Length = 45-46 lines in 2 locations

src/matcher/strategy/ArrayInclusionStrategy.php 1 location

@@ 13-57 (lines=45) @@
10
 */
11
namespace expect\matcher\strategy;
12
13
final class ArrayInclusionStrategy implements InclusionStrategy
14
{
15
    /**
16
     * @var array
17
     */
18
    private $actualValues;
19
20
    /**
21
     * @param array actualValues
22
     */
23
    public function __construct(array $actualValues)
24
    {
25
        $this->actualValues = $actualValues;
26
    }
27
28
    /**
29
     * <code>
30
     * <?php
31
     *     $strategy = new ArrayInclusionStrategy([ 1, 2 ]);
32
     *     $result = $strategy->match([ 1, 2, 3 ]);.
33
     *
34
     *     var_dump($result->isMatched()) // true
35
     *     var_dump($result->getMatchResults()); // [ 1, 2 ]
36
     *     var_dump($result->getUnmatchResults()); // [ 3 ]
37
     * ?>
38
     * </code>
39
     *
40
     * @param array expectValues
41
     */
42
    public function match(array $expectValues)
43
    {
44
        $matchResults = [];
45
        $unmatchResults = [];
46
47
        foreach ($expectValues as $expectValue) {
48
            if (in_array($expectValue, $this->actualValues)) {
49
                $matchResults[] = $expectValue;
50
            } else {
51
                $unmatchResults[] = $expectValue;
52
            }
53
        }
54
55
        return new InclusionResult($expectValues, $matchResults, $unmatchResults);
56
    }
57
}
58

src/matcher/strategy/StringInclusionStrategy.php 1 location

@@ 13-58 (lines=46) @@
10
 */
11
namespace expect\matcher\strategy;
12
13
final class StringInclusionStrategy implements InclusionStrategy
14
{
15
    /**
16
     * @var string
17
     */
18
    private $actualValue;
19
20
    /**
21
     * @param string actualValues
22
     */
23
    public function __construct($actualValue)
24
    {
25
        $this->actualValue = $actualValue;
26
    }
27
28
    /**
29
     * <code>
30
     * <?php
31
     *     $strategy = new StringInclusionStrategy('foo');
32
     *     $result = $strategy->match([ 'foo', 'bar' ]);.
33
     *
34
     *     var_dump($result->isMatched()) // true
35
     *     var_dump($result->getMatchResults()); // ['foo']
36
     *     var_dump($result->getUnmatchResults()); // ['bar']
37
     * ?>
38
     * </code>
39
     *
40
     * @param array expectValues
41
     */
42
    public function match(array $expectValues)
43
    {
44
        $matchResults = [];
45
        $unmatchResults = [];
46
47
        foreach ($expectValues as $expectValue) {
48
            $position = strpos($this->actualValue, $expectValue);
49
            if ($position !== false) {
50
                $matchResults[] = $expectValue;
51
            } else {
52
                $unmatchResults[] = $expectValue;
53
            }
54
        }
55
56
        return new InclusionResult($expectValues, $matchResults, $unmatchResults);
57
    }
58
}
59