jidaikobo-shibata /
kontiki-framework
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Jidaikobo\Kontiki\Controllers; |
||
| 4 | |||
| 5 | use Psr\Http\Message\ResponseInterface as Response; |
||
| 6 | use Psr\Http\Message\ServerRequestInterface as Request; |
||
| 7 | use Slim\App; |
||
| 8 | use Slim\Views\PhpRenderer; |
||
| 9 | use Jidaikobo\Kontiki\Core\Auth; |
||
| 10 | use Jidaikobo\Kontiki\Managers\CsrfManager; |
||
| 11 | use Jidaikobo\Kontiki\Managers\FlashManager; |
||
| 12 | use Jidaikobo\Kontiki\Models\AccountModel; |
||
| 13 | use Jidaikobo\Kontiki\Services\FormService; |
||
| 14 | use Jidaikobo\Kontiki\Services\RoutesService; |
||
| 15 | |||
| 16 | class AccountController extends BaseController |
||
| 17 | { |
||
| 18 | use Traits\CreateEditTrait; |
||
| 19 | |||
| 20 | protected string $adminDirName = 'account'; |
||
| 21 | protected string $label = 'account'; |
||
| 22 | private Auth $auth; |
||
| 23 | private FormService $formService; |
||
| 24 | private AccountModel $model; |
||
| 25 | |||
| 26 | protected string $backStringAfterSaveKey = 'x_save_success'; |
||
| 27 | protected string $backStringAfterSave = ':name Saved successfully.'; |
||
| 28 | |||
| 29 | public function __construct( |
||
| 30 | CsrfManager $csrfManager, |
||
| 31 | FlashManager $flashManager, |
||
| 32 | PhpRenderer $view, |
||
| 33 | RoutesService $routesService, |
||
| 34 | Auth $auth, |
||
| 35 | FormService $formService, |
||
| 36 | AccountModel $model |
||
| 37 | ) { |
||
| 38 | parent::__construct( |
||
| 39 | $csrfManager, |
||
| 40 | $flashManager, |
||
| 41 | $view, |
||
| 42 | $routesService |
||
| 43 | ); |
||
| 44 | $this->auth = $auth; |
||
| 45 | $this->formService = $formService; |
||
| 46 | $this->formService->setModel($model); |
||
| 47 | $this->model = $model; |
||
| 48 | } |
||
| 49 | |||
| 50 | public static function registerRoutes(App $app, string $basePath = ''): void |
||
| 51 | { |
||
| 52 | $app->get('/account/settings', AccountController::class . ':handleRenderEditForm'); |
||
| 53 | $app->post("/account/edit/{id}", AccountController::class . ':handleEdit'); |
||
| 54 | |||
| 55 | // redirect |
||
| 56 | $app->get('/account/index', AccountController::class . ':accoutEditRedirect'); |
||
| 57 | $app->get("/account/edit/{id}", AccountController::class . ':accoutEditRedirect'); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function accoutEditRedirect( |
||
| 61 | Request $request, |
||
| 62 | Response $response, |
||
| 63 | array $args |
||
|
0 ignored issues
–
show
|
|||
| 64 | ): Response { |
||
| 65 | return $this->redirectResponse( |
||
| 66 | $request, |
||
| 67 | $response, |
||
| 68 | "/account/settings" |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function handleRenderEditForm( |
||
| 73 | Request $request, |
||
| 74 | Response $response, |
||
| 75 | array $args |
||
| 76 | ): Response { |
||
| 77 | $args['id'] = $this->auth->getCurrentUser()['id'] ?? 0; |
||
| 78 | if ($args['id'] == 0) { |
||
| 79 | die(); |
||
|
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return Psr\Http\Message\ResponseInterface. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
Loading history...
|
|||
| 80 | } |
||
| 81 | return $this->renderEditForm($request, $response, $args); |
||
| 82 | } |
||
| 83 | |||
| 84 | public function handleEdit( |
||
| 85 | Request $request, |
||
| 86 | Response $response, |
||
| 87 | array $args |
||
| 88 | ): Response { |
||
| 89 | $id = $args['id']; |
||
| 90 | return $this->handleSave($request, $response, 'edit', $id); |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.