From a5074e695d8f0bccda46a0983f2169e21e7bcafe Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Fri, 31 Jul 2020 23:15:09 +0200 Subject: [PATCH] Stricter php-cs-fixer rules. These remove a lot of superfluous duplicitous rubbish, mostly in docblocks. --- .php_cs | 42 +++++++++++++++++++++++++-- src/App.php | 20 ++----------- src/Controllers/Filters/Filter.php | 25 ---------------- src/Redis/Lua/LuaExtension.php | 2 +- src/Redis/Redis.php | 2 +- src/Router/Route.php | 6 ---- src/Services/ConfigurationService.php | 7 +---- src/Services/QueueService.php | 28 ------------------ src/Services/SessionService.php | 8 +---- src/Workers/AbstractQueueWorker.php | 25 ---------------- src/Workers/AbstractWorker.php | 16 ---------- src/Workers/WorkerWorkItem.php | 7 +---- tests/SeleniumTestCase.php | 2 +- 13 files changed, 48 insertions(+), 142 deletions(-) diff --git a/.php_cs b/.php_cs index 973b329..b172890 100644 --- a/.php_cs +++ b/.php_cs @@ -1,3 +1,41 @@ in($directory); + } +} + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setHideProgress(false) + ->setRules([ + '@PSR2' => true, + 'strict_param' => true, + 'array_syntax' => ['syntax' => 'short'], + '@PhpCsFixer' => true, + '@PHP73Migration' => true, + 'no_php4_constructor' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_superfluous_phpdoc_tags' => true, + 'void_return' => true, + 'yoda_style' => false, + ]) + ->setFinder($finder) + ; diff --git a/src/App.php b/src/App.php index 00b1455..339ff4f 100644 --- a/src/App.php +++ b/src/App.php @@ -103,19 +103,11 @@ class App $this->logger->debug(sprintf('Bootstrap complete in %sms', number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2))); } - /** - * @return string - */ public function getCachePath(): string { return $this->cachePath; } - /** - * @param string $cachePath - * - * @return App - */ public function setCachePath(string $cachePath): App { $this->cachePath = $cachePath; @@ -125,8 +117,6 @@ class App /** * Get item from Dependency Injection. - * - * @return mixed */ public function get(string $id) { @@ -351,8 +341,6 @@ class App } /** - * @param mixed $doNotUseStaticInstance - * * @return self */ public static function Instance(array $options = []) @@ -376,10 +364,6 @@ class App /** * Convenience function to get objects out of the Dependency Injection Container. - * - * @param string $key - * - * @return mixed */ public static function DI(string $key) { @@ -439,9 +423,9 @@ class App public function runHttp(): void { - $this->debugBar['time']->startMeasure('runHTTP', "HTTP runtime"); + $this->debugBar['time']->startMeasure('runHTTP', 'HTTP runtime'); $this->app->run(); - if($this->debugBar['time']->hasStartedMeasure('runHTTP')) { + if ($this->debugBar['time']->hasStartedMeasure('runHTTP')) { $this->debugBar['time']->stopMeasure('runHTTP'); } } diff --git a/src/Controllers/Filters/Filter.php b/src/Controllers/Filters/Filter.php index 5f669f4..35ad9cf 100644 --- a/src/Controllers/Filters/Filter.php +++ b/src/Controllers/Filters/Filter.php @@ -13,17 +13,12 @@ class Filter protected $order; protected $orderDirection; - /** - * @return mixed - */ public function getOrderDirection() { return $this->orderDirection; } /** - * @param mixed $orderDirection - * * @throws FilterDecodeException * * @return Filter @@ -71,17 +66,12 @@ class Filter return $this; } - /** - * @return mixed - */ public function getLimit() { return $this->limit; } /** - * @param mixed $limit - * * @return Filter */ public function setLimit($limit): self @@ -91,17 +81,12 @@ class Filter return $this; } - /** - * @return mixed - */ public function getOffset() { return $this->offset; } /** - * @param mixed $offset - * * @return Filter */ public function setOffset($offset): self @@ -111,17 +96,12 @@ class Filter return $this; } - /** - * @return mixed - */ public function getWheres() { return $this->wheres; } /** - * @param mixed $wheres - * * @return Filter */ public function setWheres($wheres): self @@ -131,17 +111,12 @@ class Filter return $this; } - /** - * @return mixed - */ public function getOrder() { return $this->order; } /** - * @param mixed $order - * * @return Filter */ public function setOrder($order): self diff --git a/src/Redis/Lua/LuaExtension.php b/src/Redis/Lua/LuaExtension.php index 33f5597..0937b8a 100644 --- a/src/Redis/Lua/LuaExtension.php +++ b/src/Redis/Lua/LuaExtension.php @@ -26,7 +26,7 @@ abstract class LuaExtension return $this->hash; } - public function load() + public function load(): void { if (!$this->hash) { $exists = $this->redis->script('exists', $this->getScript()); diff --git a/src/Redis/Redis.php b/src/Redis/Redis.php index d1cb4ed..1207c8e 100644 --- a/src/Redis/Redis.php +++ b/src/Redis/Redis.php @@ -28,7 +28,7 @@ class Redis extends \Redis $this->scripts[] = new Lua\ZAddIfLower($this); } - public function connect($host, $port = 6379, $timeout = 0.0, $reserved = null, $retryInterval = 0, $readTimeout = 0.0) + public function connect($host, $port = 6379, $timeout = 0.0, $reserved = null, $retryInterval = 0, $readTimeout = 0.0): void { parent::connect($host, $port, $timeout, $reserved, $retryInterval, $readTimeout); $this->initialiseExtensions(); diff --git a/src/Router/Route.php b/src/Router/Route.php index 1648bb4..7a74fcc 100644 --- a/src/Router/Route.php +++ b/src/Router/Route.php @@ -117,8 +117,6 @@ class Route } /** - * @param mixed $propertyOptions - * * @return Route */ public function setPropertyOptions($propertyOptions) @@ -340,8 +338,6 @@ class Route } /** - * @param mixed $exampleEntity - * * @return Route */ public function setExampleEntity($exampleEntity) @@ -357,8 +353,6 @@ class Route } /** - * @param mixed $exampleEntityFinderFunction - * * @return Route */ public function setExampleEntityFinderFunction($exampleEntityFinderFunction) diff --git a/src/Services/ConfigurationService.php b/src/Services/ConfigurationService.php index b79b6ee..752c6bc 100644 --- a/src/Services/ConfigurationService.php +++ b/src/Services/ConfigurationService.php @@ -36,9 +36,6 @@ class ConfigurationService } /** - * @param string $key - * @param null|string $defaultValue - * * @return null|array|string */ public function get(string $key, string $defaultValue = null) @@ -97,8 +94,6 @@ class ConfigurationService /** * Locate .benzine.yml. - * - * @param null|string $path */ protected function findConfig(string $path = null): bool { @@ -120,7 +115,7 @@ class ConfigurationService return true; } - protected function parseFile(string $file) + protected function parseFile(string $file): void { $yaml = file_get_contents($file); foreach ($this->environmentService->all() as $key => $value) { diff --git a/src/Services/QueueService.php b/src/Services/QueueService.php index ca03073..99c6142 100644 --- a/src/Services/QueueService.php +++ b/src/Services/QueueService.php @@ -21,7 +21,6 @@ class QueueService } /** - * @param string $queueName * @param \Serializable[] $queueItems * * @return int the number of items successfully added @@ -51,10 +50,6 @@ class QueueService /** * Get the length of the queue. - * - * @param string $queueName - * - * @return int */ public function getQueueLength(string $queueName): int { @@ -63,10 +58,6 @@ class QueueService /** * Get the peak/maximum length of the queue. - * - * @param string $queueName - * - * @return int */ public function getQueueLengthPeak(string $queueName): int { @@ -75,10 +66,6 @@ class QueueService /** * Number of seconds that the queue was created ago. - * - * @param string $queueName - * - * @return \DateTime */ public function getQueueCreatedAgo(string $queueName): \DateTime { @@ -89,10 +76,6 @@ class QueueService /** * Number of seconds ago that the queue was updated. - * - * @param string $queueName - * - * @return \DateTime */ public function getQueueUpdatedAgo(string $queueName): \DateTime { @@ -104,8 +87,6 @@ class QueueService /** * Number of seconds until a given queue will expire. * - * @param string $queueName - * * @return \DateTime */ public function getQueueExpiresIn(string $queueName): int @@ -114,9 +95,6 @@ class QueueService } /** - * @param string $queueName - * @param int $count - * * @return WorkerWorkItem[] */ public function pop(string $queueName, int $count = 1): array @@ -144,10 +122,6 @@ class QueueService /** * Destroy a queue and all data inside it. * Returns number of redis keys deleted. - * - * @param string $queueName - * - * @return int */ public function destroyQueue(string $queueName): int { @@ -172,8 +146,6 @@ class QueueService /** * Return an key->value array of queue lengths. - * - * @return array */ public function allQueueLengths(): array { diff --git a/src/Services/SessionService.php b/src/Services/SessionService.php index 3f18b10..4781824 100644 --- a/src/Services/SessionService.php +++ b/src/Services/SessionService.php @@ -20,23 +20,17 @@ class SessionService implements \SessionHandlerInterface return $this->get($name); } - /** - * @return int - */ public function getLifetime(): int { return $this->lifetime; } - /** - * @param int $lifetime - */ public function setLifetime(int $lifetime): void { $this->lifetime = $lifetime; } - public function initSession() + public function initSession(): void { if ('cli' === PHP_SAPI || PHP_SESSION_ACTIVE === session_status()) { return; diff --git a/src/Workers/AbstractQueueWorker.php b/src/Workers/AbstractQueueWorker.php index 91f2c48..36899cb 100644 --- a/src/Workers/AbstractQueueWorker.php +++ b/src/Workers/AbstractQueueWorker.php @@ -48,19 +48,11 @@ abstract class AbstractQueueWorker extends AbstractWorker ); } - /** - * @return QueueService - */ public function getQueueService(): QueueService { return $this->queueService; } - /** - * @param QueueService $queueService - * - * @return AbstractQueueWorker - */ public function setQueueService(QueueService $queueService): AbstractQueueWorker { $this->queueService = $queueService; @@ -68,19 +60,11 @@ abstract class AbstractQueueWorker extends AbstractWorker return $this; } - /** - * @return string - */ public function getInputQueue(): string { return $this->inputQueue; } - /** - * @param string $inputQueue - * - * @return AbstractQueueWorker - */ public function setInputQueue(string $inputQueue): AbstractQueueWorker { $this->inputQueue = $inputQueue; @@ -98,8 +82,6 @@ abstract class AbstractQueueWorker extends AbstractWorker /** * @param string[] $outputQueues - * - * @return AbstractQueueWorker */ public function setOutputQueues(array $outputQueues): AbstractQueueWorker { @@ -167,9 +149,6 @@ abstract class AbstractQueueWorker extends AbstractWorker return true; } - /** - * @return null|array - */ public function getResultItems(): ?array { return $this->resultItems; @@ -177,8 +156,6 @@ abstract class AbstractQueueWorker extends AbstractWorker /** * Send work item back to the queue it came from. - * - * @param WorkerWorkItem $item */ protected function returnToInputQueue(WorkerWorkItem $item): void { @@ -206,8 +183,6 @@ abstract class AbstractQueueWorker extends AbstractWorker } /** - * @param WorkerWorkItem $item - * * @return null|WorkerWorkItem|WorkerWorkItem[] */ abstract protected function process(WorkerWorkItem $item); diff --git a/src/Workers/AbstractWorker.php b/src/Workers/AbstractWorker.php index e63e1f8..04f0621 100644 --- a/src/Workers/AbstractWorker.php +++ b/src/Workers/AbstractWorker.php @@ -31,19 +31,11 @@ abstract class AbstractWorker implements WorkerInterface { } - /** - * @return array - */ public function getCliArguments(): array { return $this->cliArguments; } - /** - * @param array $cliArguments - * - * @return AbstractWorker - */ public function setCliArguments(array $cliArguments): AbstractWorker { $this->cliArguments = $cliArguments; @@ -62,19 +54,11 @@ abstract class AbstractWorker implements WorkerInterface } } - /** - * @return int - */ public function getTimeBetweenRuns(): int { return $this->timeBetweenRuns; } - /** - * @param int $timeBetweenRuns - * - * @return AbstractWorker - */ public function setTimeBetweenRuns(int $timeBetweenRuns): AbstractWorker { $this->timeBetweenRuns = $timeBetweenRuns; diff --git a/src/Workers/WorkerWorkItem.php b/src/Workers/WorkerWorkItem.php index 416f004..5dd3007 100644 --- a/src/Workers/WorkerWorkItem.php +++ b/src/Workers/WorkerWorkItem.php @@ -29,7 +29,7 @@ class WorkerWorkItem return serialize($this->data); } - public function unserialize($serialized) + public function unserialize($serialized): void { $this->data = unserialize($serialized); } @@ -43,17 +43,12 @@ class WorkerWorkItem ; } - /** - * @return array - */ public function getData(): array { return $this->data; } /** - * @param array $data - * * @return WorkerWorkItem */ public function setData(array $data): self diff --git a/tests/SeleniumTestCase.php b/tests/SeleniumTestCase.php index 065e9e8..82727c8 100644 --- a/tests/SeleniumTestCase.php +++ b/tests/SeleniumTestCase.php @@ -40,7 +40,7 @@ abstract class SeleniumTestCase extends BaseTestCase parent::tearDownAfterClass(); } - protected function takeScreenshot($name) + protected function takeScreenshot($name): void { self::$webDriver->takeScreenshot(self::$screenshotsDir.self::$screenshotIndex."_{$name}.jpg"); ++self::$screenshotIndex;