Skip to content

Commit

Permalink
Default final readonly classes [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Feb 20, 2024
1 parent 6932fd7 commit f111d40
Show file tree
Hide file tree
Showing 85 changed files with 142 additions and 142 deletions.
2 changes: 1 addition & 1 deletion config/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function html(?string $text = null): string
* If a context is provided, it is used to replace placeholders
* in the translated string.
*
* @param string $message the message to be translated
* @param string $message the message to be translated (may contain sprintf placeholders e.g. %s, %d)
* @param mixed ...$context Optional elements that should be inserted in the string with placeholders.
* The function can be called like this:
* __('The %s contains %d monkeys and %d birds.', 'tree', 5, 3);
Expand Down
9 changes: 4 additions & 5 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
->setName('dashboard-toggle-panel');

$app->get('/login', \App\Application\Action\Authentication\Page\LoginPageAction::class)->setName('login-page');
$app->post('/login', \App\Application\Action\Authentication\Ajax\LoginSubmitAction::class)->setName(
'login-submit'
);
$app->post('/login', \App\Application\Action\Authentication\Ajax\LoginSubmitAction::class)
->setName('login-submit');
$app->get('/logout', \App\Application\Action\Authentication\Page\LogoutPageAction::class)->setName('logout')->add(
\Odan\Session\Middleware\SessionStartMiddleware::class
);
Expand All @@ -50,10 +49,10 @@
'/password-forgotten',
\App\Application\Action\Authentication\Ajax\PasswordForgottenEmailSubmitAction::class
)->setName('password-forgotten-email-submit');
// Set new password page after clicking on email link with token
// Set the new password page after clicking on email link with token
$app->get('/reset-password', \App\Application\Action\Authentication\Page\PasswordResetPageAction::class)
->setName('password-reset-page');
// Submit new password (reset-password hardcoded in login-main.js)
// Submit new password after clicking on email link with token (reset-password hardcoded in login-main.js)
$app->post(
'/reset-password',
\App\Application\Action\Authentication\Ajax\NewPasswordResetSubmitAction::class
Expand Down
2 changes: 1 addition & 1 deletion docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ found [here](https://github.com/samuelgfeller/slim-example-project/blob/master/s
namespace App\Application\ErrorHandler;
use App\Domain\Validation\ValidationException;use Fig\Http\Message\StatusCodeInterface;use Psr\Http\Message\ResponseFactoryInterface;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface;use Psr\Log\LoggerInterface;use Slim\Exception\HttpException;use Slim\Views\PhpRenderer;use Throwable;

readonly class DefaultErrorHandler
final readonly class DefaultErrorHandler
{

public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion docs/technical-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Lets say we expect the required elements `name`,`email`,`password`,`password2`
Get elements from request as array and give this data to the corresponding validation class which
will return the result
```php
public function register(Request $request, Response $response): Response
public function register(Request $request, ResponseInterface $response): Response
{
$parsedBody = $request->getParsedBody();
$validationResult = $this->userValidation->validateUserRegistration($parsedBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use App\Domain\Authentication\Service\AccountUnlockTokenVerifier;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;

Expand All @@ -24,7 +24,7 @@ public function __construct(
) {
}

public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$queryParams = $request->getQueryParams();
$flash = $this->session->getFlash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use App\Domain\Validation\ValidationException;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;

final readonly class LoginSubmitAction
Expand All @@ -29,7 +29,7 @@ public function __construct(
) {
}

public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$flash = $this->session->getFlash();
$submitValues = (array)$request->getParsedBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use App\Domain\Authentication\Service\PasswordResetterWithToken;
use App\Domain\Validation\ValidationException;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;

readonly class NewPasswordResetSubmitAction
final readonly class NewPasswordResetSubmitAction
{
public function __construct(
private TemplateRenderer $templateRenderer,
Expand All @@ -24,16 +24,16 @@ public function __construct(
}

/**
* Check if token is valid and if yes display password form.
* Check if the token is valid and if yes display password form.
*
* @param ServerRequest $request
* @param Response $response
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @return ResponseInterface
* @throws \Throwable
*
* @return Response
*/
public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$parsedBody = (array)$request->getParsedBody();
$flash = $this->session->getFlash();
Expand All @@ -43,7 +43,7 @@ public function __invoke(ServerRequest $request, Response $response): Response

$flash->add(
'success',
sprintf(__('Successfully changed password. <b>%s</b>'), __('Please log in.'))
__('Successfully changed password. <b>%s</b>', __('Please log in.'))
);

return $this->redirectHandler->redirectToRouteName($response, 'login-page');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use App\Domain\Security\Exception\SecurityException;
use App\Domain\Validation\ValidationException;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

Expand All @@ -26,14 +26,14 @@ public function __construct(
}

/**
* @param ServerRequest $request
* @param Response $response
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @throws \Throwable
*
* @return Response
* @return ResponseInterface
*/
public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$flash = $this->session->getFlash();
$userValues = (array)$request->getParsedBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use App\Domain\Authentication\Service\RegisterTokenVerifier;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;
use Slim\Interfaces\RouteParserInterface;
Expand All @@ -26,7 +26,7 @@ public function __construct(
) {
}

public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$queryParams = $request->getQueryParams();
$flash = $this->session->getFlash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use App\Application\Renderer\RedirectHandler;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class LogoutPageAction
{
Expand All @@ -17,7 +17,7 @@ public function __construct(
) {
}

public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Logout user
$this->sessionManager->destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace App\Application\Action\Authentication\Page;

use App\Application\Renderer\TemplateRenderer;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;

readonly class PasswordResetPageAction
final readonly class PasswordResetPageAction
{
public function __construct(
private TemplateRenderer $templateRenderer,
Expand All @@ -18,14 +18,14 @@ public function __construct(
/**
* Check if the token is valid and if yes display password form.
*
* @param ServerRequest $request
* @param Response $response
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @throws \Throwable
*
* @return Response
* @return ResponseInterface
*/
public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$queryParams = $request->getQueryParams();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

readonly class FetchDropdownOptionsForClientCreateAction
final readonly class FetchDropdownOptionsForClientCreateAction
{
public function __construct(
private JsonEncoder $jsonEncoder,
Expand Down
6 changes: 3 additions & 3 deletions src/Application/Action/PreflightAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace App\Application\Action;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class PreflightAction
{
public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Do nothing here. Just return the response.
return $response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

readonly class FetchDropdownOptionsForUserCreateAction
final readonly class FetchDropdownOptionsForUserCreateAction
{
public function __construct(
private JsonEncoder $jsonEncoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use App\Domain\Authentication\Service\PasswordChanger;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* When user wants to change password being authenticated.
*/
readonly class PasswordChangeSubmitAction
final readonly class PasswordChangeSubmitAction
{
public function __construct(
private JsonEncoder $jsonEncoder,
Expand All @@ -22,7 +22,7 @@ public function __construct(
) {
}

public function __invoke(ServerRequest $request, Response $response, array $args): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
$parsedBody = (array)$request->getParsedBody();
$userId = $args['user_id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

readonly class UserActivityFetchListAction
final readonly class UserActivityFetchListAction
{
public function __construct(
private JsonEncoder $jsonEncoder,
Expand Down
10 changes: 5 additions & 5 deletions src/Application/Action/User/Ajax/UserCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use App\Application\Renderer\JsonEncoder;
use App\Domain\User\Service\UserCreator;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

Expand All @@ -19,12 +19,12 @@ public function __construct(
}

/**
* @param ServerRequest $request
* @param Response $response
* @param ServerRequestInterface $request
* @param ResponseInterface $response
*
* @throws \Throwable
*/
public function __invoke(ServerRequest $request, Response $response): Response
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$userValues = (array)$request->getParsedBody();

Expand Down
2 changes: 1 addition & 1 deletion src/Application/ErrorHandler/DefaultErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Slim\Views\PhpRenderer;
use Throwable;

readonly class DefaultErrorHandler
final readonly class DefaultErrorHandler
{
private string $fileSystemPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

readonly class ForbiddenExceptionMiddleware implements MiddlewareInterface
final readonly class ForbiddenExceptionMiddleware implements MiddlewareInterface
{
public function __construct(
private ResponseFactoryInterface $responseFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;

readonly class InvalidOperationExceptionMiddleware implements MiddlewareInterface
final readonly class InvalidOperationExceptionMiddleware implements MiddlewareInterface
{
public function __construct(
private ResponseFactoryInterface $responseFactory,
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Middleware/NonFatalErrorHandlerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
/**
* Handles non-fatal errors such as warnings and notices.
*/
final class NonFatalErrorHandlerMiddleware implements MiddlewareInterface
final readonly class NonFatalErrorHandlerMiddleware implements MiddlewareInterface
{
private bool $displayErrorDetails;
private bool $logErrors;

public function __construct(bool $displayErrorDetails, bool $logErrors, private readonly LoggerInterface $logger)
public function __construct(bool $displayErrorDetails, bool $logErrors, private LoggerInterface $logger)
{
$this->displayErrorDetails = $displayErrorDetails;
$this->logErrors = $logErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Middleware that adds client network data such as IP address and user agent
* as well as user identity id to the clientNetworkData DTO.
*/
readonly class UserNetworkSessionDataMiddleware implements MiddlewareInterface
final readonly class UserNetworkSessionDataMiddleware implements MiddlewareInterface
{
public function __construct(
private UserNetworkSessionData $clientNetworkData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

readonly class ValidationExceptionMiddleware implements MiddlewareInterface
final readonly class ValidationExceptionMiddleware implements MiddlewareInterface
{
public function __construct(
private ResponseFactoryInterface $responseFactory,
Expand Down
Loading

0 comments on commit f111d40

Please sign in to comment.