Finder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFindedFiles() 0 4 1
A __construct() 0 4 1
B search() 0 17 5
A setLogger() 0 4 1
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