Skip to content

Commit 4c4e076

Browse files
committed
Merge pull request #16 from OSInet/15-undeclared-dependencies
Check Undeclared dependencies and external code
2 parents 5d8f74d + b127277 commit 4c4e076

File tree

13 files changed

+717
-94
lines changed

13 files changed

+717
-94
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ typically by piping the output like this:
5555
<td></td>
5656
</tr>
5757
<tr>
58-
<td>I18N</td>
59-
<td>Variables</td>
60-
<td></td>
61-
<td></td>
62-
<td>OK</td>
63-
</tr>
64-
<tr>
65-
<td rowspan="2">References</td>
58+
<td rowspan="3">References</td>
6659
<td>Integrity</td>
6760
<td>OK:<ul>
6861
<li>file</li>
@@ -74,19 +67,31 @@ typically by piping the output like this:
7467
<td></td>
7568
<td></td>
7669
</tr>
70+
<tr>
71+
<td>External code</td>
72+
<td>OK</td>
73+
<td></td>
74+
<td></td>
75+
</tr>
7776
<tr>
7877
<td>Taxonomy Index</td>
7978
<td>OK</td>
8079
<td></td>
8180
<td>OK</td>
8281
</tr>
8382
<tr>
84-
<td rowspan="3">System</td>
83+
<td rowspan="4">System</td>
8584
<td>Dependency (graph)</td>
8685
<td>OK</td>
8786
<td>OK</td>
8887
<td>OK</td>
8988
</tr>
89+
<tr>
90+
<td>Undeclared dependencies</td>
91+
<td>OK</td>
92+
<td></td>
93+
<td></td>
94+
</tr>
9095
<tr>
9196
<td>Unused</td>
9297
<td>OK</td>
@@ -107,16 +112,22 @@ typically by piping the output like this:
107112
<td>OK</td>
108113
</tr>
109114
<tr>
110-
<td>Variables</td>
115+
<td rowspan="2">Variables</td>
111116
<td>Size</td>
112-
<td>Not applicable</td>
117+
<td>n.a.</td>
113118
<td>OK</td>
114119
<td></td>
115120
</tr>
121+
<tr>
122+
<td>I18N</td>
123+
<td>n.a.</td>
124+
<td></td>
125+
<td>OK</td>
126+
</tr>
116127
<tr>
117128
<td rowspan="2">Views</td>
118129
<td>Override</td>
119-
<td>Not applicable</td>
130+
<td>n.a.</td>
120131
<td>OK</td>
121132
<td>OK</td>
122133
</tr>
@@ -130,7 +141,7 @@ typically by piping the output like this:
130141
<td rowspan="4">Workflows (Content Moderation)</td>
131142
<td>Summary</td>
132143
<td>OK</td>
133-
<td colspan="2" rowspan="3">Not applicable</td>
144+
<td colspan="2" rowspan="3">n.a.</td>
134145
</tr>
135146
<tr>
136147
<td>Transition (graph)</td>

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"drupal/core": "^8 || ^9",
2222
"osinet/grafizzi": "^0.0.2"
2323
},
24-
"type": "drupal-module"
24+
"type": "drupal-module",
25+
"require-dev": {
26+
"nikic/php-parser": "^4.8@dev"
27+
}
2528
}

qa.module

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
* @file
55
* OSInet Quality Assurance module for Drupal.
66
*
7-
* @copyright Copyright (C) 2005-2018 Frederic G. MARAND for Ouest Systèmes Informatiques (OSInet)
7+
* @copyright Copyright (C) 2005-2018 Frederic G. MARAND for Ouest Systèmes
8+
* Informatiques (OSInet)
89
*
910
* @since DRUPAL-4-6
1011
*
11-
* @license Licensed under the disjunction of the CeCILL, version 2 and General Public License version 2 and later
12+
* @license Licensed under the disjunction of the CeCILL, version 2 and General
13+
* Public License version 2 and later
1214
*
1315
* License note: QA is distributed by OSInet to its customers under the
1416
* CeCILL 2.0 license. OSInet support services only apply to the module
@@ -21,7 +23,11 @@
2123
* are abided by, the module distributor in that case being the
2224
* drupal.org organization or the downstream distributor, not OSInet.
2325
*/
26+
27+
use Drupal\Component\Utility\Xss;
28+
use Drupal\Core\Url;
2429
use Drupal\qa\Variable\Variable;
30+
use Symfony\Component\HttpFoundation\RedirectResponse;
2531

