diff --git a/src/ApiExtension.php b/src/ApiExtension.php index 8b8a577..dfc3260 100644 --- a/src/ApiExtension.php +++ b/src/ApiExtension.php @@ -54,4 +54,4 @@ public function afterCompile(ClassType $class): void [$application->getName()] ); } -} \ No newline at end of file +} diff --git a/src/ApiManager.php b/src/ApiManager.php index 8fe4a6f..0e85b51 100644 --- a/src/ApiManager.php +++ b/src/ApiManager.php @@ -66,7 +66,7 @@ public function __construct(Container $container, Request $request, Response $re */ public function run(string $path, ?array $params = [], ?string $method = null, bool $throw = false): void { - $params = array_merge($this->safeGetParams($path), $this->getBodyParams($method = $method ?: $this->getMethod()), $params ?? []); + $params = array_merge($this->safeGetParams($path), $this->getBodyParams($method = $method ?: $this->getHttpMethod()), $params ?? []); if (preg_match('/^api\/v([^\/]+)\/?(.*?)$/', $path, $pathParser)) { if (($version = (int) $pathParser[1]) < 1 || $version > 999 || !preg_match('#^[+-]?\d+$#D', $pathParser[1])) { @@ -143,9 +143,6 @@ public function get(string $path, ?array $params = [], ?string $method = null): } - /** - * @return Convention - */ public function getConvention(): Convention { return $this->convention; @@ -311,12 +308,7 @@ private function invokeActionMethod(Endpoint $endpoint, string $action, string $ } - /** - * Return current HTTP method. - * - * @return string - */ - private function getMethod(): string + private function getHttpMethod(): string { if (($method = $_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST' && preg_match('#^[A-Z]+$#D', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? '') diff --git a/src/Endpoint/BaseEndpoint.php b/src/Endpoint/BaseEndpoint.php index a65167a..2305855 100644 --- a/src/Endpoint/BaseEndpoint.php +++ b/src/Endpoint/BaseEndpoint.php @@ -44,9 +44,6 @@ abstract class BaseEndpoint implements Endpoint private $startupCheck = false; - /** - * @return string - */ public function __toString(): string { return get_class($this); @@ -123,10 +120,6 @@ final public function sendJson(array $haystack, int $httpCode = 200): void } - /** - * @param string $message - * @param int|null $code - */ final public function sendError(string $message, ?int $code = null): void { $this->sendJson([ @@ -190,11 +183,6 @@ final public function flashMessage(string $message, string $type = 'info'): void } - /** - * @param string $key - * @param string|null $message - * @param int|null $code - */ final public function validateDataKey(string $key, ?string $message = null, ?int $code = null): void { if (array_key_exists($key, $this->data) === false) { @@ -277,9 +265,6 @@ final public function saveState(): void } - /** - * @return User - */ final public function getUser(): User { static $user; @@ -292,9 +277,6 @@ final public function getUser(): User } - /** - * @return bool - */ final public function isUserLoggedIn(): bool { try { @@ -305,18 +287,12 @@ final public function isUserLoggedIn(): bool } - /** - * @return IIdentity|null - */ final public function getUserEntity(): ?IIdentity { return $this->getUser()->getIdentity(); } - /** - * @return IAuthorizator - */ final public function getAuthorizator(): IAuthorizator { return $this->getUser()->getAuthorizator(); @@ -359,10 +335,6 @@ final public function linkSafe(string $dest, array $params = []): ?string } - /** - * @param string|null $namespace - * @return Cache - */ final public function getCache(?string $namespace = null): Cache { static $storage; @@ -382,9 +354,6 @@ final public function getCache(?string $namespace = null): Cache } - /** - * @return ITranslator - */ final public function getTranslator(): ITranslator { static $translator; @@ -410,7 +379,7 @@ final public function translate($message, ...$parameters): string /** - * @return array + * @return mixed[] */ final public function getParameters(): array { diff --git a/src/Endpoint/Endpoint.php b/src/Endpoint/Endpoint.php index 6d7bf4f..b3a01cd 100644 --- a/src/Endpoint/Endpoint.php +++ b/src/Endpoint/Endpoint.php @@ -22,4 +22,4 @@ public function startup(): void; public function startupCheck(): void; public function saveState(): void; -} \ No newline at end of file +} diff --git a/src/Endpoint/PingEndpoint.php b/src/Endpoint/PingEndpoint.php index 2110fec..ab856d9 100644 --- a/src/Endpoint/PingEndpoint.php +++ b/src/Endpoint/PingEndpoint.php @@ -5,6 +5,8 @@ namespace Baraja\StructuredApi; +use Nette\Utils\DateTime; + final class PingEndpoint extends BaseEndpoint { public function actionDefault(): void @@ -12,22 +14,18 @@ public function actionDefault(): void $this->sendJson([ 'result' => 'PONG', 'ip' => $this->getIp(), - 'datetime' => date('Y-m-d H:i:s'), + 'datetime' => DateTime::from('now'), ]); } - /** - * @return string - */ private function getIp(): string { $ip = null; - if (isset($_SERVER['REMOTE_ADDR'])) { $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } return is_string($ip) ? $ip : '127.0.0.1'; } -} \ No newline at end of file +} diff --git a/src/Entity/Convention.php b/src/Entity/Convention.php index a484f16..c6c5559 100644 --- a/src/Entity/Convention.php +++ b/src/Entity/Convention.php @@ -27,18 +27,12 @@ final class Convention private $keysToHide = ['password', 'passwd', 'pass', 'pwd', 'creditcard', 'credit card', 'cc', 'pin']; - /** - * @return string - */ public function getDateTimeFormat(): string { return $this->dateTimeFormat; } - /** - * @param string $dateTimeFormat - */ public function setDateTimeFormat(string $dateTimeFormat): void { if ($dateTimeFormat === '') { @@ -49,18 +43,12 @@ public function setDateTimeFormat(string $dateTimeFormat): void } - /** - * @return int - */ public function getDefaultErrorCode(): int { return $this->defaultErrorCode; } - /** - * @param int $code - */ public function setDefaultErrorCode(int $code): void { if ($code < 100 || $code > 999) { @@ -71,18 +59,12 @@ public function setDefaultErrorCode(int $code): void } - /** - * @return int - */ public function getDefaultOkCode(): int { return $this->defaultOkCode; } - /** - * @param int $code - */ public function setDefaultOkCode(int $code): void { if ($code < 100 || $code > 999) { @@ -93,18 +75,12 @@ public function setDefaultOkCode(int $code): void } - /** - * @return bool - */ public function isRewriteTooStringMethod(): bool { return $this->rewriteTooStringMethod; } - /** - * @param bool $rewriteTooStringMethod - */ public function setRewriteTooStringMethod(bool $rewriteTooStringMethod): void { $this->rewriteTooStringMethod = $rewriteTooStringMethod; diff --git a/src/Entity/ItemsListItem.php b/src/Entity/ItemsListItem.php index c7ff5e2..fe11e99 100644 --- a/src/Entity/ItemsListItem.php +++ b/src/Entity/ItemsListItem.php @@ -26,9 +26,6 @@ public function __construct(string $id, array $data = []) } - /** - * @return string - */ public function getId(): string { return $this->id; diff --git a/src/Entity/StatusCount.php b/src/Entity/StatusCount.php index 8bb17c1..43c0a31 100644 --- a/src/Entity/StatusCount.php +++ b/src/Entity/StatusCount.php @@ -33,27 +33,18 @@ public function __construct(string $key, int $count, ?string $label = null) } - /** - * @return string - */ public function getKey(): string { return $this->key; } - /** - * @return string - */ public function getLabel(): string { return $this->label; } - /** - * @return int - */ public function getCount(): int { return $this->count; diff --git a/src/Helpers.php b/src/Helpers.php index 8193f94..ebf833e 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -10,9 +10,7 @@ final class Helpers { - /** - * @throws \Error - */ + /** @throws \Error */ public function __construct() { throw new \Error('Class ' . get_class($this) . ' is static and cannot be instantiated.'); @@ -49,9 +47,6 @@ public static function getCurrentUrl(): ?string } - /** - * @return string|null - */ public static function getBaseUrl(): ?string { static $return; @@ -76,10 +71,6 @@ public static function getBaseUrl(): ?string } - /** - * @param string $name - * @return string - */ public static function formatApiName(string $name): string { return (string) preg_replace_callback('/-([a-z])/', function (array $match): string { diff --git a/src/Response/BaseResponse.php b/src/Response/BaseResponse.php index 8359ea6..5d5ca21 100644 --- a/src/Response/BaseResponse.php +++ b/src/Response/BaseResponse.php @@ -39,18 +39,12 @@ final public function __construct(Convention $convention, array $haystack, int $ } - /** - * @return string - */ public function getContentType(): string { return 'text/plain'; } - /** - * @return string - */ public function __toString(): string { return ''; @@ -75,9 +69,6 @@ final public function getArray(): array } - /** - * @return int - */ final public function getHttpCode(): int { return $this->httpCode; diff --git a/src/Response/JsonResponse.php b/src/Response/JsonResponse.php index df5cd65..0926ad6 100644 --- a/src/Response/JsonResponse.php +++ b/src/Response/JsonResponse.php @@ -10,18 +10,12 @@ final class JsonResponse extends BaseResponse { - /** - * @return string - */ public function getContentType(): string { return 'application/json'; } - /** - * @return string - */ public function __toString(): string { try { diff --git a/src/Response/ThrowResponse.php b/src/Response/ThrowResponse.php index 08d0455..d48d0cf 100644 --- a/src/Response/ThrowResponse.php +++ b/src/Response/ThrowResponse.php @@ -11,9 +11,6 @@ final class ThrowResponse extends \RuntimeException private $response; - /** - * @param BaseResponse $response - */ public function __construct(BaseResponse $response) { parent::__construct(''); @@ -21,9 +18,6 @@ public function __construct(BaseResponse $response) } - /** - * @return BaseResponse - */ public function getResponse(): BaseResponse { return $this->response;