Finder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 44
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 18 4
A createRegExp() 0 5 1
1
<?php
2
/**
3
 * Class Finder
4
 *
5
 * @author Mauro Moreno <[email protected]>
6
 */
7
namespace MauroMoreno\FindBundle\Service;
8
9
/**
10
 * Class Finder
11
 * @package MauroMoreno\FindBundle\Service
12
 */
13
class Finder implements FinderInterface
14
{
15
16
    /**
17
     * Find method
18
     *
19
     * @param string $pattern
20
     * @param \SplFileInfo $fileInfo
21
     *
22
     * @return bool|\SplFileInfo
23
     */
24 5
    public function find($pattern, \SplFileInfo $fileInfo)
25
    {
26 5
        if (!is_string($pattern)) {
27 1
            throw new \InvalidArgumentException('Pattern should be an string');
28
        }
29 4
        $pattern = $this->createRegExp($pattern);
30 4
        $data = fopen($fileInfo->getPathName(), 'r');
31
32 4
        $return = false;
33
34 4
        while ($line = fgets($data, 1024)) {
35 4
            if (preg_match($pattern, $line)) {
36 3
                $return = $fileInfo;
37 3
            }
38 4
        }
39
40 4
        return $return;
41
    }
42
43
    /**
44
     * Create Regular Expression
45
     *
46
     * @param string $pattern
47
     *
48
     * @return string
49
     */
50 4
    private function createRegExp($pattern)
51
    {
52 4
        $regexp = "/$pattern/";
53 4
        return $regexp;
54
    }
55
56
}
57