Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRadu committed Jun 16, 2024
1 parent 4daef72 commit 82266ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/App/src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ class Message
public const INVALID_CLIENT_ID = 'Invalid client_id.';
public const INVALID_CONFIG = 'Invalid configuration value: \'%s\'';
public const INVALID_VALUE = 'The value specified for \'%s\' is invalid.';
public const MAIL_NOT_SENT_TO = 'Could not send mail to \'%s\'.';

public const MAIL_SENT_RECOVER_IDENTITY = 'If the provided email identifies an account in our system, '
. 'you will receive an email with your account\'s identity.';
public const MAIL_SENT_RESET_PASSWORD = 'If the provided email identifies an account in our system, '
. 'you will receive an email with further instructions on resetting your account\'s password.';
public const MAIL_SENT_USER_ACTIVATION = 'User activation mail has been successfully sent to \'%s\'';
public const MAIL_NOT_SENT_TO = 'Could not send mail to \'%s\'.';
public const MISSING_CONFIG = 'Missing configuration value: \'%s\'.';
public const RESET_PASSWORD_EXPIRED = 'Password reset request for hash: \'%s\' is invalid (expired).';
public const RESET_PASSWORD_NOT_FOUND = 'Could not find password reset request identified by hash: \'%s\'';
public const RESET_PASSWORD_OK = 'Password successfully modified.';
public const RESET_PASSWORD_USED = 'Password reset request for hash: \'%s\' is invalid (used).';
public const RESET_PASSWORD_VALID = 'Password reset request for hash: \'%s\' is valid.';
public const RESOURCE_NOT_ALLOWED = 'You are not allowed to access this resource.';
public const RESTRICTION_DEPRECATION = 'Cannot use both `%s` and `%s` attributes on the same object.';
public const RESTRICTION_IMAGE = 'File must be an image (jpg, png).';
public const RESTRICTION_ROLES = 'User accounts must have at least one role.';
public const ROLE_NOT_FOUND = 'Role not found.';
Expand All @@ -44,5 +46,4 @@ class Message
public const VALIDATOR_REQUIRED_FIELD = 'This field is required and cannot be empty.';
public const VALIDATOR_REQUIRED_FIELD_BY_NAME = '%s is required and cannot be empty.';
public const VALIDATOR_REQUIRED_UPLOAD = 'A file must be uploaded first.';
public const RESTRICTION_DEPRECATION = 'Cannot use both `%s` and `%s` attributes on the same object.';
}
29 changes: 20 additions & 9 deletions src/App/src/Middleware/DeprecationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Api\App\Exception\DeprecationConflictException;
use Api\App\Handler\ResponseTrait;
use Api\App\Message;
use Laminas\Stratigility\MiddlewarePipe;

Check warning on line 12 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'MiddlewarePipe'

Check warning on line 12 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined namespace

Undefined namespace 'Stratigility'
use Mezzio\Middleware\LazyLoadingMiddleware;

Check warning on line 13 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'LazyLoadingMiddleware'

Check warning on line 13 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined namespace

Undefined namespace 'Middleware'
use Mezzio\Router\RouteResult;

Check warning on line 14 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'RouteResult'

Check warning on line 14 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined namespace

Undefined namespace 'Router'
use Psr\Http\Message\ResponseInterface;

Check warning on line 15 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'ResponseInterface'

Check warning on line 15 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined namespace

Undefined namespace 'Message'
Expand Down Expand Up @@ -43,13 +44,20 @@ public function process(
}

$reflectionHandler = null;
$routeMiddleware = $routeResult->getMatchedRoute()->getMiddleware();
$matchedRoute = $routeResult->getMatchedRoute();
if (! $matchedRoute) {
return $response;
}

$routeMiddleware = $matchedRoute->getMiddleware();
if ($routeMiddleware instanceof LazyLoadingMiddleware) {

Check warning on line 53 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'LazyLoadingMiddleware'
$reflectionMiddlewareClass = new ReflectionClass($routeMiddleware->middlewareName);
/** @var class-string $routeMiddlewareName */
$routeMiddlewareName = $routeMiddleware->middlewareName;

Check failure on line 55 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 10 spaces

Check failure on line 55 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 10 spaces
$reflectionMiddlewareClass = new ReflectionClass($routeMiddlewareName);
if ($reflectionMiddlewareClass->implementsInterface(RequestHandlerInterface::class)) {

Check warning on line 57 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'RequestHandlerInterface'
$reflectionHandler = $reflectionMiddlewareClass;
}
} else {
} elseif ($routeMiddleware instanceof MiddlewarePipe) {

Check warning on line 60 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'MiddlewarePipe'
$reflectionClass = new ReflectionClass($routeMiddleware);
$middlewarePipeline = $reflectionClass->getProperty('pipeline')->getValue($routeMiddleware);
for ($middlewarePipeline->rewind(); $middlewarePipeline->valid(); $middlewarePipeline->next()) {
Expand Down Expand Up @@ -80,29 +88,32 @@ public function process(
);
}

$sunset = '';
$link = '';
if ($attributes[self::RESOURCE_DEPRECATION_ATTRIBUTE] ?? '') {
$sunset = null;
$link = null;
if (array_key_exists(self::RESOURCE_DEPRECATION_ATTRIBUTE, $attributes)) {

Check failure on line 93 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function array_key_exists() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 93 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function array_key_exists() should not be referenced via a fallback global name, but via a use statement.
$sunset = $attributes[self::RESOURCE_DEPRECATION_ATTRIBUTE]['sunset'];
$link = $attributes[self::RESOURCE_DEPRECATION_ATTRIBUTE]['link'];
}

if ($attributes[self::METHOD_DEPRECATION_ATTRIBUTE] ?? '') {
if (array_key_exists(self::METHOD_DEPRECATION_ATTRIBUTE, $attributes)) {

Check failure on line 98 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function array_key_exists() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 98 in src/App/src/Middleware/DeprecationMiddleware.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, latest], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function array_key_exists() should not be referenced via a fallback global name, but via a use statement.
$sunset = $attributes[self::METHOD_DEPRECATION_ATTRIBUTE]['sunset'];
$link = $attributes[self::METHOD_DEPRECATION_ATTRIBUTE]['link'];
}

if ($sunset) {
if ($sunset !== null) {
$response = $response->withHeader('sunset', $sunset);
}

if ($link) {
if ($link !== null) {
$response = $response->withHeader('link', $link);
}

return $response;
}

/**
* @param class-string $type
*/
public function getAttributes(ReflectionClass|ReflectionMethod $reflection, string $type): array
{
$attributes = [];
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/App/Attribute/MethodDeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testInvalidDateThrowsException(): void
link: 'test-link',
deprecationReason: 'test-deprecation-reason',
)]
public function test()
public function test(): void
{
}
};
Expand All @@ -40,7 +40,7 @@ public function testValidDatePassesValidation(): void
link: 'test-link',
deprecationReason: 'test-deprecation-reason',
)]
public function test()
public function test(): void
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/App/Middleware/DeprecationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp(): void
* @throws ReflectionException
* @throws Exception

Check warning on line 49 in test/Unit/App/Middleware/DeprecationMiddlewareTest.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Exception'
*/
public function testThrowsDeprecationConflictException()
public function testThrowsDeprecationConflictException(): void
{
$handler = new #[ResourceDeprecation(
sunset: '2038-01-01',
Expand Down

0 comments on commit 82266ae

Please sign in to comment.