This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSymfonyExtension.php
189 lines (167 loc) · 7.37 KB
/
SymfonyExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace Extension\Symfony;
use Hal\Application\Config\Configuration;
use Hal\Component\Bounds\Bounds;
use Hal\Component\File\Finder;
use Hal\Component\Result\ResultCollection;
require_once __DIR__ . '/CliSummaryReport.php';
require_once __DIR__ . '/HtmlSummaryReport.php';
class SymfonyExtension implements \Hal\Application\Extension\Extension {
/**
* @var array
*/
private $datas = array();
/**
* @param Configuration $config
* @param ResultCollection $collection
* @param ResultCollection $aggregatedResults
* @param Bounds $bounds
* @return mixed
*/
public function receive(Configuration $config, ResultCollection $collection, ResultCollection $aggregatedResults, Bounds $bounds)
{
$this->datas = (object) array(
'symfony' => (object) array(
'version' => '?'
)
,'controllers' => (object) array(
'total' => 0
, 'ccn' => 0
, 'mi' => 0
, 'lloc' => 0
, 'methods' => 0
)
, 'forms' => (object) array(
'total' => 0
, 'ccn' => 0
, 'mi' => 0
, 'lloc' => 0
, 'methods' => 0
)
,'commands' => (object) array(
'total' => 0
, 'ccn' => 0
, 'mi' => 0
, 'lloc' => 0
, 'methods' => 0
)
,'misc' => (object) array(
'paramconverters' => 0
, 'events' => 0
)
,'twig' => (object) array(
'total' => 0
,'js' => 0
,'html' => 0
,'css' => 0
,'other' => 0
)
);
$ccnControllers = $llocControllers = $miControllers = $methodsControllers = array();
$ccnForms = $llocForms = $miForms = $methodsForms = array();
$ccnCommands = $llocCommands = $miCommands = $methodsCommands= array();
// search controller
foreach($collection as $f => $item) {
$classes = $item->getOop()->getClasses();
foreach($classes as $class) {
// search controllers
if('Symfony\Bundle\FrameworkBundle\Controller\Controller' == $class->getParent()
||\preg_match('/Controller$/', $class->getName())) {
$this->datas->controllers->total++;
$ccnControllers[$f] = $item->getMcCabe()->getCyclomaticComplexityNumber();
$llocControllers[$f] = $item->getLoc()->getLogicalLoc();
$miControllers[$f] = $item->getMaintainabilityIndex()->getMaintainabilityIndex();
$methodsControllers[$f] = sizeof($class->getMethods());
}
// search commands
if('Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand' == $class->getParent()
||\preg_match('/Command$/', $class->getName())) {
$this->datas->commands->total++;
$ccnCommands[$f] = $item->getMcCabe()->getCyclomaticComplexityNumber();
$llocCommands[$f] = $item->getLoc()->getLogicalLoc();
$miCommands[$f] = $item->getMaintainabilityIndex()->getMaintainabilityIndex();
$methodsCommands[$f] = sizeof($class->getMethods());
}
// search forms
if('Symfony\Component\Form\AbstractType' == $class->getParent()
||\preg_match('/Type/', $class->getName())) {
$this->datas->forms->total++;
$ccnForms[$f] = $item->getMcCabe()->getCyclomaticComplexityNumber();
$llocForms[$f] = $item->getLoc()->getLogicalLoc();
$miForms[$f] = $item->getMaintainabilityIndex()->getMaintainabilityIndex();
$methodsForms[$f] = sizeof($class->getMethods());
}
// search params converters
if(in_array('Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface', $class->getInterfaces())) {
$this->datas->misc->paramconverters++;
}
// search events
if('Symfony\Component\EventDispatcher\Event' == $class->getParent()) {
$this->datas->misc->events++;
}
}
}
// twig
$finder = new Finder('twig', $config->getPath()->getExcludedDirs());
$files = $finder->find($config->getPath()->getBasePath());
$this->datas->twig->total = sizeof($files);
foreach($files as $filename) {
switch(true) {
case preg_match('/\.html\.twig$/i', $filename):
$this->datas->twig->html++;
break;
case preg_match('/\.js\.twig$/i', $filename):
$this->datas->twig->js++;
break;
case preg_match('/\.css\.twig$/i', $filename):
$this->datas->twig->css++;
break;
default:
$this->datas->twig->other++;
break;
}
}
// search Symfony version
$finder = new Finder('cache', $config->getPath()->getExcludedDirs());
$files = $finder->find($config->getPath()->getBasePath());
foreach($files as $filename) {
if(preg_match('/bootstrap\.php\.cache/', $filename)) {
$content = file_get_contents($filename);
if(preg_match("/const VERSION ='(.*?)';/", $content, $matches)) {
list(, $sfVersion) = $matches;
$this->datas->symfony->version = $sfVersion;
}
break;
}
}
// averages
$this->datas->controllers->ccn = round(array_sum($ccnControllers) / sizeof($ccnControllers), 2);
$this->datas->controllers->mi = round(array_sum($miControllers) / sizeof($miControllers), 2);
$this->datas->controllers->lloc = round(array_sum($llocControllers) / sizeof($llocControllers), 0);
$this->datas->controllers->methods = round(array_sum($methodsControllers) / sizeof($methodsControllers), 1);
$this->datas->forms->ccn = round(array_sum($ccnForms) / sizeof($ccnForms), 2);
$this->datas->forms->mi = round(array_sum($miForms) / sizeof($miForms), 2);
$this->datas->forms->lloc = round(array_sum($llocForms) / sizeof($llocForms), 0);
$this->datas->forms->methods = round(array_sum($methodsForms) / sizeof($methodsForms), 1);
$this->datas->commands->ccn = round(array_sum($ccnCommands) / sizeof($ccnCommands), 2);
$this->datas->commands->mi = round(array_sum($miCommands) / sizeof($miCommands), 2);
$this->datas->commands->lloc = round(array_sum($llocCommands) / sizeof($llocCommands), 0);
$this->datas->commands->methods = round(array_sum($methodsCommands) / sizeof($methodsCommands), 1);
}
/**
* @return string
*/
public function getName()
{
return 'Symfony 2';
}
public function getReporterHtmlSummary()
{
return new HtmlSummaryReport($this->datas);
}
public function getReporterCliSummary()
{
return new CliSummaryReport($this->datas);
}
}
return new SymfonyExtension();