1 | <?php |
||
24 | class Html implements FormaterInterface { |
||
25 | |||
26 | /** |
||
27 | * Bounds |
||
28 | * |
||
29 | * @var BoundsInterface |
||
30 | */ |
||
31 | private $bound; |
||
32 | |||
33 | /** |
||
34 | * Validator |
||
35 | * |
||
36 | * @var Validator |
||
37 | */ |
||
38 | private $validator; |
||
39 | |||
40 | /** |
||
41 | * Template configuration |
||
42 | * |
||
43 | * @var TemplateConfiguration |
||
44 | */ |
||
45 | private $template; |
||
46 | |||
47 | /** |
||
48 | * Constructor |
||
49 | * |
||
50 | * @param Validator $validator |
||
51 | * @param BoundsInterface $bound |
||
52 | * @param TemplateConfiguration $template |
||
53 | */ |
||
54 | public function __construct(Validator $validator, BoundsInterface $bound, TemplateConfiguration $template) |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function terminate(ResultCollection $collection, ResultCollection $groupedResults){ |
||
65 | \Twig_Autoloader::register(); |
||
66 | $loader = new \Twig_Loader_Filesystem(__DIR__.'/../../../../../templates/html'); |
||
67 | $twig = new \Twig_Environment($loader, array('cache' => false)); |
||
68 | $twig->addExtension(new FormatingExtension($this->validator)); |
||
69 | |||
70 | $bound = $this->bound->calculate($collection); |
||
71 | return $twig->render('summary/report.html.twig', array( |
||
72 | 'keys' => array_keys(current($collection->asArray())) |
||
73 | , 'results' => $collection->asArray() |
||
74 | , 'groupedResults' => $groupedResults |
||
75 | , 'root' => $groupedResults->getIterator()->current() |
||
76 | , 'relations' => $this->prepareDataRelations($collection) |
||
77 | , 'scores' => $collection->getScore()->all() |
||
78 | , 'ruleSet' => $this->validator->getRuleSet() |
||
79 | , 'bounds' => $bound |
||
80 | , 'withOOP' => null !== $bound->getSum('instability') |
||
81 | , 'title' => $this->template->getTitle() |
||
82 | )); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Build flat array of relations |
||
87 | * |
||
88 | * @param ResultCollection $collection |
||
89 | * @return array |
||
90 | */ |
||
91 | private function prepareDataRelations(ResultCollection $collection) { |
||
92 | $array = array(); |
||
93 | |||
94 | // map of classes an relations |
||
95 | foreach($collection as $item) { |
||
96 | |||
97 | // case of oop is disabled |
||
98 | if(!$item->getOOP()) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | foreach($item->getOOP()->getClasses() as $class) { |
||
103 | $array[$class->getFullname()] = (object) array( |
||
104 | 'name' => $class->getFullname() |
||
105 | , 'size' => 3000 |
||
106 | , 'relations' => array_merge( |
||
107 | !is_null($class->getParent()) ? array($class->getParent()) : array() |
||
108 | , $class->getDependencies() |
||
109 | ) |
||
110 | ); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | // dependency can not be in the parsed sources (for example, native PHP classes) |
||
115 | foreach($array as $class => $infos) { |
||
116 | foreach($infos->relations as $relation) { |
||
117 | if(!isset($array[$relation])) { |
||
118 | $array[$relation] = (object) array('name' => $relation, 'relations' => array(), 'size' => 3000); |
||
119 | } |
||
120 | // array_push($array[$relation]->imports, $class); |
||
121 | } |
||
122 | } |
||
123 | return array_values($array); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | public function getName() { |
||
132 | } |