Skip to content

Commit bbb2973

Browse files
committed
Improve auth middleware logic
1 parent 064d35e commit bbb2973

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ parameters:
108108
count: 1
109109
path: src/Controller/DevelopersController.php
110110

111-
-
112-
message: '#^Method `redirect\(\)` must be used to prevent unreachable code\. Use `return \$this\-\>redirect\(\)` or assign it to a variable\.$#'
113-
identifier: cake.controller.redirectMustBeUsed
114-
count: 1
115-
path: src/Controller/DevelopersController.php
116-
117111
-
118112
message: '#^Parameter \#1 \$payload of method App\\Controller\\EventsController\:\:getHash\(\) expects string, string\|false given\.$#'
119113
identifier: argument.type

src/Middleware/AuthenticationMiddleware.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,19 @@ protected function isWriteAccessRequired(ServerRequest $request): bool
134134

135135
// Check for the controller name
136136
if (! isset(self::READ_ONLY_ACCESS_CONTROL_LIST[$controllerName])) {
137-
// Not public
138-
return false;
137+
return false;// The controller is not in the list
139138
}
140139

141140
// Require for all actions ?
142141
if (self::READ_ONLY_ACCESS_CONTROL_LIST[$controllerName] === '*') {
143-
return true;
142+
return true;// Needs write access
144143
}
145144

146145
// Check for the specific action name
147-
return in_array($action, self::READ_ONLY_ACCESS_CONTROL_LIST[$controllerName]);
146+
if (in_array($action, self::READ_ONLY_ACCESS_CONTROL_LIST[$controllerName])) {// phpcs:ignore SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn.UselessIfCondition
147+
return true;// Needs write access
148+
}
149+
150+
return false;// phpcs:ignore SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn.UselessIfCondition
148151
}
149152
}

0 commit comments

Comments
 (0)