Completed
Push — master ( 28c9d6...b69760 )
by Scott
03:03
created

EndsWith   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 10 3
A fileEndsWith() 0 6 1
1
<?php
2
namespace exussum12\CoverageChecker\FileMatchers;
3
4
use exussum12\CoverageChecker\FileMatcher;
5
use exussum12\CoverageChecker\Exceptions\FileNotFound;
6
7
/**
8
 * Class EndsWith
9
 * @package exussum12\CoverageChecker\FileMatchers
10
 */
11
class EndsWith implements FileMatcher
12
{
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function match($needle, array $haystack)
18
    {
19
        foreach ($haystack as $file) {
20
            if ($this->fileEndsWith($file, $needle)) {
21
                return $file;
22
            }
23
        }
24
25
        throw new FileNotFound();
26
    }
27
28
    /**
29
     * Find if two strings end in the same way
30
     * @param $haystack
31
     * @param $needle
32
     * @return bool
33
     */
34
    protected function fileEndsWith($haystack, $needle)
35
    {
36
        $length = strlen($needle);
37
38
        return (substr($haystack, -$length) === $needle);
39
    }
40
}
41