From fbbb7c99c0b6037b363f529a94451228655c1b37 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 17 Feb 2023 16:38:13 +0200 Subject: [PATCH] cs --- application/Espo/ORM/Defs/Defs.php | 8 +-- application/Espo/ORM/Defs/DefsData.php | 12 ++--- application/Espo/ORM/Defs/EntityDefs.php | 43 ++++++---------- application/Espo/ORM/Defs/FieldDefs.php | 14 ++---- application/Espo/ORM/Defs/IndexDefs.php | 2 +- application/Espo/ORM/Defs/RelationDefs.php | 49 +++++++------------ application/Espo/ORM/Locker/BaseLocker.php | 25 +++------- application/Espo/ORM/Locker/MysqlLocker.php | 14 +++--- .../Repository/RDBRelationSelectBuilder.php | 10 ++-- .../ORM/Repository/RDBTransactionManager.php | 8 +-- .../Espo/ORM/Repository/Repository.php | 4 +- .../Espo/ORM/Repository/RepositoryFactory.php | 4 +- 12 files changed, 70 insertions(+), 123 deletions(-) diff --git a/application/Espo/ORM/Defs/Defs.php b/application/Espo/ORM/Defs/Defs.php index 260eadcb22..d6f2191f56 100644 --- a/application/Espo/ORM/Defs/Defs.php +++ b/application/Espo/ORM/Defs/Defs.php @@ -36,12 +36,8 @@ use RuntimeException; */ class Defs { - private $data; - - public function __construct(DefsData $data) - { - $this->data = $data; - } + public function __construct(private DefsData $data) + {} /** * Get an entity type list. diff --git a/application/Espo/ORM/Defs/DefsData.php b/application/Espo/ORM/Defs/DefsData.php index a05ff37fb1..321eef968a 100644 --- a/application/Espo/ORM/Defs/DefsData.php +++ b/application/Espo/ORM/Defs/DefsData.php @@ -35,17 +35,11 @@ use RuntimeException; class DefsData { - /** - * @var array - */ + /** @var array */ private array $cache = []; - private Metadata $metadata; - - public function __construct(Metadata $metadata) - { - $this->metadata = $metadata; - } + public function __construct(private Metadata $metadata) + {} public function clearCache(): void { diff --git a/application/Espo/ORM/Defs/EntityDefs.php b/application/Espo/ORM/Defs/EntityDefs.php index 942a561ca2..f55acb0a98 100644 --- a/application/Espo/ORM/Defs/EntityDefs.php +++ b/application/Espo/ORM/Defs/EntityDefs.php @@ -33,46 +33,28 @@ use RuntimeException; class EntityDefs { - /** - * @var array> - */ + /** @var array|mixed> */ private array $data; - private string $name; - - /** - * @var array - */ + /** @var array */ private $attributeCache = []; - - /** - * @var array - */ + /** @var array */ private $relationCache = []; - - /** - * @var array - */ + /** @var array */ private $indexCache = []; - - /** - * @var array - */ + /** @var array */ private $fieldCache = []; private function __construct() - { - } + {} /** - * @param array $raw + * @param array $raw */ public static function fromRaw(array $raw, string $name): self { $obj = new self(); - $obj->data = $raw; - $obj->name = $name; return $obj; @@ -93,6 +75,7 @@ class EntityDefs */ public function getAttributeNameList(): array { + /** @var string[] */ return array_keys($this->data['attributes'] ?? $this->data['fields'] ?? []); } @@ -103,6 +86,7 @@ class EntityDefs */ public function getRelationNameList(): array { + /** @var string[] */ return array_keys($this->data['relations'] ?? []); } @@ -113,6 +97,7 @@ class EntityDefs */ public function getIndexNameList(): array { + /** @var string[] */ return array_keys($this->data['indexes'] ?? []); } @@ -123,6 +108,7 @@ class EntityDefs */ public function getFieldNameList(): array { + /** @var string[] */ return array_keys($this->data['vFields'] ?? []); } @@ -232,6 +218,7 @@ class EntityDefs /** * Get an attribute definitions. + * * @throws RuntimeException */ public function getAttribute(string $name): AttributeDefs @@ -264,6 +251,7 @@ class EntityDefs /** * Get an index definitions. + * * @throws RuntimeException */ public function getIndex(string $name): IndexDefs @@ -280,6 +268,7 @@ class EntityDefs /** * Get a field definitions. + * * @throws RuntimeException */ public function getField(string $name): FieldDefs @@ -304,10 +293,8 @@ class EntityDefs /** * Get a parameter value by a name. - * - * @return mixed */ - public function getParam(string $name) + public function getParam(string $name): mixed { return $this->data[$name] ?? null; } diff --git a/application/Espo/ORM/Defs/FieldDefs.php b/application/Espo/ORM/Defs/FieldDefs.php index 7a7b8da35b..831b72cda3 100644 --- a/application/Espo/ORM/Defs/FieldDefs.php +++ b/application/Espo/ORM/Defs/FieldDefs.php @@ -36,16 +36,12 @@ use RuntimeException; */ class FieldDefs { - /** - * @var array - */ - private $data; - + /** @var array */ + private array $data; private string $name; private function __construct() - { - } + {} /** * @param array $raw @@ -91,10 +87,8 @@ class FieldDefs /** * Get a parameter value by a name. - * - * @return mixed */ - public function getParam(string $name) + public function getParam(string $name): mixed { return $this->data[$name] ?? null; } diff --git a/application/Espo/ORM/Defs/IndexDefs.php b/application/Espo/ORM/Defs/IndexDefs.php index a94983d9f3..5fd51ef7b7 100644 --- a/application/Espo/ORM/Defs/IndexDefs.php +++ b/application/Espo/ORM/Defs/IndexDefs.php @@ -34,7 +34,7 @@ namespace Espo\ORM\Defs; */ class IndexDefs { - /** @var array */ + /** @var array */ private $data; private string $name; diff --git a/application/Espo/ORM/Defs/RelationDefs.php b/application/Espo/ORM/Defs/RelationDefs.php index 94d485aca1..470cb90b78 100644 --- a/application/Espo/ORM/Defs/RelationDefs.php +++ b/application/Espo/ORM/Defs/RelationDefs.php @@ -38,19 +38,15 @@ use RuntimeException; */ class RelationDefs { - /** - * @var array - */ + /** @var array */ private array $data; - private string $name; private function __construct() - { - } + {} /** - * @param array $raw + * @param array $raw */ public static function fromRaw(array $raw, string $name): self { @@ -141,14 +137,13 @@ class RelationDefs /** * Get a foreign entity type. + * * @throws RuntimeException */ public function getForeignEntityType(): string { if (!$this->hasForeignEntityType()) { - throw new RuntimeException( - "No 'entity' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'entity' parameter defined in the relation '{$this->name}'."); } return $this->data['entity']; @@ -164,14 +159,13 @@ class RelationDefs /** * Get a foreign relation name. + * * @throws RuntimeException */ public function getForeignRelationName(): string { if (!$this->hasForeignRelationName()) { - throw new RuntimeException( - "No 'foreign' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'foreign' parameter defined in the relation '{$this->name}'."); } return $this->data['foreign']; @@ -187,14 +181,13 @@ class RelationDefs /** * Get a foreign key. + * * @throws RuntimeException */ public function getForeignKey(): string { if (!$this->hasForeignKey()) { - throw new RuntimeException( - "No 'foreignKey' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'foreignKey' parameter defined in the relation '{$this->name}'."); } return $this->data['foreignKey']; @@ -215,9 +208,7 @@ class RelationDefs public function getKey(): string { if (!$this->hasKey()) { - throw new RuntimeException( - "No 'key' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'key' parameter defined in the relation '{$this->name}'."); } return $this->data['key']; @@ -233,14 +224,13 @@ class RelationDefs /** * Get a mid-key. For Many-to-Many relationships only. + * * @throws RuntimeException */ public function getMidKey(): string { if (!$this->hasMidKey()) { - throw new RuntimeException( - "No 'midKey' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'midKey' parameter defined in the relation '{$this->name}'."); } return $this->data['midKeys'][0]; @@ -248,6 +238,7 @@ class RelationDefs /** * Whether a foreign mid-key is defined. For Many-to-Many relationships only. + * * @throws RuntimeException */ public function hasForeignMidKey(): bool @@ -257,14 +248,13 @@ class RelationDefs /** * Get a foreign mid-key. For Many-to-Many relationships only. + * * @throws RuntimeException */ public function getForeignMidKey(): string { if (!$this->hasForeignMidKey()) { - throw new RuntimeException( - "No 'foreignMidKey' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'foreignMidKey' parameter defined in the relation '{$this->name}'."); } return $this->data['midKeys'][1]; @@ -280,14 +270,13 @@ class RelationDefs /** * Get a relationship name. + * * @throws RuntimeException */ public function getRelationshipName(): string { if (!$this->hasRelationshipName()) { - throw new RuntimeException( - "No 'relationName' parameter defined in the relation '{$this->name}'." - ); + throw new RuntimeException("No 'relationName' parameter defined in the relation '{$this->name}'."); } return $this->data['relationName']; @@ -324,10 +313,8 @@ class RelationDefs /** * Get a parameter value by a name. - * - * @return mixed */ - public function getParam(string $name) + public function getParam(string $name): mixed { return $this->data[$name] ?? null; } diff --git a/application/Espo/ORM/Locker/BaseLocker.php b/application/Espo/ORM/Locker/BaseLocker.php index 9fdbbe54d4..542887bdcd 100644 --- a/application/Espo/ORM/Locker/BaseLocker.php +++ b/application/Espo/ORM/Locker/BaseLocker.php @@ -29,31 +29,22 @@ namespace Espo\ORM\Locker; -use Espo\ORM\{ - TransactionManager, - QueryComposer\QueryComposer, - Query\LockTableBuilder, -}; +use Espo\ORM\Query\LockTableBuilder; +use Espo\ORM\QueryComposer\QueryComposer; +use Espo\ORM\TransactionManager; use PDO; use RuntimeException; class BaseLocker implements Locker { - private PDO $pdo; - - private QueryComposer $queryComposer; - - private TransactionManager $transactionManager; - private bool $isLocked = false; - public function __construct(PDO $pdo, QueryComposer $queryComposer, TransactionManager $transactionManager) - { - $this->pdo = $pdo; - $this->queryComposer = $queryComposer; - $this->transactionManager = $transactionManager; - } + public function __construct( + private PDO $pdo, + private QueryComposer $queryComposer, + private TransactionManager $transactionManager + ) {} /** * {@inheritdoc} diff --git a/application/Espo/ORM/Locker/MysqlLocker.php b/application/Espo/ORM/Locker/MysqlLocker.php index 8e286e233b..bf8e15f53d 100644 --- a/application/Espo/ORM/Locker/MysqlLocker.php +++ b/application/Espo/ORM/Locker/MysqlLocker.php @@ -31,11 +31,8 @@ namespace Espo\ORM\Locker; use Espo\ORM\QueryComposer\QueryComposer; use Espo\ORM\QueryComposer\MysqlQueryComposer; - -use Espo\ORM\{ - TransactionManager, - Query\LockTableBuilder, -}; +use Espo\ORM\Query\LockTableBuilder; +use Espo\ORM\TransactionManager; use PDO; use RuntimeException; @@ -52,8 +49,11 @@ class MysqlLocker implements Locker private bool $isLocked = false; - public function __construct(PDO $pdo, QueryComposer $queryComposer, TransactionManager $transactionManager) - { + public function __construct( + PDO $pdo, + QueryComposer $queryComposer, + TransactionManager $transactionManager + ) { if (!$queryComposer instanceof MysqlQueryComposer) { throw new RuntimeException(); } diff --git a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php index b84ac1e19d..8b21bac95f 100644 --- a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php @@ -121,7 +121,7 @@ class RDBRelationSelectBuilder * Usage example: * `->columnsWhere(['column' => $value])` * - * @param WhereItem|array $clause Where clause. + * @param WhereItem|array $clause Where clause. */ public function columnsWhere($clause): self { @@ -252,7 +252,7 @@ class RDBRelationSelectBuilder * @param Join|string $target * A relation name or table. A relation name should be in camelCase, a table in CamelCase. * @param string|null $alias An alias. - * @param WhereItem|array|null $conditions Join conditions. + * @param WhereItem|array|null $conditions Join conditions. */ public function leftJoin($target, ?string $alias = null, $conditions = null): self { @@ -289,7 +289,7 @@ class RDBRelationSelectBuilder * * `where(array $clause)` * * `where(string $key, string $value)` * - * @param WhereItem|array|string $clause A key or where clause. + * @param WhereItem|array|string $clause A key or where clause. * @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string. */ public function where($clause = [], $value = null): self @@ -439,8 +439,8 @@ class RDBRelationSelectBuilder } /** - * @param array $where - * @return array + * @param array $where + * @return array */ protected function applyRelationAliasToWhereClause(array $where): array { diff --git a/application/Espo/ORM/Repository/RDBTransactionManager.php b/application/Espo/ORM/Repository/RDBTransactionManager.php index 9939866802..3cd03e36af 100644 --- a/application/Espo/ORM/Repository/RDBTransactionManager.php +++ b/application/Espo/ORM/Repository/RDBTransactionManager.php @@ -38,14 +38,10 @@ use RuntimeException; */ class RDBTransactionManager { - private TransactionManager $transactionManager; - private int $level = 0; - public function __construct(TransactionManager $transactionManager) - { - $this->transactionManager = $transactionManager; - } + public function __construct(private TransactionManager $transactionManager) + {} public function isStarted(): bool { diff --git a/application/Espo/ORM/Repository/Repository.php b/application/Espo/ORM/Repository/Repository.php index deb7f0a4ac..94bc9c9bde 100644 --- a/application/Espo/ORM/Repository/Repository.php +++ b/application/Espo/ORM/Repository/Repository.php @@ -56,7 +56,7 @@ interface Repository * Store an entity. * * @param TEntity $entity - * @param array $options + * @param array $options */ public function save(Entity $entity, array $options = []): void; @@ -64,7 +64,7 @@ interface Repository * Remove an entity. * * @param TEntity $entity - * @param array $options + * @param array $options */ public function remove(Entity $entity, array $options = []): void; } diff --git a/application/Espo/ORM/Repository/RepositoryFactory.php b/application/Espo/ORM/Repository/RepositoryFactory.php index 4a781e45d4..3397d2c043 100644 --- a/application/Espo/ORM/Repository/RepositoryFactory.php +++ b/application/Espo/ORM/Repository/RepositoryFactory.php @@ -29,10 +29,12 @@ namespace Espo\ORM\Repository; +use Espo\ORM\Entity; + interface RepositoryFactory { /** - * @return Repository<\Espo\ORM\Entity> + * @return Repository */ public function create(string $entityType): Repository; }