Skip to content

Commit aeb90fc

Browse files
committed
Issue #6: fix a bunch of Scrutinizer issues.
1 parent 0bc613d commit aeb90fc

File tree

11 files changed

+48
-76
lines changed

11 files changed

+48
-76
lines changed

src/Controller/CheckListController.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(QaCheckManager $qam) {
3636
*/
3737
public static function create(ContainerInterface $container) {
3838
$qam = $container->get(Data::MANAGER);
39+
assert($qam instanceof QaCheckManager);
3940
return new static($qam);
4041
}
4142

@@ -81,20 +82,4 @@ public function report() {
8182
return $checks;
8283
}
8384

84-
/**
85-
* Placeholder controller for "view".
86-
*
87-
* @param string $qaVariable
88-
* The variable to view.
89-
*
90-
* @return array
91-
* A render array.
92-
*/
93-
public function view($qaVariable) {
94-
return [
95-
'#type' => 'markup',
96-
'#markup' => $this->t('Implement method: view'),
97-
];
98-
}
99-
10085
}

src/Controller/DependenciesReportController.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,13 @@ class DependenciesReportController extends ControllerBase {
1212
/**
1313
* Action.
1414
*
15-
* @return string
16-
* Return Hello string.
17-
*/
18-
public function report() {
19-
return [
20-
'#type' => 'markup',
21-
'#markup' => $this->t('Implement method: report'),
22-
];
23-
}
24-
25-
/**
26-
* Placeholder controller for "dependencies".
27-
*
28-
* @param string $qaVariable
29-
* The variable name.
30-
*
3115
* @return array
3216
* A render array.
3317
*/
34-
public function view($qaVariable) {
18+
public function report() {
3519
return [
3620
'#type' => 'markup',
37-
'#markup' => $this->t('Implement method: view'),
21+
'#markup' => $this->t('Implement method: report'),
3822
];
3923
}
4024

src/Controller/ProjectsReportController.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function __construct(
4242

4343
public static function create(ContainerInterface $container) {
4444
$updateManager = $container->get('update.manager');
45+
assert($updateManager instanceof UpdateManagerInterface);
4546
$kve = $container->get('keyvalue.expirable');
47+
assert($kve instanceof KeyValueExpirableFactoryInterface);
4648
return new static($updateManager, $kve);
4749
}
4850

@@ -111,15 +113,15 @@ private final function qa_report_project(Variable $variable = NULL) {
111113
$bc[] = l($this->t('Variables'), 'admin/reports/qa/variable');
112114
drupal_set_breadcrumb($bc);
113115

114-
drupal_set_title($this->t('Variable: %name', ['%name' => $variable->name]),
115-
PASS_THROUGH);
116+
drupal_set_title($this->t('Variable: %name', ['%name' => $variable->name]), ['passthrough' => TRUE]);
116117
return $variable->dump();
117118
}
118119

119120
/**
120121
* Page callback for projects list.
121122
*
122-
* @return string
123+
* @return array
124+
* A render array.
123125
*
124126
* @FIXME This still uses the D7 info structure.
125127
*
@@ -187,9 +189,11 @@ private final function qa_report_projects() {
187189
$rows[] = $row;
188190
}
189191
}
190-
return theme('table', [
191-
'header' => $header,
192-
'rows' => $rows,
193-
]);
192+
return [
193+
'#theme' => 'table',
194+
'#header' => $header,
195+
'#rows' => $rows,
196+
];
194197
}
198+
195199
}

src/Controller/ResultsReportController.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,13 @@ class ResultsReportController extends ControllerBase {
1414
/**
1515
* Action.
1616
*
17-
* @return string
18-
* Return Hello string.
19-
*/
20-
public function report() {
21-
return [
22-
'#type' => 'markup',
23-
'#markup' => $this->t('Implement method: report'),
24-
];
25-
}
26-
27-
/**
28-
* Placeholder controller for "results".
29-
*
30-
* @param string $qaVariable
31-
* The variable name.
32-
*
3317
* @return array
3418
* A render array.
3519
*/
36-
public function view($qaVariable) {
20+
public function report() {
3721
return [
3822
'#type' => 'markup',
39-
'#markup' => $this->t('Implement method: view'),
23+
'#markup' => $this->t('Implement method: report'),
4024
];
4125
}
4226

src/Controller/VariablesReportController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class VariablesReportController extends ControllerBase {
1414
/**
1515
* Action.
1616
*
17-
* @return string
18-
* Return Hello string.
17+
* @return array
18+
* A render array.
1919
*/
2020
public function report() {
2121
return [

src/Plugin/Qa/Control/BaseControl.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\qa\Plugin\Qa\Control;
44

55
use Drupal\Component\Utility\Crypt;
6+
use Drupal\Core\PrivateKey;
67
use Drupal\qa\Exportable;
78
use Drupal\qa\Pass;
89
use Drupal\qa\Plugin\QaCheckInterface;
@@ -49,19 +50,32 @@ abstract class BaseControl extends Exportable implements QaCheckInterface {
4950
*/
5051
protected static $packages = [];
5152

53+
/**
54+
* The private_key service.
55+
*
56+
* @var \Drupal\Core\PrivateKey
57+
*/
58+
protected $pk;
59+
5260
/**
5361
* BaseControl constructor.
62+
*
63+
* @param \Drupal\Core\PrivateKey $pk
64+
* The private_ket service.
5465
*/
55-
public function __construct() {
66+
public function __construct(PrivateKey $pk) {
5667
parent::__construct();
5768
$this->package_name = $this->namespace;
69+
$this->pk = $pk;
5870
}
5971

6072
/**
6173
* {@inheritdoc}
6274
*/
6375
public static function create(ContainerInterface $container) {
64-
return new static();
76+
$pk = $container->get('private_key');
77+
assert($pk instanceof PrivateKey);
78+
return new static($pk);
6579
}
6680

6781
/**
@@ -141,7 +155,7 @@ public static function getControls($package_name = NULL) {
141155
*/
142156
public function run(): Pass {
143157
global $base_url;
144-
$site_key = Crypt::hmacBase64($base_url, \Drupal::service('private_key')->get());
158+
$site_key = Crypt::hmacBase64($base_url, $this->pk->get());
145159
$key = uniqid($site_key);
146160
$pass = new Pass($this);
147161
$this->passes[$key] = $pass;

src/Plugin/Qa/Control/I18n/Variables.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function init() {
3737
/**
3838
* Identify variables translations for languages not currently on site
3939
*/
40-
function checkExtra() {
40+
public function checkExtra() {
4141
$languages = array_keys(language_list());
4242
$ph = db_placeholders($languages, 'char');
4343
$sq = <<<sql
@@ -69,7 +69,7 @@ function checkExtra() {
6969
/**
7070
* Identify variables for which at least one translation is missing
7171
*/
72-
function checkMissing() {
72+
public function checkMissing() {
7373
$languages = array_keys(language_list());
7474
$ph = db_placeholders($languages, 'char');
7575
$sq = <<<sql
@@ -102,12 +102,12 @@ function checkMissing() {
102102
return $ret;
103103
}
104104

105-
static function getDependencies(): array {
105+
public static function getDependencies(): array {
106106
$ret = ['i18n']; // introduces {i18n_variable}
107107
return $ret;
108108
}
109109

110-
function run(): Pass {
110+
public function run(): Pass {
111111
$pass = parent::run();
112112
$pass->record($this->checkExtra());
113113
$pass->life->modify();

src/Plugin/Qa/Control/Taxonomy/Freetagging.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\qa\Taxonomy;
44

5+
use Drupal\Core\PrivateKey;
56
use Drupal\qa\Pass;
67
use Drupal\qa\Plugin\Qa\Control\BaseControl;
78

@@ -13,8 +14,8 @@ class Freetagging extends BaseControl {
1314
/**
1415
* {@inheritdoc]
1516
*/
16-
public function __construct() {
17-
parent::__construct();
17+
public function __construct(PrivateKey $pk) {
18+
parent::__construct($pk);
1819
$this->package_name = __NAMESPACE__;
1920
}
2021

@@ -40,7 +41,7 @@ public function init() {
4041
*
4142
* @return array
4243
*/
43-
function checkTags($vocabulary) {
44+
public function checkTags($vocabulary) {
4445
$sq = <<<sql
4546
SELECT td.tid
4647
FROM {taxonomy_term_data} td
@@ -69,7 +70,7 @@ function checkTags($vocabulary) {
6970
return $ret;
7071
}
7172

72-
function run(): Pass {
73+
public function run(): Pass {
7374
$pass = parent::run();
7475
$vocabularies = taxonomy_get_vocabularies();
7576
foreach ($vocabularies as $vocabulary) {

src/Plugin/Qa/Control/Views/Overrides.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function init() {
1515
$this->description = t('Have any views been overridden or only created in the DB ? This is a performance and change management issue.');
1616
}
1717

18-
function checkViewType($view) {
18+
public function checkViewType($view) {
1919
$status = $view->type == t('Default') ? 1 : 0;
2020
if (!$status) {
2121
$name = empty($view->human_name) ? $view->name : $view->human_name;
@@ -37,7 +37,7 @@ function checkViewType($view) {
3737
return $ret;
3838
}
3939

40-
function run(): Pass {
40+
public function run(): Pass {
4141
$pass = parent::run();
4242
$views = views_get_all_views(TRUE);
4343
foreach ($views as $view) {

src/Plugin/Qa/Control/Views/Php.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function getPhpFormats($reset = FALSE) {
116116
return $php;
117117
}
118118

119-
function run(): Pass {
119+
public function run(): Pass {
120120
$pass = parent::run();
121121
$views = views_get_all_views(TRUE);
122122
foreach ($views as $view) {

0 commit comments

Comments
 (0)