Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/composer-post-install-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols

/**
* @param array{source: string, destination: string, environment: array<string>} $file
*/
function copyFile(array $file): void
{
if (! in_array(getEnvironment(), $file['environment'])) {
Expand All @@ -33,8 +36,11 @@ function getEnvironment(): string
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
}

// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
// the `environment` key will indicate on what environments the file will be copied,
/**
* When adding files to the below array:
* - `source` and `destination` paths must be relative to the project root folder
* - `environment` key will indicate on what environments the file will be copied
*/
$files = [
[
'source' => 'config/autoload/local.php.dist',
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 5
level: 8
paths:
- bin
- config
Expand Down
21 changes: 16 additions & 5 deletions src/Admin/src/Command/AdminCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use function implode;
use function sprintf;
use function trim;

use const PHP_EOL;

Expand Down Expand Up @@ -75,6 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$messages = [];
foreach ($inputFilter->getMessages() as $field => $errors) {
foreach ($errors as $error) {
/** @var scalar $error */
$messages[] = sprintf('%s: %s', $field, $error);
}
}
Expand All @@ -90,6 +92,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @return array{
* identity: string,
* password: string,
* passwordConfirm: string,
* firstName: string,
* lastName: string,
* status: 'active',
* roles: array{uuid: non-empty-string}[],
* }
* @throws Exception
*/
private function getData(InputInterface $input): array
Expand All @@ -100,11 +111,11 @@ private function getData(InputInterface $input): array
}

return [
'identity' => $input->getOption('identity'),
'password' => $input->getOption('password'),
'passwordConfirm' => $input->getOption('password'),
'firstName' => $input->getOption('firstName'),
'lastName' => $input->getOption('lastName'),
'identity' => trim($input->getOption('identity')),
'password' => trim($input->getOption('password')),
'passwordConfirm' => trim($input->getOption('password')),
'firstName' => trim($input->getOption('firstName')),
'lastName' => trim($input->getOption('lastName')),
'status' => AdminStatusEnum::Active->value,
'roles' => [
['uuid' => $adminRole->getUuid()->toString()],
Expand Down
20 changes: 20 additions & 0 deletions src/Admin/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@
use Mezzio\Application;
use Mezzio\Hal\Metadata\MetadataMap;

/**
* @phpstan-import-type MetadataType from AppConfigProvider
* @phpstan-type DependenciesType array{
* delegators: array<class-string, class-string[]>,
* factories: array<class-string, class-string>,
* aliases: array<class-string, class-string>,
* }
*/
class ConfigProvider
{
/**
* @return array{
* dependencies: DependenciesType,
* "Mezzio\Hal\Metadata\MetadataMap": MetadataType[],
* }
*/
public function __invoke(): array
{
return [
Expand All @@ -38,6 +52,9 @@ public function __invoke(): array
];
}

/**
* @return DependenciesType
*/
private function getDependencies(): array
{
return [
Expand Down Expand Up @@ -74,6 +91,9 @@ private function getDependencies(): array
];
}

/**
* @return MetadataType[]
*/
private function getHalConfig(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
);
}

/** @var non-empty-array<non-empty-string, mixed> $data */
$data = (array) $this->inputFilter->getValues();

return $this->createResponse(
$request,
$this->adminService->saveAdmin(
(array) $this->inputFilter->getValues(),
$request->getAttribute(IdentityInterface::class)
)
$this->adminService->saveAdmin($data, $request->getAttribute(IdentityInterface::class))
);
}
}
8 changes: 4 additions & 4 deletions src/Admin/src/Handler/Admin/PatchAdminResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
);
}

/** @var non-empty-array<non-empty-string, mixed> $data */
$data = (array) $this->inputFilter->getValues();

return $this->createResponse(
$request,
$this->adminService->saveAdmin(
(array) $this->inputFilter->getValues(),
$request->getAttribute(Admin::class)
)
$this->adminService->saveAdmin($data, $request->getAttribute(Admin::class))
);
}
}
8 changes: 4 additions & 4 deletions src/Admin/src/Handler/Admin/PostAdminResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
);
}

return $this->createdResponse(
$request,
$this->adminService->saveAdmin((array) $this->inputFilter->getValues())
);
/** @var non-empty-array<non-empty-string, mixed> $data */
$data = (array) $this->inputFilter->getValues();

return $this->createdResponse($request, $this->adminService->saveAdmin($data));
}
}
2 changes: 1 addition & 1 deletion src/Admin/src/Service/AdminRoleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function findAdminRole(string $id): AdminRole
}

/**
* @param array<string, mixed> $params
* @param array<non-empty-string, mixed> $params
*/
public function getAdminRoles(array $params): QueryBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/src/Service/AdminRoleServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getAdminRoleRepository(): AdminRoleRepository;
public function findAdminRole(string $id): AdminRole;

