From 5be5e0bc60b554105e82d6e6b4f9490cec18d2bb Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 31 Jul 2018 19:53:59 +0200 Subject: [PATCH] Fixed coding styles --- module/Core/src/Service/Tag/TagService.php | 12 +++++++----- .../Core/src/Service/Tag/TagServiceInterface.php | 8 ++++---- module/Rest/src/Service/ApiKeyService.php | 14 ++++++++------ module/Rest/src/Service/ApiKeyServiceInterface.php | 10 +++++----- phpstan.neon | 1 - 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 65ae733a..5369769d 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -28,16 +28,18 @@ class TagService implements TagServiceInterface * @return Tag[] * @throws \UnexpectedValueException */ - public function listTags() + public function listTags(): array { - return $this->em->getRepository(Tag::class)->findBy([], ['name' => 'ASC']); + /** @var Tag[] $tags */ + $tags = $this->em->getRepository(Tag::class)->findBy([], ['name' => 'ASC']); + return $tags; } /** * @param array $tagNames * @return void */ - public function deleteTags(array $tagNames) + public function deleteTags(array $tagNames): void { /** @var TagRepository $repo */ $repo = $this->em->getRepository(Tag::class); @@ -50,7 +52,7 @@ class TagService implements TagServiceInterface * @param string[] $tagNames * @return Collection|Tag[] */ - public function createTags(array $tagNames) + public function createTags(array $tagNames): Collection { $tags = $this->tagNamesToEntities($this->em, $tagNames); $this->em->flush(); @@ -65,7 +67,7 @@ class TagService implements TagServiceInterface * @throws EntityDoesNotExistException * @throws ORM\OptimisticLockException */ - public function renameTag($oldName, $newName) + public function renameTag($oldName, $newName): Tag { $criteria = ['name' => $oldName]; /** @var Tag|null $tag */ diff --git a/module/Core/src/Service/Tag/TagServiceInterface.php b/module/Core/src/Service/Tag/TagServiceInterface.php index 7ee57bda..a70b9e48 100644 --- a/module/Core/src/Service/Tag/TagServiceInterface.php +++ b/module/Core/src/Service/Tag/TagServiceInterface.php @@ -12,13 +12,13 @@ interface TagServiceInterface /** * @return Tag[] */ - public function listTags(); + public function listTags(): array; /** * @param string[] $tagNames * @return void */ - public function deleteTags(array $tagNames); + public function deleteTags(array $tagNames): void; /** * Provided a list of tag names, creates all that do not exist yet @@ -26,7 +26,7 @@ interface TagServiceInterface * @param string[] $tagNames * @return Collection|Tag[] */ - public function createTags(array $tagNames); + public function createTags(array $tagNames): Collection; /** * @param string $oldName @@ -34,5 +34,5 @@ interface TagServiceInterface * @return Tag * @throws EntityDoesNotExistException */ - public function renameTag($oldName, $newName); + public function renameTag($oldName, $newName): Tag; } diff --git a/module/Rest/src/Service/ApiKeyService.php b/module/Rest/src/Service/ApiKeyService.php index e886bcf1..815bbed3 100644 --- a/module/Rest/src/Service/ApiKeyService.php +++ b/module/Rest/src/Service/ApiKeyService.php @@ -25,7 +25,7 @@ class ApiKeyService implements ApiKeyServiceInterface * @param \DateTime $expirationDate * @return ApiKey */ - public function create(\DateTime $expirationDate = null) + public function create(\DateTime $expirationDate = null): ApiKey { $key = new ApiKey(); if ($expirationDate !== null) { @@ -44,7 +44,7 @@ class ApiKeyService implements ApiKeyServiceInterface * @param string $key * @return bool */ - public function check(string $key) + public function check(string $key): bool { /** @var ApiKey|null $apiKey */ $apiKey = $this->getByKey($key); @@ -58,7 +58,7 @@ class ApiKeyService implements ApiKeyServiceInterface * @return ApiKey * @throws InvalidArgumentException */ - public function disable(string $key) + public function disable(string $key): ApiKey { /** @var ApiKey|null $apiKey */ $apiKey = $this->getByKey($key); @@ -77,10 +77,12 @@ class ApiKeyService implements ApiKeyServiceInterface * @param bool $enabledOnly Tells if only enabled keys should be returned * @return ApiKey[] */ - public function listKeys(bool $enabledOnly = false) + public function listKeys(bool $enabledOnly = false): array { $conditions = $enabledOnly ? ['enabled' => true] : []; - return $this->em->getRepository(ApiKey::class)->findBy($conditions); + /** @var ApiKey[] $apiKeys */ + $apiKeys = $this->em->getRepository(ApiKey::class)->findBy($conditions); + return $apiKeys; } /** @@ -89,7 +91,7 @@ class ApiKeyService implements ApiKeyServiceInterface * @param string $key * @return ApiKey|null */ - public function getByKey(string $key) + public function getByKey(string $key): ?ApiKey { /** @var ApiKey|null $apiKey */ $apiKey = $this->em->getRepository(ApiKey::class)->findOneBy([ diff --git a/module/Rest/src/Service/ApiKeyServiceInterface.php b/module/Rest/src/Service/ApiKeyServiceInterface.php index eab38503..3d62adbe 100644 --- a/module/Rest/src/Service/ApiKeyServiceInterface.php +++ b/module/Rest/src/Service/ApiKeyServiceInterface.php @@ -14,7 +14,7 @@ interface ApiKeyServiceInterface * @param \DateTime $expirationDate * @return ApiKey */ - public function create(\DateTime $expirationDate = null); + public function create(\DateTime $expirationDate = null): ApiKey; /** * Checks if provided key is a valid api key @@ -22,7 +22,7 @@ interface ApiKeyServiceInterface * @param string $key * @return bool */ - public function check(string $key); + public function check(string $key): bool; /** * Disables provided api key @@ -31,7 +31,7 @@ interface ApiKeyServiceInterface * @return ApiKey * @throws InvalidArgumentException */ - public function disable(string $key); + public function disable(string $key): ApiKey; /** * Lists all existing api keys @@ -39,7 +39,7 @@ interface ApiKeyServiceInterface * @param bool $enabledOnly Tells if only enabled keys should be returned * @return ApiKey[] */ - public function listKeys(bool $enabledOnly = false); + public function listKeys(bool $enabledOnly = false): array; /** * Tries to find one API key by its key string @@ -47,5 +47,5 @@ interface ApiKeyServiceInterface * @param string $key * @return ApiKey|null */ - public function getByKey(string $key); + public function getByKey(string $key): ?ApiKey; } diff --git a/phpstan.neon b/phpstan.neon index f1c8ab6d..c67d210b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,4 +4,3 @@ parameters: - module/Rest/src/Util/RestUtils.php ignoreErrors: - '#is not subtype of Throwable#' - - '#Cannot access offset#'