2632
/**
2733
* Page callback for qa/dependencies
@@ -33,7 +39,7 @@ use Drupal\qa\Variable\Variable;
3339
*/
3440
function qa_page_dependencies() {
3541
/** @var \Drupal\qa\Dependencies $qaDep */
36-
$qaDep = \Drupal::service('qa.dependencies');
42+
$qaDep = Drupal::service('qa.dependencies');
3743
$G = $qaDep->build();
3844
// passed by reference: cannot pass a function return
3945
return graphviz_filter_render($G);
@@ -49,14 +55,16 @@ function qa_page_dependencies() {
4955
function qa_report_finished($success, $results, $operations) {
5056
unset($results['#message']);
5157
if ($success) {
52-
$message = format_plural(count($results), 'One control pass ran.', '@count control passes ran.');
58+
$message = Drupal::translation()
59+
->formatPlural(count($results), 'One control pass ran.',
60+
'@count control passes ran.');
5361
}
5462
else {
5563
$message = t('Finished with an error.');
5664
}
5765
drupal_set_message($message);
5866
$_SESSION['qa_results'] = $results;
59-
drupal_goto('admin/reports/qa/results');
67+
return new RedirectResponse(Url::fromRoute('qa.reports.results'));
6068
}
6169

6270
/**
@@ -66,37 +74,41 @@ function qa_report_finished($success, $results, $operations) {
6674
*/
6775
function qa_report_results() {
6876
if (empty($_SESSION['qa_results'])) {
69-
drupal_goto('admin/reports/qa');
77+
return new RedirectResponse(Url::fromRoute('qa.reports'));
7078
}
7179
// Work around incomplete classes
7280
$results = unserialize(serialize($_SESSION['qa_results']));
7381

74-
$header = array(
82+
$header = [
7583
t('Control'),
7684
t('Status'),
7785
t('Results'),
78-
);
79-
$data = array();
86+
];
87+
$data = [];
88+
$r = Drupal::service('renderer');
8089
foreach ($results as $pass) {
8190
$control = $pass->control;
82-
$data[] = array(
91+
$data[] = [
8392
$control->title,
8493
$pass->status
85-
? theme('image', array(
86-
'path' => 'misc/watchdog-ok.png',
87-
'alt' => t('OK'),
88-
))
89-
: theme('image', array(
90-
'path' => 'misc/watchdog-error.png',
91-
'alt' => t('Error'),
92-
)),
94+
? $r->render([
95+
'#theme' => 'image',
96+
'#path' => 'misc/watchdog-ok.png',
97+
'#alt' => t('OK'),
98+
])
99+
: $r->render([
100+
'#theme' => 'image',
101+
'#path' => 'misc/watchdog-error.png',
102+
'#alt' => t('Error'),
103+
]),
93104
$pass->result,
94-
);
105+
];
95106
}
96-
$ret = theme('table', [
97-
'header' => $header,
98-
'rows' => $data,
99-
'attributes' => [
107+
$ret = $r->render([
108+
'#theme' => 'table',
109+
'#header' => $header,
110+
'#rows' => $data,
111+
'#attributes' => [
100112
'id' => 'qa-results',
101113
],
102114
'#attached' => ['library' => ['qa/results']],
@@ -111,19 +123,20 @@ function qa_report_results() {
111123
* @return array
112124
*/
113125
function qa_report_form($form, $form_state) {
114-
$form = array();
126+
$form = [];
115127
$base = drupal_get_path('module', 'qa');
116128
$packages = Exportable::getClasses($base, 'Drupal\qa\BasePackage');
117129
ksort($packages);
118130
foreach ($packages as $package_name => $package) {
119131
$collapsed = TRUE;
120-
$form[$package_name] = array(
132+
$form[$package_name] = [
121133
'#type' => 'fieldset',
122-
'#title' => filter_xss_admin($package->title),
123-
'#description' => filter_xss_admin($package->description),
134+
'#title' => Xss::filterAdmin($package->title),
135+
'#description' => Xss::filterAdmin($package->description),
124136
'#collapsible' => TRUE,
125-
);
126-
$controls = $package->getClasses($package->dir, 'Drupal\qa\Plugin\Qa\Control\BaseControl');
137+
];
138+
$controls = $package->getClasses($package->dir,
139+
'Drupal\qa\Plugin\Qa\Control\BaseControl');
127140

128141
foreach ($controls as $control_name => $control) {
129142
$default_value = isset($_SESSION[$control_name])
@@ -133,37 +146,39 @@ function qa_report_form($form, $form_state) {
133146
$collapsed = FALSE;
134147
}
135148

136-
$deps = array();
149+
$deps = [];
137150
$met = TRUE;
138151
foreach ($control->getDependencies() as $dep_name) {
139-
if (module_exists($dep_name)) {
140-
$deps[] = t('@module (<span class="admin-enabled">available</span>)', array('@module' => $dep_name));
152+
if (Drupal::moduleHandler()->moduleExists($dep_name)) {
153+
$deps[] = t('@module (<span class="admin-enabled">available</span>)',
154+
['@module' => $dep_name]);
141155
}
142156
else {
143-
$deps[] = t('@module (<span class="admin-disabled">unavailable</span>)', array('@module' => $dep_name));
157+
$deps[] = t('@module (<span class="admin-disabled">unavailable</span>)',
158+
['@module' => $dep_name]);
144159
$met = FALSE;
145160
}
146161
}
147-
$form[$package_name][$control_name] = array(
148-
'#type' => 'checkbox',
162+
$form[$package_name][$control_name] = [
163+
'#type' => 'checkbox',
149164
'#default_value' => $met ? $default_value : 0,
150-
'#title' => filter_xss_admin($control->title),
151-
'#description' => filter_xss_admin($control->description),
152-
'#disabled' => !$met,
153-
);
154-
$form[$package_name][$control_name .'-dependencies'] = array(
155-
'#value' => t('Depends on: !dependencies', array(
165+
'#title' => Xss::filterAdmin($control->title),
166+
'#description' => Xss::filterAdmin($control->description),
167+
'#disabled' => !$met,
168+
];
169+
$form[$package_name][$control_name . '-dependencies'] = [
170+
'#value' => t('Depends on: !dependencies', [
156171
'!dependencies' => implode(', ', $deps),
157-
)),
172+
]),
158173
'#prefix' => '<div class="admin-dependencies">',
159174
'#suffix' => '</div>',
160-
);
175+
];
161176
}
162177
$form[$package_name]['#collapsed'] = $collapsed;
163178
}
164179

165180
$form['submit'] = [
166-
'#type' => 'submit',
181+
'#type' => 'submit',
167182
'#value' => t('Run controls'),
168183
];
169184

@@ -177,37 +192,40 @@ function qa_report_form($form, $form_state) {
177192
* @param array $form_state
178193
*/
179194
function qa_report_form_submit($form, &$form_state) {
180-
$controls = array();
195+
$controls = [];
181196
foreach ($form_state['values'] as $item => $value) {
182-
if (class_exists($item) && is_subclass_of($item, '\Drupal\qa\Plugin\Qa\Control\BaseControl')) {
197+
if (class_exists($item) && is_subclass_of($item,
198+
'\Drupal\qa\Plugin\Qa\Control\BaseControl')) {
183199
if ($value) {
184200
$controls[$item] = $value;
185201
}
186202
$_SESSION[$item] = $value;
187203
}
188204
elseif ($value == 1) {
189-
$args = array(
205+
$args = [
190206
'%control' => $item,
191-
);
192-
drupal_set_message(t('Requested invalid control %control', $args), 'error');
193-
watchdog('qa', 'Requested invalid control %control', $args, WATCHDOG_ERROR);
207+
];
208+
drupal_set_message(t('Requested invalid control %control', $args),
209+
'error');
210+
\Drupal::logger('qa')->error('Requested invalid control %control', $args);
194211
}
195212
}
196213

197-
drupal_set_message(t('Prepare to run these controls: @controls', array(
198-
'@controls' => implode(', ', array_keys($controls)))), 'status');
199-
$batch = array(
200-
'operations' => array(),
201-
'title' => t('QA Controls running'),
202-
'init_message' => t('QA Controls initializing'),
214+
drupal_set_message(t('Prepare to run these controls: @controls', [
215+
'@controls' => implode(', ', array_keys($controls)),
216+
]), 'status');
217+
$batch = [
218+
'operations' => [],
219+
'title' => t('QA Controls running'),
220+
'init_message' => t('QA Controls initializing'),
203221
// 'progress_message' => t('current: @current, Remaining: @remaining, Total: @total'),
204-
'error_message' => t('Error in QA Control'),
205-
'finished' => 'qa_report_finished',
222+
'error_message' => t('Error in QA Control'),
223+
'finished' => 'qa_report_finished',
206224
// 'file' => '', // only if outside module file
207-
);
225+
];
208226

209227
foreach ($controls as $item => $value) {
210-
$batch['operations'][] = array('qa_report_run_pass', array($item));
228+
$batch['operations'][] = ['qa_report_run_pass', [$item]];
211229
}
212230
batch_set($batch);
213231
}
@@ -218,23 +236,29 @@ function qa_report_form_submit($form, &$form_state) {
218236
* @return void
219237
*/
220238
function qa_report_run_pass($class_name, &$context) {
221-
$name_arg = array('@class' => $class_name);
239+
$name_arg = ['@class' => $class_name];
222240

223241
$control = new $class_name();
224242
if (!is_object($control)) {
225-
drupal_set_message(t('Cannot obtain an instance for @class', $name_arg), 'error');
226-
$context['results']['#message'] = t('Control @class failed to run.', $name_arg);
243+
drupal_set_message(t('Cannot obtain an instance for @class', $name_arg),
244+
'error');
245+
$context['results']['#message'] = t('Control @class failed to run.',
246+
$name_arg);
227247
$context['message'] = t('Control @class failed to run.', $name_arg);
228248
$context['results'][$class_name] = 'wow';
229249
}
230250
else {
231-
drupal_set_message(t('Running a control instance for @class', $name_arg), 'status');
251+
drupal_set_message(t('Running a control instance for @class', $name_arg),
252+
'status');
232253
$pass = $control->run();
233254
if (!$pass->status) {
234255
$context['success'] = FALSE;
235256
}
236257
$context['results']['#message'][] = t('Control @class ran', $name_arg);
237-
$context['message'] = theme('item_list', $context['results']['#message']);
258+
$context['message'] = \Drupal::service('renderer')->render([
259+
'#theme' => 'item_list',
260+
'#items' => $context['results']['#message'],
261+
]);
238262
$context['results'][$class_name] = $pass;
239263
}
240264
}

qa.services.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
services:
22
plugin.manager.qa_check:
33
class: Drupal\qa\Plugin\QaCheckManager
4+
arguments:
5+
- '@kernel'
46
parent: default_plugin_manager
57

68
logger.channel.qa:

0 commit comments

Comments
 (0)