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

EndsWith::fileEndsWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 9.4285
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