/**
* @param array<string, mixed> $params
* @param array<non-empty-string, mixed> $params
*/
public function getAdminRoles(array $params): QueryBuilder;
}
5 changes: 3 additions & 2 deletions src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function findAdmin(string $uuid): Admin
}

/**
* @param array<string, mixed> $params
* @param array<non-empty-string, mixed> $params
*/
public function getAdmins(array $params): QueryBuilder
{
Expand All @@ -82,6 +82,7 @@ public function getAdmins(array $params): QueryBuilder
}

/**
* @param non-empty-array<non-empty-string, mixed> $data
* @throws BadRequestException
* @throws ConflictException
* @throws NotFoundException
Expand Down Expand Up @@ -118,7 +119,7 @@ public function saveAdmin(array $data, ?Admin $admin = null): Admin
$admin->setStatus($status);
}

$this->validateUniqueAdmin($admin->getIdentity(), $admin->getUuid());
$this->validateUniqueAdmin((string) $admin->getIdentity(), $admin->getUuid());

if (array_key_exists('roles', $data) && count($data['roles']) > 0) {
$admin->resetRoles();
Expand Down
3 changes: 2 additions & 1 deletion src/Admin/src/Service/AdminServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public function deleteAdmin(Admin $admin): void;
public function findAdmin(string $uuid): Admin;

/**
* @param array<string, mixed> $params
* @param array<non-empty-string, mixed> $params
*/
public function getAdmins(array $params): QueryBuilder;

/**
* @param non-empty-array<non-empty-string, mixed> $data
* @throws BadRequestException
* @throws ConflictException
* @throws NotFoundException
Expand Down
15 changes: 14 additions & 1 deletion src/App/src/Attribute/BaseDeprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

readonly class BaseDeprecation
{
/**
* @throws SunsetException
*/
public function __construct(
public ?string $sunset = null,
public ?string $link = null,
Expand All @@ -18,10 +21,20 @@ public function __construct(
public string $type = 'text/html',
) {
if (null !== $sunset && ! (new Date())->isValid($sunset)) {
throw new SunsetException(Message::invalidValue('sunset'));
throw SunsetException::create(Message::invalidValue('sunset'));
}
}

/**
* @return array{
* sunset: string|null,
* link: string|null,
* rel: string,
* type: string,
* deprecationReason: string|null,
* deprecationType: class-string,
* }
*/
public function toArray(): array
{
return [
Expand Down
37 changes: 37 additions & 0 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,45 @@
use Mezzio\Hal\Metadata\RouteBasedResourceMetadata;
use Mezzio\ProblemDetails\ProblemDetailsMiddleware;

/**
* @phpstan-type CollectionType array{
* __class__: class-string,
* collection_class: class-string,
* collection_relation: non-empty-string,
* route: non-empty-string,
* }
* @phpstan-type ResourceType array{
* __class__: class-string,
* resource_class: class-string,
* route: non-empty-string,
* extractor: class-string,
* resource_identifier: non-empty-string,
* route_identifier_placeholder: non-empty-string,
* }
* @phpstan-type MetadataType CollectionType|ResourceType
* @phpstan-type DependenciesType array{
* delegators: array<class-string, class-string[]>,
* factories: array<class-string, class-string>,
* aliases: array<class-string, class-string>,
* }
*/
class ConfigProvider
{
/**
* @return array{
* dependencies: DependenciesType,
* }
*/
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

/**
* @return DependenciesType
*/
private function getDependencies(): array
{
return [
Expand Down Expand Up @@ -73,6 +103,9 @@ private function getDependencies(): array

/**
* @param class-string $collectionClass
* @param non-empty-string $route
* @param non-empty-string $collectionRelation
* @return CollectionType
*/
public static function getCollection(string $collectionClass, string $route, string $collectionRelation): array
{
Expand All @@ -86,6 +119,10 @@ public static function getCollection(string $collectionClass, string $route, str

/**
* @param class-string $resourceClass
* @param non-empty-string $route
* @param non-empty-string $resourceIdentifier
* @param non-empty-string $resourceIdentifierPlaceholder
* @return ResourceType
*/
public static function getResource(
string $resourceClass,
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class BadRequestException extends Exception implements ProblemDetailsExceptionIn
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/ConflictException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class ConflictException extends Exception implements ProblemDetailsExceptionInte
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/ExpiredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class ExpiredException extends Exception implements ProblemDetailsExceptionInter
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/ForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class ForbiddenException extends Exception implements ProblemDetailsExceptionInt
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/NotAcceptableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class NotAcceptableException extends Exception implements ProblemDetailsExceptio
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
4 changes: 4 additions & 0 deletions src/App/src/Exception/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class NotFoundException extends Exception implements ProblemDetailsExceptionInte
{
use CommonProblemDetailsExceptionTrait;

/**
* @param non-empty-string $detail
* @param array<string, mixed> $additional
*/
public static function create(string $detail, string $type = '', string $title = '', array $additional = []): self
{
$exception = new self();
Expand Down
Loading