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:10 +02:00
parent 4e4c359682
commit 524ee6e6ee
11 changed files with 54 additions and 181 deletions

42
.php_cs
View file

@ -1,3 +1,41 @@
<?php <?php
define("__PHPCS_ROOT__", __DIR__); $finder = PhpCsFixer\Finder::create();
return require(__PHPCS_ROOT__ . "/vendor/benzine/benzine-style/php_cs.php");
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

@ -29,7 +29,7 @@ abstract class Model implements ModelInterface, \Serializable
{ {
} }
public function __wakeup() public function __wakeup(): void
{ {
$this->__setUp(); $this->__setUp();
} }
@ -98,17 +98,17 @@ abstract class Model implements ModelInterface, \Serializable
$this->__fromPublicArray($data); $this->__fromPublicArray($data);
} }
public function __pre_save() public function __pre_save(): void
{ {
// Stub function to be overridden. // Stub function to be overridden.
} }
public function __post_save() public function __post_save(): void
{ {
// Stub function to be overridden. // Stub function to be overridden.
} }
public function __set($name, $value) public function __set($name, $value): void
{ {
$this->{$name} = $value; $this->{$name} = $value;
} }
@ -235,7 +235,7 @@ abstract class Model implements ModelInterface, \Serializable
return json_encode($this->__toRawArray(), JSON_PRETTY_PRINT); return json_encode($this->__toRawArray(), JSON_PRETTY_PRINT);
} }
public function unserialize($serialized) public function unserialize($serialized): void
{ {
$unserialized = json_decode($serialized); $unserialized = json_decode($serialized);
foreach ($unserialized as $k => $v) { foreach ($unserialized as $k => $v) {

View file

@ -90,8 +90,6 @@ abstract class Service
} }
/** /**
* @param Sql\Where $where
*
* @return Benzine\ORM\Abstracts\Model[] * @return Benzine\ORM\Abstracts\Model[]
*/ */
public function search(Sql\Where $where): array public function search(Sql\Where $where): array

View file

@ -32,7 +32,7 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
parent::__construct($table, $adapter, $features, $resultSetPrototype, $sql); parent::__construct($table, $adapter, $features, $resultSetPrototype, $sql);
} }
public function __set($property, $value) public function __set($property, $value): void
{ {
if (property_exists($this, $property)) { if (property_exists($this, $property)) {
$this->{$property} = $value; $this->{$property} = $value;
@ -221,7 +221,7 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
if ($conditional instanceof \Closure) { if ($conditional instanceof \Closure) {
$select->where($conditional); $select->where($conditional);
} else { } else {
$spec = function (Where $where) use ($conditional) { $spec = function (Where $where) use ($conditional): void {
switch ($conditional['condition']) { switch ($conditional['condition']) {
case FilterCondition::CONDITION_EQUAL: case FilterCondition::CONDITION_EQUAL:
$where->equalTo($conditional['column'], $conditional['value']); $where->equalTo($conditional['column'], $conditional['value']);
@ -326,7 +326,7 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
if ($conditional instanceof \Closure) { if ($conditional instanceof \Closure) {
$select->where($conditional); $select->where($conditional);
} else { } else {
$spec = function (Where $where) use ($conditional) { $spec = function (Where $where) use ($conditional): void {
switch ($conditional['condition']) { switch ($conditional['condition']) {
case FilterCondition::CONDITION_EQUAL: case FilterCondition::CONDITION_EQUAL:
$where->equalTo($conditional['column'], $conditional['value']); $where->equalTo($conditional['column'], $conditional['value']);
@ -389,7 +389,7 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
*/ */
public function fetchRandom() public function fetchRandom()
{ {
$resultSet = $this->select(function (Select $select) { $resultSet = $this->select(function (Select $select): void {
switch ($this->adapter->getDriver()->getDatabasePlatformName()) { switch ($this->adapter->getDriver()->getDatabasePlatformName()) {
case 'MySQL': case 'MySQL':
$select->order(new Expression('RAND()')); $select->order(new Expression('RAND()'));
@ -424,7 +424,7 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
if ($where instanceof Select) { if ($where instanceof Select) {
$resultSet = $this->selectWith($where); $resultSet = $this->selectWith($where);
} else { } else {
$resultSet = $this->select(function (Select $select) use ($where, $order, $offset) { $resultSet = $this->select(function (Select $select) use ($where, $order, $offset): void {
if (!is_null($where)) { if (!is_null($where)) {
$select->where($where); $select->where($where);
} }
@ -441,10 +441,6 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
return (count($resultSet) > 0) ? $resultSet->current() : null; return (count($resultSet) > 0) ? $resultSet->current() : null;
} }
/**
* @param PredicateInterface[]|Where[] $where
* @param mixed $wheres
*/
public function getCount($wheres = []): int public function getCount($wheres = []): int
{ {
$select = $this->getSql()->select(); $select = $this->getSql()->select();
@ -505,8 +501,6 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
/** /**
* Returns an array of all primary keys on the table keyed by the column. * Returns an array of all primary keys on the table keyed by the column.
*
* @return array
*/ */
public function getHighestPrimaryKey(): array public function getHighestPrimaryKey(): array
{ {
@ -529,8 +523,6 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
/** /**
* Returns an array of all autoincrement keys on the table keyed by the column. * Returns an array of all autoincrement keys on the table keyed by the column.
*
* @return array
*/ */
public function getHighestAutoincrementKey(): array public function getHighestAutoincrementKey(): array
{ {
@ -737,9 +729,6 @@ abstract class TableGateway extends \Laminas\Db\TableGateway\TableGateway
return $results; return $results;
} }
/**
* @return Model
*/
public function getNewModelInstance(array $data = []): Model public function getNewModelInstance(array $data = []): Model
{ {
$model = $this->model; $model = $this->model;

View file

@ -88,17 +88,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getPhpType() public function getPhpType()
{ {
return $this->phpType; return $this->phpType;
} }
/** /**
* @param mixed $phpType
*
* @return Column * @return Column
*/ */
public function setPhpType($phpType) public function setPhpType($phpType)
@ -124,8 +119,6 @@ class Column extends Entity
} }
/** /**
* @param mixed $field
*
* @return Column * @return Column
*/ */
public function setField($field) public function setField($field)
@ -135,17 +128,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getDbField() public function getDbField()
{ {
return $this->dbField; return $this->dbField;
} }
/** /**
* @param mixed $dbField
*
* @return Column * @return Column
*/ */
public function setDbField($dbField) public function setDbField($dbField)
@ -160,17 +148,12 @@ class Column extends Entity
return $this->transCamel2Studly->transform($this->getFieldSanitised()); return $this->transCamel2Studly->transform($this->getFieldSanitised());
} }
/**
* @return mixed
*/
public function getMaxDecimalPlaces() public function getMaxDecimalPlaces()
{ {
return $this->maxDecimalPlaces; return $this->maxDecimalPlaces;
} }
/** /**
* @param mixed $maxDecimalPlaces
*
* @return Column * @return Column
*/ */
public function setMaxDecimalPlaces($maxDecimalPlaces) public function setMaxDecimalPlaces($maxDecimalPlaces)
@ -180,17 +163,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getDefaultValue() public function getDefaultValue()
{ {
return $this->defaultValue; return $this->defaultValue;
} }
/** /**
* @param mixed $defaultValue
*
* @return Column * @return Column
*/ */
public function setDefaultValue($defaultValue) public function setDefaultValue($defaultValue)
@ -211,19 +189,11 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return bool
*/
public function isDefaultValueIsLiteral(): bool public function isDefaultValueIsLiteral(): bool
{ {
return $this->defaultValueIsLiteral; return $this->defaultValueIsLiteral;
} }
/**
* @param bool $defaultValueIsLiteral
*
* @return Column
*/
public function setDefaultValueIsLiteral(bool $defaultValueIsLiteral): Column public function setDefaultValueIsLiteral(bool $defaultValueIsLiteral): Column
{ {
$this->defaultValueIsLiteral = $defaultValueIsLiteral; $this->defaultValueIsLiteral = $defaultValueIsLiteral;
@ -231,17 +201,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getMaxLength() public function getMaxLength()
{ {
return $this->maxLength; return $this->maxLength;
} }
/** /**
* @param mixed $maxLength
*
* @return Column * @return Column
*/ */
public function setMaxLength($maxLength) public function setMaxLength($maxLength)
@ -251,17 +216,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getMaxFieldLength() public function getMaxFieldLength()
{ {
return $this->maxFieldLength; return $this->maxFieldLength;
} }
/** /**
* @param mixed $maxFieldLength
*
* @return Column * @return Column
*/ */
public function setMaxFieldLength($maxFieldLength) public function setMaxFieldLength($maxFieldLength)
@ -271,17 +231,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getDbType() public function getDbType()
{ {
return $this->dbType; return $this->dbType;
} }
/** /**
* @param mixed $dbType
*
* @throws DBTypeNotTranslatedException * @throws DBTypeNotTranslatedException
* *
* @return Column * @return Column
@ -342,17 +297,12 @@ class Column extends Entity
return $this; return $this;
} }
/**
* @return mixed
*/
public function getPermittedValues() public function getPermittedValues()
{ {
return $this->permittedValues; return $this->permittedValues;
} }
/** /**
* @param mixed $permittedValues
*
* @return Column * @return Column
*/ */
public function setPermittedValues($permittedValues) public function setPermittedValues($permittedValues)

View file

@ -32,7 +32,6 @@ class Model extends Entity
/** /**
* @param Model[] $models * @param Model[] $models
* @param array $keyMap
* @param ConstraintObject[] $zendConstraints * @param ConstraintObject[] $zendConstraints
*/ */
public function computeConstraints(array $models, array $keyMap, array $zendConstraints): self public function computeConstraints(array $models, array $keyMap, array $zendConstraints): self
@ -161,7 +160,7 @@ class Model extends Entity
/** /**
* @param Model[] $models * @param Model[] $models
*/ */
public function scanForRemoteRelations(array &$models) public function scanForRemoteRelations(array &$models): void
{ {
//echo "Scan: {$this->getClassName()}\n"; //echo "Scan: {$this->getClassName()}\n";
foreach ($this->getColumns() as $column) { foreach ($this->getColumns() as $column) {
@ -360,9 +359,6 @@ class Model extends Entity
return $this->namespace; return $this->namespace;
} }
/**
* @param string $namespace
*/
public function setNamespace(string $namespace): self public function setNamespace(string $namespace): self
{ {
$this->namespace = $namespace; $this->namespace = $namespace;
@ -450,9 +446,6 @@ class Model extends Entity
return $parameters; return $parameters;
} }
/**
* @return mixed
*/
public function getAutoIncrements() public function getAutoIncrements()
{ {
$autoincrementKeys = []; $autoincrementKeys = [];
@ -467,9 +460,6 @@ class Model extends Entity
return $autoincrementKeys; return $autoincrementKeys;
} }
/**
* @param mixed $autoIncrements
*/
public function setAutoIncrements($autoIncrements): self public function setAutoIncrements($autoIncrements): self
{ {
$this->autoIncrements = $autoIncrements; $this->autoIncrements = $autoIncrements;
@ -477,9 +467,6 @@ class Model extends Entity
return $this; return $this;
} }
/**
* @return null|string
*/
public function getClassPrefix(): ?string public function getClassPrefix(): ?string
{ {
return $this->classPrefix; return $this->classPrefix;
@ -487,10 +474,6 @@ class Model extends Entity
/** /**
* When set to null, this class has no prefix. * When set to null, this class has no prefix.
*
* @param null|string $classPrefix
*
* @return Model
*/ */
public function setClassPrefix(?string $classPrefix): Model public function setClassPrefix(?string $classPrefix): Model
{ {

View file

@ -22,19 +22,11 @@ class RelatedModel extends Entity
protected Model $relatedModel; protected Model $relatedModel;
/**
* @return Database
*/
public function getDatabase(): Database public function getDatabase(): Database
{ {
return $this->database; return $this->database;
} }
/**
* @param Database $database
*
* @return RelatedModel
*/
public function setDatabase(Database $database): RelatedModel public function setDatabase(Database $database): RelatedModel
{ {
$this->database = $database; $this->database = $database;
@ -319,19 +311,11 @@ class RelatedModel extends Entity
return $this->getRemoteClassPrefix(); return $this->getRemoteClassPrefix();
} }
/**
* @return Model
*/
public function getLocalRelatedModel(): Model public function getLocalRelatedModel(): Model
{ {
return $this->relatedModel; return $this->relatedModel;
} }
/**
* @param Model $localRelatedModel
*
* @return RelatedModel
*/
public function setLocalRelatedModel(Model $localRelatedModel): RelatedModel public function setLocalRelatedModel(Model $localRelatedModel): RelatedModel
{ {
$this->relatedModel = $localRelatedModel; $this->relatedModel = $localRelatedModel;
@ -339,19 +323,11 @@ class RelatedModel extends Entity
return $this; return $this;
} }
/**
* @return Model
*/
public function getRemoteRelatedModel(): Model public function getRemoteRelatedModel(): Model
{ {
return $this->remoteRelatedModel; return $this->remoteRelatedModel;
} }
/**
* @param Model $remoteRelatedModel
*
* @return RelatedModel
*/
public function setRemoteRelatedModel(Model $remoteRelatedModel): RelatedModel public function setRemoteRelatedModel(Model $remoteRelatedModel): RelatedModel
{ {
$this->remoteRelatedModel = $remoteRelatedModel; $this->remoteRelatedModel = $remoteRelatedModel;

View file

@ -42,19 +42,11 @@ class Database
} }
} }
/**
* @return string
*/
public function getName(): string public function getName(): string
{ {
return $this->name; return $this->name;
} }
/**
* @param string $name
*
* @return Database
*/
public function setName(string $name): Database public function setName(string $name): Database
{ {
$this->name = $name; $this->name = $name;
@ -62,19 +54,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getType(): string public function getType(): string
{ {
return $this->type; return $this->type;
} }
/**
* @param string $type
*
* @return Database
*/
public function setType(string $type): Database public function setType(string $type): Database
{ {
$this->type = $type; $this->type = $type;
@ -82,19 +66,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getHostname(): string public function getHostname(): string
{ {
return $this->hostname; return $this->hostname;
} }
/**
* @param string $hostname
*
* @return Database
*/
public function setHostname(string $hostname): Database public function setHostname(string $hostname): Database
{ {
$this->hostname = $hostname; $this->hostname = $hostname;
@ -102,19 +78,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getUsername(): string public function getUsername(): string
{ {
return $this->username; return $this->username;
} }
/**
* @param string $username
*
* @return Database
*/
public function setUsername(string $username): Database public function setUsername(string $username): Database
{ {
$this->username = $username; $this->username = $username;
@ -122,19 +90,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getPassword(): string public function getPassword(): string
{ {
return $this->password; return $this->password;
} }
/**
* @param string $password
*
* @return Database
*/
public function setPassword(string $password): Database public function setPassword(string $password): Database
{ {
$this->password = $password; $this->password = $password;
@ -142,19 +102,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getDatabase(): string public function getDatabase(): string
{ {
return $this->database; return $this->database;
} }
/**
* @param string $database
*
* @return Database
*/
public function setDatabase(string $database): Database public function setDatabase(string $database): Database
{ {
$this->database = $database; $this->database = $database;
@ -162,19 +114,11 @@ class Database
return $this; return $this;
} }
/**
* @return string
*/
public function getCharset(): string public function getCharset(): string
{ {
return $this->charset; return $this->charset;
} }
/**
* @param string $charset
*
* @return Database
*/
public function setCharset(string $charset): Database public function setCharset(string $charset): Database
{ {
$this->charset = $charset; $this->charset = $charset;

View file

@ -9,17 +9,12 @@ class Table extends Entity
/** @var Column */ /** @var Column */
protected $columns; protected $columns;
/**
* @return mixed
*/
public function getTableName() public function getTableName()
{ {
return $this->tableName; return $this->tableName;
} }
/** /**
* @param mixed $tableName
*
* @return Table * @return Table
*/ */
public function setTableName($tableName) public function setTableName($tableName)

View file

@ -134,7 +134,7 @@ class Laminator
return $this->workPath; return $this->workPath;
} }
public function exceptionHandler($exception) public function exceptionHandler($exception): void
{ {
// UHOH exception handler // UHOH exception handler
/** @var \Exception $exception */ /** @var \Exception $exception */

View file

@ -32,7 +32,7 @@ class Profiler implements ProfilerInterface
]; ];
} }
public function profilerStart($target) public function profilerStart($target): void
{ {
if (is_string($target)) { if (is_string($target)) {
$this->sql = $target; $this->sql = $target;
@ -48,7 +48,7 @@ class Profiler implements ProfilerInterface
$this->timer = microtime(true); $this->timer = microtime(true);
} }
public function profilerFinish() public function profilerFinish(): void
{ {
$uuid = UUID::v4(); $uuid = UUID::v4();
$executionTime = microtime(true) - $this->timer; $executionTime = microtime(true) - $this->timer;