Applied some improvements

This commit is contained in:
Alejandro Celaya 2018-03-27 23:56:55 +02:00
parent 6935b2ebe2
commit fe9ab20cbb
11 changed files with 51 additions and 45 deletions

View File

@ -9,6 +9,7 @@
**Enhancements:** **Enhancements:**
* [130: Update to Expressive 3](https://github.com/shlinkio/shlink/issues/130) * [130: Update to Expressive 3](https://github.com/shlinkio/shlink/issues/130)
* [137: Update symfony packages to v4](https://github.com/shlinkio/shlink/issues/137)
**Tasks** **Tasks**

View File

@ -103,7 +103,8 @@
"phpcov merge build --html build/html" "phpcov merge build --html build/html"
], ],
"stan": "phpstan analyse module/*/src/ --level=6 -c phpstan.neon", "stan": "phpstan analyse module/*/src/ --level=6 -c phpstan.neon",
"infect": "infection --threads=4 --min-msi=60 --only-covered --log-verbosity=2", "infect": "infection --threads=4 --min-msi=65 --only-covered --log-verbosity=2",
"infect-show": "infection --threads=4 --min-msi=65 --only-covered --log-verbosity=2 --show-mutations",
"expressive": "expressive" "expressive": "expressive"
}, },
"config": { "config": {

View File

@ -80,7 +80,7 @@ class QrCodeAction implements MiddlewareInterface
* @param Request $request * @param Request $request
* @return int * @return int
*/ */
protected function getSizeParam(Request $request) private function getSizeParam(Request $request): int
{ {
$size = (int) $request->getAttribute('size', 300); $size = (int) $request->getAttribute('size', 300);
if ($size < 50) { if ($size < 50) {

View File

@ -57,7 +57,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return string * @return string
*/ */
public function getReferer() public function getReferer(): string
{ {
return $this->referer; return $this->referer;
} }
@ -66,7 +66,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param string $referer * @param string $referer
* @return $this * @return $this
*/ */
public function setReferer($referer) public function setReferer($referer): self
{ {
$this->referer = $referer; $this->referer = $referer;
return $this; return $this;
@ -75,7 +75,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return \DateTime * @return \DateTime
*/ */
public function getDate() public function getDate(): \DateTime
{ {
return $this->date; return $this->date;
} }
@ -84,7 +84,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param \DateTime $date * @param \DateTime $date
* @return $this * @return $this
*/ */
public function setDate($date) public function setDate($date): self
{ {
$this->date = $date; $this->date = $date;
return $this; return $this;
@ -93,7 +93,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return ShortUrl * @return ShortUrl
*/ */
public function getShortUrl() public function getShortUrl(): ShortUrl
{ {
return $this->shortUrl; return $this->shortUrl;
} }
@ -102,7 +102,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param ShortUrl $shortUrl * @param ShortUrl $shortUrl
* @return $this * @return $this
*/ */
public function setShortUrl($shortUrl) public function setShortUrl($shortUrl): self
{ {
$this->shortUrl = $shortUrl; $this->shortUrl = $shortUrl;
return $this; return $this;
@ -111,7 +111,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return string * @return string
*/ */
public function getRemoteAddr() public function getRemoteAddr(): string
{ {
return $this->remoteAddr; return $this->remoteAddr;
} }
@ -120,7 +120,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param string $remoteAddr * @param string $remoteAddr
* @return $this * @return $this
*/ */
public function setRemoteAddr($remoteAddr) public function setRemoteAddr($remoteAddr): self
{ {
$this->remoteAddr = $remoteAddr; $this->remoteAddr = $remoteAddr;
return $this; return $this;
@ -129,7 +129,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return string * @return string
*/ */
public function getUserAgent() public function getUserAgent(): string
{ {
return $this->userAgent; return $this->userAgent;
} }
@ -138,7 +138,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param string $userAgent * @param string $userAgent
* @return $this * @return $this
*/ */
public function setUserAgent($userAgent) public function setUserAgent($userAgent): self
{ {
$this->userAgent = $userAgent; $this->userAgent = $userAgent;
return $this; return $this;
@ -147,7 +147,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* @return VisitLocation * @return VisitLocation
*/ */
public function getVisitLocation() public function getVisitLocation(): VisitLocation
{ {
return $this->visitLocation; return $this->visitLocation;
} }
@ -156,7 +156,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
* @param VisitLocation $visitLocation * @param VisitLocation $visitLocation
* @return $this * @return $this
*/ */
public function setVisitLocation($visitLocation) public function setVisitLocation($visitLocation): self
{ {
$this->visitLocation = $visitLocation; $this->visitLocation = $visitLocation;
return $this; return $this;
@ -165,11 +165,11 @@ class Visit extends AbstractEntity implements \JsonSerializable
/** /**
* Specify data which should be serialized to JSON * Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>, * @return array data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource. * which is a value of any type other than a resource.
* @since 5.4.0 * @since 5.4.0
*/ */
public function jsonSerialize() public function jsonSerialize(): array
{ {
return [ return [
'referer' => $this->referer, 'referer' => $this->referer,

View File

@ -14,7 +14,7 @@ trait TagManagerTrait
* @param string[] $tags * @param string[] $tags
* @return Collections\Collection|Tag[] * @return Collections\Collection|Tag[]
*/ */
protected function tagNamesToEntities(EntityManagerInterface $em, array $tags) private function tagNamesToEntities(EntityManagerInterface $em, array $tags)
{ {
$entities = []; $entities = [];
foreach ($tags as $tagName) { foreach ($tags as $tagName) {
@ -33,8 +33,8 @@ trait TagManagerTrait
* @param string $tagName * @param string $tagName
* @return string * @return string
*/ */
protected function normalizeTagName($tagName) private function normalizeTagName($tagName): string
{ {
return str_replace(' ', '-', strtolower(trim($tagName))); return \str_replace(' ', '-', \strtolower(\trim($tagName)));
} }
} }

View File

@ -9,7 +9,7 @@ use Zend\InputFilter\Input;
trait InputFactoryTrait trait InputFactoryTrait
{ {
public function createInput($name, $required = true): Input private function createInput($name, $required = true): Input
{ {
$input = new Input($name); $input = new Input($name);
$input->setRequired($required) $input->setRequired($required)

View File

@ -59,7 +59,7 @@ class ListShortcodesAction extends AbstractRestAction
* @param array $query * @param array $query
* @return array * @return array
*/ */
public function queryToListParams(array $query) private function queryToListParams(array $query): array
{ {
return [ return [
$query['page'] ?? 1, $query['page'] ?? 1,

View File

@ -92,7 +92,7 @@ class JWTService implements JWTServiceInterface
* @param array $data * @param array $data
* @return string * @return string
*/ */
protected function encode(array $data): string private function encode(array $data): string
{ {
return JWT::encode($data, $this->appOptions->getSecretKey(), self::DEFAULT_ENCRYPTION_ALG); return JWT::encode($data, $this->appOptions->getSecretKey(), self::DEFAULT_ENCRYPTION_ALG);
} }
@ -101,7 +101,7 @@ class JWTService implements JWTServiceInterface
* @param string $jwt * @param string $jwt
* @return array * @return array
*/ */
protected function decode(string $jwt): array private function decode(string $jwt): array
{ {
return (array) JWT::decode($jwt, $this->appOptions->getSecretKey(), [self::DEFAULT_ENCRYPTION_ALG]); return (array) JWT::decode($jwt, $this->appOptions->getSecretKey(), [self::DEFAULT_ENCRYPTION_ALG]);
} }

View File

@ -44,7 +44,7 @@ class ApiKey extends AbstractEntity
/** /**
* @return string * @return string
*/ */
public function getKey() public function getKey(): string
{ {
return $this->key; return $this->key;
} }
@ -53,7 +53,7 @@ class ApiKey extends AbstractEntity
* @param string $key * @param string $key
* @return $this * @return $this
*/ */
public function setKey($key) public function setKey($key): self
{ {
$this->key = $key; $this->key = $key;
return $this; return $this;
@ -62,7 +62,7 @@ class ApiKey extends AbstractEntity
/** /**
* @return \DateTime|null * @return \DateTime|null
*/ */
public function getExpirationDate() public function getExpirationDate(): ?\DateTime
{ {
return $this->expirationDate; return $this->expirationDate;
} }
@ -71,7 +71,7 @@ class ApiKey extends AbstractEntity
* @param \DateTime $expirationDate * @param \DateTime $expirationDate
* @return $this * @return $this
*/ */
public function setExpirationDate($expirationDate) public function setExpirationDate($expirationDate): self
{ {
$this->expirationDate = $expirationDate; $this->expirationDate = $expirationDate;
return $this; return $this;
@ -80,9 +80,9 @@ class ApiKey extends AbstractEntity
/** /**
* @return bool * @return bool
*/ */
public function isExpired() public function isExpired(): bool
{ {
if (! isset($this->expirationDate)) { if ($this->expirationDate === null) {
return false; return false;
} }
@ -92,7 +92,7 @@ class ApiKey extends AbstractEntity
/** /**
* @return boolean * @return boolean
*/ */
public function isEnabled() public function isEnabled(): bool
{ {
return $this->enabled; return $this->enabled;
} }
@ -101,7 +101,7 @@ class ApiKey extends AbstractEntity
* @param boolean $enabled * @param boolean $enabled
* @return $this * @return $this
*/ */
public function setEnabled($enabled) public function setEnabled($enabled): self
{ {
$this->enabled = $enabled; $this->enabled = $enabled;
return $this; return $this;
@ -112,7 +112,7 @@ class ApiKey extends AbstractEntity
* *
* @return $this * @return $this
*/ */
public function disable() public function disable(): self
{ {
return $this->setEnabled(false); return $this->setEnabled(false);
} }
@ -122,17 +122,17 @@ class ApiKey extends AbstractEntity
* *
* @return bool * @return bool
*/ */
public function isValid() public function isValid(): bool
{ {
return $this->isEnabled() && ! $this->isExpired(); return $this->isEnabled() && ! $this->isExpired();
} }
/** /**
* The string repesentation of an API key is the key itself * The string representation of an API key is the key itself
* *
* @return string * @return string
*/ */
public function __toString() public function __toString(): string
{ {
return $this->getKey(); return $this->getKey();
} }

View File

@ -32,8 +32,8 @@ class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, Sta
], $status); ], $status);
} }
protected function responsePhraseToCode(string $responsePhrase): string private function responsePhraseToCode(string $responsePhrase): string
{ {
return strtoupper(str_replace(' ', '_', $responsePhrase)); return \strtoupper(\str_replace(' ', '_', $responsePhrase));
} }
} }

View File

@ -77,22 +77,22 @@ class CheckAuthenticationMiddleware implements MiddlewareInterface, StatusCodeIn
// Get token making sure the an authorization type is provided // Get token making sure the an authorization type is provided
$authToken = $request->getHeaderLine(self::AUTHORIZATION_HEADER); $authToken = $request->getHeaderLine(self::AUTHORIZATION_HEADER);
$authTokenParts = explode(' ', $authToken); $authTokenParts = \explode(' ', $authToken);
if (count($authTokenParts) === 1) { if (\count($authTokenParts) === 1) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_AUTHORIZATION_ERROR, 'error' => RestUtils::INVALID_AUTHORIZATION_ERROR,
'message' => sprintf($this->translator->translate( 'message' => \sprintf($this->translator->translate(
'You need to provide the Bearer type in the %s header.' 'You need to provide the Bearer type in the %s header.'
), self::AUTHORIZATION_HEADER), ), self::AUTHORIZATION_HEADER),
], self::STATUS_UNAUTHORIZED); ], self::STATUS_UNAUTHORIZED);
} }
// Make sure the authorization type is Bearer // Make sure the authorization type is Bearer
list($authType, $jwt) = $authTokenParts; [$authType, $jwt] = $authTokenParts;
if (strtolower($authType) !== 'bearer') { if (\strtolower($authType) !== 'bearer') {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_AUTHORIZATION_ERROR, 'error' => RestUtils::INVALID_AUTHORIZATION_ERROR,
'message' => sprintf($this->translator->translate( 'message' => \sprintf($this->translator->translate(
'Provided authorization type %s is not supported. Use Bearer instead.' 'Provided authorization type %s is not supported. Use Bearer instead.'
), $authType), ), $authType),
], self::STATUS_UNAUTHORIZED); ], self::STATUS_UNAUTHORIZED);
@ -119,11 +119,15 @@ class CheckAuthenticationMiddleware implements MiddlewareInterface, StatusCodeIn
} }
} }
protected function createTokenErrorResponse() /**
* @return JsonResponse
* @throws \InvalidArgumentException
*/
private function createTokenErrorResponse(): JsonResponse
{ {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_AUTH_TOKEN_ERROR, 'error' => RestUtils::INVALID_AUTH_TOKEN_ERROR,
'message' => sprintf( 'message' => \sprintf(
$this->translator->translate( $this->translator->translate(
'Missing or invalid auth token provided. Perform a new authentication request and send provided ' 'Missing or invalid auth token provided. Perform a new authentication request and send provided '
. 'token on every new request on the "%s" header' . 'token on every new request on the "%s" header'