|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Solidifier; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
6
|
|
|
use Gaufrette\Filesystem; |
|
7
|
|
|
use Solidifier\Reporters\HTMLReporter; |
|
8
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
9
|
|
|
use Gaufrette\Adapter\Local; |
|
10
|
|
|
use Solidifier\Visitors\PreAnalyze\ObjectTypes; |
|
11
|
|
|
|
|
12
|
|
|
class Application extends \Pimple |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::__construct(); |
|
17
|
|
|
|
|
18
|
|
|
$this->initializeFilesystem(); |
|
|
|
|
|
|
19
|
|
|
$this->initializeServices(); |
|
|
|
|
|
|
20
|
|
|
$this->initializeSubscribers(); |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
private function initializeFilesystem() |
|
24
|
|
|
{ |
|
25
|
|
|
$this['filesystem.path'] = 'src/'; |
|
|
|
|
|
|
26
|
|
|
$this['filesystem.adapter'] = function($c) { |
|
27
|
|
|
return new Local($c['filesystem.path']); |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
$this['filesystem'] = function($c) { |
|
31
|
|
|
return new Filesystem($c['filesystem.adapter']); |
|
32
|
|
|
}; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private function initializeServices() |
|
36
|
|
|
{ |
|
37
|
|
|
$this['configuration'] = function($c) { |
|
38
|
|
|
|
|
39
|
|
|
$configuration = array(); |
|
40
|
|
|
|
|
41
|
|
|
$filename = '.solidifier.yml'; |
|
42
|
|
|
$fs = $c['filesystem']; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if($fs->has($filename)) |
|
45
|
|
|
{ |
|
46
|
|
|
$configuration = Yaml::parse($fs->read($filename)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $configuration; |
|
50
|
|
|
}; |
|
51
|
|
|
|
|
52
|
|
|
$this['event.dispatcher'] = function($c) { |
|
|
|
|
|
|
53
|
|
|
return new EventDispatcher(); |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
$this['dispatcher'] = function($c) { |
|
57
|
|
|
return new Dispatchers\EventDispatcher($c['event.dispatcher']); |
|
58
|
|
|
}; |
|
59
|
|
|
|
|
60
|
|
|
$this['analyzer'] = function($c) { |
|
61
|
|
|
$analyzer = new Analyzers\Analyzer($c['dispatcher'], $c['filesystem']); |
|
62
|
|
|
|
|
63
|
|
|
$handler = new ConfigurationHandler($c['configuration'], $c['objectTypes.list']); |
|
64
|
|
|
$handler->configure($analyzer); |
|
65
|
|
|
|
|
66
|
|
|
return $analyzer; |
|
67
|
|
|
}; |
|
68
|
|
|
|
|
69
|
|
|
$this['twig.path'] = 'views'; |
|
|
|
|
|
|
70
|
|
|
$this['twig.cache'] = false; |
|
71
|
|
|
$this['twig.debug'] = true; |
|
72
|
|
|
|
|
73
|
|
|
$this['twig'] = function($c) { |
|
74
|
|
|
$loader = new \Twig_Loader_Filesystem($c['twig.path']); |
|
75
|
|
|
$twig = new \Twig_Environment($loader, array( |
|
|
|
|
|
|
76
|
|
|
'cache' => $c['twig.cache'], |
|
77
|
|
|
'debug' => $c['twig.debug'], |
|
78
|
|
|
)); |
|
79
|
|
|
|
|
80
|
|
|
if($c['twig.debug'] === true) |
|
81
|
|
|
{ |
|
82
|
|
|
$twig->addExtension(new \Twig_Extension_Debug()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $twig; |
|
86
|
|
|
}; |
|
87
|
|
|
|
|
88
|
|
|
$this['objectTypes.list'] = function($c) { |
|
|
|
|
|
|
89
|
|
|
return new ObjectTypes(); |
|
90
|
|
|
}; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
private function initializeSubscribers() |
|
94
|
|
|
{ |
|
95
|
|
|
$this['subscriber.console'] = function($c) { |
|
|
|
|
|
|
96
|
|
|
return new EventSubscribers\Console(); |
|
97
|
|
|
}; |
|
98
|
|
|
|
|
99
|
|
|
$this['reporter.html'] = function($c) { |
|
100
|
|
|
return new Reporters\HTMLReporter($c['twig']); |
|
101
|
|
|
}; |
|
102
|
|
|
|
|
103
|
|
|
$this['subscriber.html'] = function($c) { |
|
104
|
|
|
return new EventSubscribers\HTML($c['reporter.html']); |
|
105
|
|
|
}; |
|
106
|
|
|
} |
|
107
|
|
|
} |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: