Skip to content

Commit

Permalink
Merge pull request #254 from slimphp/remove-php-73
Browse files Browse the repository at this point in the history
Remove php 7.3
  • Loading branch information
l0gicgate committed Jan 14, 2022
2 parents 4c9abf2 + 1fe6627 commit 8a91d18
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 181 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0]
php: [7.4, 8.0, 8.1]
experimental: [false]
include:
- php: 8.0
analysis: true
- php: 8.1
experimental: true
analysis: true

steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-json": "*",
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
"slim/psr7": "^1.5",
"slim/slim": "^4.9"
},
"require-dev": {
"jangregor/phpstan-prophecy": "^0.8.1",
"jangregor/phpstan-prophecy": "^1.0.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^0.12.99",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^9.5.11",
"squizlabs/php_codesniffer": "^3.6"
},
Expand Down
3 changes: 3 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
// Add Routing Middleware
$app->addRoutingMiddleware();

// Add Body Parsing Middleware
$app->addBodyParsingMiddleware();

// Add Error Middleware
$errorMiddleware = $app->addErrorMiddleware($displayErrorDetails, $logError, $logErrorDetails);
$errorMiddleware->setDefaultErrorHandler($errorHandler);
Expand Down
44 changes: 5 additions & 39 deletions src/Application/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,20 @@

abstract class Action
{
/**
* @var LoggerInterface
*/
protected $logger;
protected LoggerInterface $logger;

/**
* @var Request
*/
protected $request;
protected Request $request;

/**
* @var Response
*/
protected $response;
protected Response $response;

/**
* @var array
*/
protected $args;
protected array $args;

/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

/**
* @param Request $request
* @param Response $response
* @param array $args
* @return Response
* @throws HttpNotFoundException
* @throws HttpBadRequestException
*/
Expand All @@ -62,29 +43,20 @@ public function __invoke(Request $request, Response $response, array $args): Res
}

/**
* @return Response
* @throws DomainRecordNotFoundException
* @throws HttpBadRequestException
*/
abstract protected function action(): Response;

/**
* @return array|object
* @throws HttpBadRequestException
*/
protected function getFormData()
{
$input = json_decode(file_get_contents('php://input'));

if (json_last_error() !== JSON_ERROR_NONE) {
throw new HttpBadRequestException($this->request, 'Malformed JSON input.');
}

return $input;
return $this->request->getParsedBody();
}

/**
* @param string $name
* @return mixed
* @throws HttpBadRequestException
*/
Expand All @@ -99,8 +71,6 @@ protected function resolveArg(string $name)

/**
* @param array|object|null $data
* @param int $statusCode
* @return Response
*/
protected function respondWithData($data = null, int $statusCode = 200): Response
{
Expand All @@ -109,10 +79,6 @@ protected function respondWithData($data = null, int $statusCode = 200): Respons
return $this->respond($payload);
}

/**
* @param ActionPayload $payload
* @return Response
*/
protected function respond(ActionPayload $payload): Response
{
$json = json_encode($payload, JSON_PRETTY_PRINT);
Expand Down
33 changes: 3 additions & 30 deletions src/Application/Actions/ActionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,40 @@ class ActionError implements JsonSerializable
public const VALIDATION_ERROR = 'VALIDATION_ERROR';
public const VERIFICATION_ERROR = 'VERIFICATION_ERROR';

/**
* @var string
*/
private $type;
private string $type;

/**
* @var string
*/
private $description;
private string $description;

/**
* @param string $type
* @param string|null $description
*/
public function __construct(string $type, ?string $description)
{
$this->type = $type;
$this->description = $description;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @param string $type
* @return self
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}

/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}

/**
* @param string|null $description
* @return self
*/
public function setDescription(?string $description = null): self
{
$this->description = $description;
return $this;
}

/**
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
$payload = [
'type' => $this->type,
Expand Down
26 changes: 3 additions & 23 deletions src/Application/Actions/ActionPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,15 @@

class ActionPayload implements JsonSerializable
{
/**
* @var int
*/
private $statusCode;
private int $statusCode;

/**
* @var array|object|null
*/
private $data;

/**
* @var ActionError|null
*/
private $error;
private ?ActionError $error;

/**
* @param int $statusCode
* @param array|object|null $data
* @param ActionError|null $error
*/
public function __construct(
int $statusCode = 200,
$data = null,
Expand All @@ -37,9 +26,6 @@ public function __construct(
$this->error = $error;
}

/**
* @return int
*/
public function getStatusCode(): int
{
return $this->statusCode;
Expand All @@ -53,19 +39,13 @@ public function getData()
return $this->data;
}

/**
* @return ActionError|null
*/
public function getError(): ?ActionError
{
return $this->error;
}

/**
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
$payload = [
'statusCode' => $this->statusCode,
Expand Down
15 changes: 3 additions & 12 deletions src/Application/Actions/User/UserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@

abstract class UserAction extends Action
{
/**
* @var UserRepository
*/
protected $userRepository;
protected UserRepository $userRepository;

/**
* @param LoggerInterface $logger
* @param UserRepository $userRepository
*/
public function __construct(
LoggerInterface $logger,
UserRepository $userRepository
) {
public function __construct(LoggerInterface $logger, UserRepository $userRepository)
{
parent::__construct($logger);
$this->userRepository = $userRepository;
}
Expand Down
22 changes: 3 additions & 19 deletions src/Application/Handlers/ShutdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,12 @@

class ShutdownHandler
{
/**
* @var Request
*/
private $request;
private Request $request;

/**
* @var HttpErrorHandler
*/
private $errorHandler;
private HttpErrorHandler $errorHandler;

/**
* @var bool
*/
private $displayErrorDetails;
private bool $displayErrorDetails;

/**
* ShutdownHandler constructor.
*
* @param Request $request
* @param HttpErrorHandler $errorHandler
* @param bool $displayErrorDetails
*/
public function __construct(
Request $request,
HttpErrorHandler $errorHandler,
Expand Down
10 changes: 1 addition & 9 deletions src/Application/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@

class Settings implements SettingsInterface
{
/**
* @var array
*/
private $settings;
private array $settings;

/**
* Settings constructor.
* @param array $settings
*/
public function __construct(array $settings)
{
$this->settings = $settings;
}

/**
* @param string $key
* @return mixed
*/
public function get(string $key = '')
Expand Down
Loading

0 comments on commit 8a91d18

Please sign in to comment.