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

ContainsInOrderConstraint   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 16 3
A toString() 0 4 1
A failureDescription() 0 8 2
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