Completed
Push — master ( a7292a...85b851 )
by Vladimir
05:32
created

CheckFinder.php$0 ➔ clear()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
crap 1
1
<?php
2
/**
3
 * This file is part of the `tvi/monitor-bundle` project.
4
 *
5
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
10
11
namespace Tvi\MonitorBundle\Check;
12
13
use Symfony\Component\Finder\Finder;
14
15
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
16
 * @author Vladimir Turnaev <[email protected]>
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
18
class CheckFinder
19
{
20
    protected $searchDirs = [__DIR__.'/**'];
21
22 41
    public function __construct(array $dirs = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
23
    {
24 41
        if($dirs) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
25
            $this->searchDirs = array_merge($this->searchDirs, $dirs);
26
        }
27 41
    }
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @return string[]
31
     */
32 41
    public function find()
33
    {
34 41
        $fs = Finder::create();
35 41
        $files = $fs->in($this->searchDirs)->name('*.php')->files();
36
37 41
        $res = [];
38 41
        foreach ($files as $f) {
39
            /* @var \SplFileInfo $f */
40
41 41
            $code = $f->getContents();
0 ignored issues
show
Bug introduced by
The method getContents() does not exist on SplFileInfo. It seems like you code against a sub-type of SplFileInfo such as Symfony\Component\Finder\SplFileInfo or Symfony\Component\Finder...terator\MockSplFileInfo. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            /** @scrutinizer ignore-call */ 
42
            $code = $f->getContents();
Loading history...
42 41
            $class = $this->getConfigClass($code);
43 41
            if(is_subclass_of($class, CheckConfigInterface::class)) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
44 41
                $res[] = $class;
45
            }
46
        }
47
48 41
        return $res;
49
    }
50
51 41
    private function getConfigClass($contents)
0 ignored issues
show
Coding Style introduced by
Private method name "CheckFinder::getConfigClass" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function getConfigClass()
Loading history...
52
    {
53 41
        $namespace = [];
54 41
        $class = [];
55
56 41
        $tokens = token_get_all($contents);
57
58
        do {
0 ignored issues
show
Coding Style introduced by
Expected "do \n... while (...);\n"; found "do \n... while(...);\n"
Loading history...
59 41
            $token = current($tokens);
60
61 41
            if(isset($token[0]) && $token[0] == T_NAMESPACE) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
62 41
                next($tokens);
63
                do {
0 ignored issues
show
Coding Style introduced by
Expected "do \n... while (...);\n"; found "do \n... while(...);\n"
Loading history...
64 41
                    $token = current($tokens);
65 41
                    if($token == ';') {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
66 41
                        break 1;
67
                    }
68 41
                    $namespace[] = $token[1];
69 41
                } while(next($tokens));
70
71 41
                $namespace = trim(implode('', $namespace));
72
            }
73
74 41
            if(isset($token[0]) && $token[0] == T_CLASS) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
75 41
                next($tokens);
76
                do {
0 ignored issues
show
Coding Style introduced by
Expected "do \n... while (...);\n"; found "do \n... while(...);\n"
Loading history...
77 41
                    $token = current($tokens);
78
79 41
                    if($token[0] == T_EXTENDS) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
80
                        break 1;
81
                    }
82
83 41
                    if($token[0] == T_STRING) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
84 41
                        $class[] = $token[1];
85 41
                        break 1;
86
                    }
87
88 41
                } while(next($tokens));
89
90 41
                $class = trim(implode('', $class));
91
92 41
                break;
93
            }
94
95 41
        } while(next($tokens));
96
97 41
        $configClass = (string)$namespace . '\\' . (string)$class;
98
99 41
        return $configClass;
100
    }
101
}
102
103