Completed
Push — next ( 3fc9f0...5d2fc6 )
by Jonathan
9s
created

ContainsInOrderConstraint::matches()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Test;
4
5
use PHPUnit_Framework_Constraint;
6
7
class ContainsInOrderConstraint extends PHPUnit_Framework_Constraint
8
{
9
    protected $expected;
10
11
    public function __construct(array $expected)
12
    {
13
        parent::__construct();
14
        $this->expected = $expected;
15
    }
16
17
    public function matches($other)
0 ignored issues
show
Coding Style introduced by
function matches() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
18
    {
19
        $cursor = 0;
20
21
        foreach ($this->expected as $substring) {
22
            $next = strpos($other, $substring, $cursor);
23
24
            if ($next === false) {
25
                return false;
26
            }
27
28
            $cursor = $next + strlen($substring) + 1;
29
        }
30
31
        return true;
32
    }
33
34
    public function toString()
35
    {
36
        return 'matches array of '.count($this->expected).' strings';
37
    }
38
39
    protected function failureDescription($other)
40
    {
41
        if (is_string($other)) {
42
            return 'string '.strlen($other).' bytes long '.$this->toString();
43
        } else {
44
            return $this->exporter->export($other).' '.$this->toString();
45
        }
46
    }
47
}
48