Finder::search()   B
last analyzed

Complexity

Conditions 5
Paths 10

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 17
rs 8.8571
cc 5
eloc 10
nc 10
nop 2
1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundle\Finder;
4
5
use Psr\Log\LoggerInterface;
6
7
class Finder
8
{
9
    private $files;
10
11
    /**
12
     * [$logger description]
13
     *
14
     * @var \Psr\Log\LoggerInterface
15
     */
16
    private $logger;
17
18
    public function __construct()
19
    {
20
        $this->files = [];
21
    }
22
23
    /**
24
     * [search description]
25
     *
26
     * @param string $dir       search directory
27
     * @param string $extension extension to find, Ex: yml, php, raml
28
     */
29
    public function search($dir, $extension)
30
    {
31
        if (isset($this->logger)) {
32
            $this->logger->info('Finder invocato su directory : '.$dir);
33
        }
34
        $rdi = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
35
        $rit = new \RecursiveIteratorIterator($rdi);
36
37
        foreach ($rit as $file) {
38
            if (isset($this->logger)) {
39
                $this->logger->debug('Valuto file', ['filename' => $file]);
40
            }
41
            if (pathinfo($file, PATHINFO_EXTENSION) == $extension) {
42
                $this->files[] = $file;
43
            }
44
        }
45
    }
46
47
    public function setLogger(LoggerInterface $logger)
48
    {
49
        $this->logger = $logger;
50
    }
51
52
    public function getFindedFiles()
53
    {
54
        return $this->files;
55
    }
56
}
57