Stricter php-cs-fixer rules. These remove a lot of superfluous duplicitous rubbish, mostly in docblocks.

This commit is contained in:
Greyscale 2020-07-31 23:15:09 +02:00
parent e9519be717
commit a5074e695d
13 changed files with 48 additions and 142 deletions

42
.php_cs
View file

@ -1,3 +1,41 @@
<?php
define("__PHPCS_ROOT__", __DIR__);
return require(__PHPCS_ROOT__ . "/vendor/benzine/benzine-style/php_cs.php");
$finder = PhpCsFixer\Finder::create();
if (!defined('__PHPCS_ROOT__')) {
define('__PHPCS_ROOT__', __DIR__);
}
$directories = [
__PHPCS_ROOT__.'/src',
__PHPCS_ROOT__.'/bin',
__PHPCS_ROOT__.'/tests',
];
if (isset($additionalDirectories)) {
$directories = array_merge($directories, $additionalDirectories);
}
foreach ($directories as $directory) {
if (file_exists($directory) && is_dir($directory)) {
$finder->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)
;

View file

@ -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');
}
}

View file

@ -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

View file

@ -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());

View file

@ -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();

View file

@ -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)

View file

@ -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) {

View file

@ -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
{

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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;