1
|
|
|
<?php |
2
|
|
|
namespace Finder\Contracts\Spider; |
3
|
|
|
|
4
|
|
|
use Finder\Logic\Output\AbstractOutput; |
5
|
|
|
use Finder\Logic\Output\Filter\OutputFilterInterface; |
6
|
|
|
use Finder\Logic\Output\TriggerableInterface; |
7
|
|
|
|
8
|
|
|
use Symfony\Component\Finder\Finder; |
9
|
|
|
|
10
|
|
|
use Finder\Spider\File; |
11
|
|
|
use Finder\Spider\Directory; |
12
|
|
|
use Finder\Spider\Registrator\FileRegistrator; |
13
|
|
|
use Finder\Spider\Metrics\FileMetric; |
14
|
|
|
|
15
|
|
|
use Support\Helps\DebugHelper; |
16
|
|
|
use Support\Helps\CodeFileHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Run all script analysers and outputs their result. |
20
|
|
|
*/ |
21
|
|
|
abstract class Spider extends TargetManager |
22
|
|
|
{ |
23
|
|
|
protected $registrator = false; |
24
|
|
|
protected $metrics = false; |
25
|
|
|
|
26
|
|
|
public function __construct($target, $parent = false) |
27
|
|
|
{ |
28
|
|
|
parent::__construct($target, $parent); |
29
|
|
|
|
30
|
|
|
$this->registrator = new FileRegistrator($this->getTarget(), $this->getParent()); |
|
|
|
|
31
|
|
|
$this->setMetric(); |
32
|
|
|
|
33
|
|
|
if ($this->getParent()) { |
34
|
|
|
$this->getMetric()->registerMetricCount('Targets', CodeFileHelper::getClassName($this)); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getMetric() |
39
|
|
|
{ |
40
|
|
|
return $this->metrics; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function setMetric($metricClass = false) |
44
|
|
|
{ |
45
|
|
|
if (!$metricClass) { |
46
|
|
|
$metricClass = new FileMetric($this->getTarget(), $this->getParent()); |
47
|
|
|
} |
48
|
|
|
$this->metrics = $metricClass; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function run() |
52
|
|
|
{ |
53
|
|
|
$this->analyse(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function followChildrens($finder) |
57
|
|
|
{ |
58
|
|
|
// check if there are any search results |
59
|
|
|
if (!$finder->hasResults()) { |
60
|
|
|
DebugHelper::info('No Results: '.$this->getTargetPath()); |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
foreach ($finder as $file) { |
66
|
|
|
if ($file->getType() == 'file') { |
67
|
|
|
$newSpider = new File($file, $this); |
|
|
|
|
68
|
|
|
} else { |
69
|
|
|
$newSpider = new Directory($file, $this); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
$newSpider->run(); |
72
|
|
|
|
73
|
|
|
$this->getMetric()->mergeWith( |
|
|
|
|
74
|
|
|
$newSpider->getMetric()->saveAndReturnArray() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (!$this->getParent()) { |
79
|
|
|
dd('Spider', $this->getMetric()->returnMetrics()); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..