Skip to content

Commit 70ca003

Browse files
committed
Fix loadModel was removed and fix redirect should be used with a return
1 parent bbc61c6 commit 70ca003

11 files changed

Lines changed: 94 additions & 79 deletions

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
"composer/ca-bundle": "^1.3"
2727
},
2828
"require-dev": {
29+
"cakedc/cakephp-phpstan": "^4",
2930
"cakephp/bake": "^3.6",
30-
"cakephp/debug_kit": "^5.2",
31+
"cakephp/debug_kit": "^5.0",
3132
"php-mock/php-mock-phpunit": "^2.6",
3233
"phpmyadmin/coding-standard": "^3",
3334
"phpstan/phpstan": "^2",

src/Controller/AppController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
*
4040
* @see http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
4141
*
42-
* @property NotificationsTable $Notifications
43-
* @property DevelopersTable $Developers
4442
*/
4543
class AppController extends Controller
4644
{
45+
protected NotificationsTable $Notifications;
46+
protected DevelopersTable $Developers;
47+
4748
/** @var array */
4849
public $whitelist = [
4950
'Developers',
@@ -114,8 +115,9 @@ public function initialize(): void
114115
{
115116
parent::initialize();
116117
$this->loadComponent('Flash');
117-
$this->loadModel('Notifications');
118-
$this->loadModel('Developers');
118+
$this->Notifications = $this->fetchTable('Notifications');
119+
$this->Developers = $this->fetchTable('Developers');
120+
119121
/* $this->loadComponent(
120122
'Auth', [
121123
'loginAction' => [

src/Controller/DevelopersController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function callback(): ?Response
103103
return $this->redirect($last_page);
104104
}
105105

106-
public function logout(): void
106+
public function logout(): Response
107107
{
108108
$this->request->getSession()->destroy();
109109

@@ -112,7 +112,7 @@ public function logout(): void
112112
'You have been logged out successfully',
113113
['params' => ['class' => $flash_class]]
114114
);
115-
$this->redirect('/');
115+
return $this->redirect('/');
116116
}
117117

118118
protected function authenticateDeveloper(array $userInfo, string $accessToken): void

src/Controller/GithubController.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Cake\Log\Log;
2525
use Cake\ORM\TableRegistry;
2626
use Cake\Routing\Router;
27+
use Cake\Http\Response;
2728
use InvalidArgumentException;
2829

2930
use function __;
@@ -63,12 +64,11 @@ public function initialize(): void
6364
* @param int $reportId The report number
6465
*
6566
* @throws NotFoundException
66-
* @return void Nothing
6767
*/
68-
public function create_issue($reportId): void
68+
public function create_issue($reportId): ?Response
6969
{
7070
if (empty($reportId)) {
71-
throw new NotFoundException(__('Invalid report Id.'));
71+
throw new NotFoundException('Invalid report Id.');
7272
}
7373

7474
$reportId = (int) $reportId;
@@ -77,15 +77,15 @@ public function create_issue($reportId): void
7777
$report = $reportsTable->findById($reportId)->all()->first();
7878

7979
if (! $report) {
80-
throw new NotFoundException(__('The report does not exist.'));
80+
throw new NotFoundException('The report does not exist.');
8181
}
8282

8383
$reportArray = $report->toArray();
8484
if (empty($this->request->getParsedBody())) {
8585
$this->set('error_name', $reportArray['error_name']);
8686
$this->set('error_message', $reportArray['error_message']);
8787

88-
return;
88+
return null;
8989
}
9090

9191
$this->disableAutoRender();
@@ -113,7 +113,7 @@ public function create_issue($reportId): void
113113
$report->status = $this->getReportStatusFromIssueState($issueDetails['state']);
114114
$reportsTable->save($report);
115115

116-
$this->redirect([
116+
return $this->redirect([
117117
'_name' => 'reports:view',
118118
'id' => $reportId,
119119
]);
@@ -123,6 +123,7 @@ public function create_issue($reportId): void
123123
$this->getErrors($issueDetails, $status),
124124
['params' => ['class' => $flash_class]]
125125
);
126+
return null;
126127
}
127128
}
128129

@@ -136,7 +137,7 @@ public function create_issue($reportId): void
136137
public function link_issue($reportId): void
137138
{
138139
if (empty($reportId)) {
139-
throw new NotFoundException(__('Invalid report Id.'));
140+
throw new NotFoundException('Invalid report Id.');
140141
}
141142

142143
$reportId = (int) $reportId;
@@ -145,12 +146,12 @@ public function link_issue($reportId): void
145146
$report = $reportsTable->findById($reportId)->all()->first();
146147

147148
if (! $report) {
148-
throw new NotFoundException(__('The report does not exist.'));
149+
throw new NotFoundException('The report does not exist.');
149150
}
150151

151152
$ticket_id = intval($this->request->getQuery('ticket_id'));
152153
if (! $ticket_id) {
153-
throw new NotFoundException(__('Invalid Ticket ID!!'));
154+
throw new NotFoundException('Invalid Ticket ID!!');
154155
}
155156

156157
$reportArray = $report->toArray();
@@ -195,7 +196,7 @@ public function link_issue($reportId): void
195196
);
196197
}
197198

198-
$this->redirect([
199+
return $this->redirect([
199200
'_name' => 'reports:view',
200201
'id' => $reportId,
201202
]);
@@ -206,12 +207,11 @@ public function link_issue($reportId): void
206207
*
207208
* @param int $reportId The report Id
208209
* @throws NotFoundException
209-
* @return void Nothing
210210
*/
211-
public function unlink_issue($reportId): void
211+
public function unlink_issue($reportId): Response
212212
{
213213
if (empty($reportId)) {
214-
throw new NotFoundException(__('Invalid report Id.'));
214+
throw new NotFoundException('Invalid report Id.');
215215
}
216216

217217
$reportId = (int) $reportId;
@@ -220,14 +220,14 @@ public function unlink_issue($reportId): void
220220
$report = $reportsTable->findById($reportId)->all()->first();
221221

222222
if (! $report) {
223-
throw new NotFoundException(__('The report does not exist.'));
223+
throw new NotFoundException('The report does not exist.');
224224
}
225225

226226
$reportArray = $report->toArray();
227227
$ticket_id = $reportArray['sourceforge_bug_id'];
228228

229229
if (! $ticket_id) {
230-
throw new NotFoundException(__('Invalid Ticket ID!!'));
230+
throw new NotFoundException('Invalid Ticket ID!!');
231231
}
232232

233233
// "formatted" text of the comment.
@@ -260,7 +260,7 @@ public function unlink_issue($reportId): void
260260
);
261261
}
262262

263-
$this->redirect([
263+
return $this->redirect([
264264
'_name' => 'reports:view',
265265
'id' => $reportId,
266266
]);
@@ -487,9 +487,8 @@ protected function getReportStatusFromIssueState(string $issueState): string
487487
*
488488
* Can not (& should not) be directly accessed via web.
489489
*
490-
* @return void Nothing
491490
*/
492-
public function sync_issue_status(): void
491+
public function sync_issue_status(): ?Response
493492
{
494493
if (! Configure::read('CronDispatcher')) {
495494
$flash_class = 'alert alert-error';
@@ -498,9 +497,7 @@ public function sync_issue_status(): void
498497
['params' => ['class' => $flash_class]]
499498
);
500499

501-
$this->redirect('/');
502-
503-
return;
500+
return $this->redirect('/');
504501
}
505502

506503
$this->disableAutoRender();
@@ -556,5 +553,7 @@ public function sync_issue_status(): void
556553
['scope' => 'cron_jobs']
557554
);
558555
}
556+
557+
return null;
559558
}
560559
}

src/Controller/IncidentsController.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
/**
4242
* Incidents controller handling incident creation and rendering.
4343
*
44-
* @property NotificationsTable $Notifications
45-
* @property IncidentsTable $Incidents
46-
* @property ReportsTable $Reports
4744
*/
4845
class IncidentsController extends AppController
4946
{
47+
protected NotificationsTable $Notifications;
48+
protected IncidentsTable $Incidents;
49+
protected ReportsTable $Reports;
50+
5051
/**
5152
* Initialization hook method.
5253
*
@@ -58,8 +59,9 @@ public function initialize(): void
5859
{
5960
parent::initialize();
6061
$this->loadComponent('Mailer');
61-
$this->loadModel('Notifications');
62-
$this->loadModel('Incidents');
62+
$this->Notifications = $this->fetchTable('Notifications');
63+
$this->Incidents = $this->fetchTable('Incidents');
64+
$this->Reports = $this->fetchTable('Reports');
6365
}
6466

6567
public function create(): ?Response
@@ -114,13 +116,13 @@ public function create(): ?Response
114116
public function json(?string $id): ?Response
115117
{
116118
if (empty($id)) {
117-
throw new NotFoundException(__('Invalid Incident'));
119+
throw new NotFoundException('Invalid Incident');
118120
}
119121

120122
$this->Incidents->recursive = -1;
121123
$incident = $this->Incidents->findById($id)->all()->first();
122124
if (! $incident) {
123-
throw new NotFoundException(__('The incident does not exist.'));
125+
throw new NotFoundException('The incident does not exist.');
124126
}
125127

126128
$incident['full_report'] =
@@ -138,14 +140,14 @@ public function json(?string $id): ?Response
138140
public function view(?string $incidentId): void
139141
{
140142
if (empty($incidentId)) {
141-
throw new NotFoundException(__('Invalid Incident'));
143+
throw new NotFoundException('Invalid Incident');
142144
}
143145

144146
$incidentId = (int) $incidentId;
145147

146148
$incident = $this->Incidents->findById($incidentId)->all()->first();
147149
if (! $incident) {
148-
throw new NotFoundException(__('The incident does not exist.'));
150+
throw new NotFoundException('The incident does not exist.');
149151
}
150152

151153
$incident['full_report'] =

src/Controller/NotificationsController.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
namespace App\Controller;
2020

21+
use App\Model\Table\NotificationsTable;
22+
use App\Model\Table\DevelopersTable;
23+
use App\Model\Table\ReportsTable;
2124
use Cake\Event\EventInterface;
2225
use Cake\Http\Response;
2326
use Cake\ORM\TableRegistry;
@@ -32,6 +35,10 @@
3235
*/
3336
class NotificationsController extends AppController
3437
{
38+
protected NotificationsTable $Notifications;
39+
protected DevelopersTable $Developers;
40+
protected ReportsTable $Reports;
41+
3542
/**
3643
* Initialization hook method.
3744
*
@@ -49,9 +56,9 @@ public function initialize(): void
4956
'Form',
5057
'Reports',
5158
]);
52-
$this->loadModel('Notifications');
53-
$this->loadModel('Developers');
54-
$this->loadModel('Reports');
59+
$this->Notifications = $this->fetchTable('Notifications');
60+
$this->Developers = $this->fetchTable('Developers');
61+
$this->Reports = $this->fetchTable('Reports');
5562
}
5663

5764
public function beforeFilter(EventInterface $event)
@@ -153,10 +160,8 @@ public function data_tables(): Response
153160
* Currently it deletes them (marks them "read").
154161
* Can be Extended for other mass operations as well.
155162
* Expects an array of Notification Ids as a POST parameter.
156-
*
157-
* @return void Nothing
158163
*/
159-
public function mass_action(): void
164+
public function mass_action(): Response
160165
{
161166
$msg = 'Selected Notifications have been marked \'Read\'!';
162167
$flash_class = 'alert alert-success';
@@ -184,6 +189,6 @@ public function mass_action(): void
184189
$msg,
185190
['params' => ['class' => $flash_class]]
186191
);
187-
$this->redirect('/notifications/');
192+
return $this->redirect('/notifications/');
188193
}
189194
}

0 commit comments

Comments
 (0)