diff --git a/application/Espo/ORM/QueryComposer/Util.php b/application/Espo/ORM/QueryComposer/Util.php index 895081f9ba..be588dd7a9 100644 --- a/application/Espo/ORM/QueryComposer/Util.php +++ b/application/Espo/ORM/QueryComposer/Util.php @@ -70,12 +70,20 @@ class Util return in_array(strtoupper($argument), ['NULL', 'TRUE', 'FALSE']); } + /** + * @param string $expression + * @return string[] + */ public static function getAllAttributesFromComplexExpression(string $expression): array { return self::getAllAttributesFromComplexExpressionImplementation($expression); } - protected static function getAllAttributesFromComplexExpressionImplementation( + /** + * @param string[]|null $list + * @return string[] + */ + private static function getAllAttributesFromComplexExpressionImplementation( string $expression, ?array &$list = null ): array { @@ -113,6 +121,9 @@ class Util return $list; } + /** + * @return string[] + */ static public function parseArgumentListFromFunctionContent(string $functionContent): array { $functionContent = trim($functionContent); diff --git a/application/Espo/ORM/Repository/HookMediator.php b/application/Espo/ORM/Repository/HookMediator.php index 4d5cae8d14..351d2c0efc 100644 --- a/application/Espo/ORM/Repository/HookMediator.php +++ b/application/Espo/ORM/Repository/HookMediator.php @@ -29,21 +29,35 @@ namespace Espo\ORM\Repository; -use Espo\ORM\{ - Entity, - Query\Select, -}; +use Espo\ORM\Entity; +use Espo\ORM\Query\Select; interface HookMediator { + /** + * @param array $options + */ public function beforeSave(Entity $entity, array $options): void; + /** + * @param array $options + */ public function afterSave(Entity $entity, array $options): void; + /** + * @param array $options + */ public function beforeRemove(Entity $entity, array $options): void; + /** + * @param array $options + */ public function afterRemove(Entity $entity, array $options): void; + /** + * @param array|null $columnData Role values. + * @param array $options + */ public function beforeRelate( Entity $entity, string $relationName, @@ -52,6 +66,10 @@ interface HookMediator array $options ): void; + /** + * @param array|null $columnData Role values. + * @param array $options + */ public function afterRelate( Entity $entity, string $relationName, @@ -60,11 +78,23 @@ interface HookMediator array $options ): void; + /** + * @param array $options + */ public function beforeUnrelate(Entity $entity, string $relationName, Entity $foreignEntity, array $options): void; + /** + * @param array $options + */ public function afterUnrelate(Entity $entity, string $relationName, Entity $foreignEntity, array $options): void; + /** + * @param array $options + */ public function beforeMassRelate(Entity $entity, string $relationName, Select $query, array $options): void; + /** + * @param array $options + */ public function afterMassRelate(Entity $entity, string $relationName, Select $query, array $options): void; } diff --git a/application/Espo/ORM/Repository/RDBRelation.php b/application/Espo/ORM/Repository/RDBRelation.php index 10ac093454..1f4ae588d1 100644 --- a/application/Espo/ORM/Repository/RDBRelation.php +++ b/application/Espo/ORM/Repository/RDBRelation.php @@ -149,9 +149,7 @@ class RDBRelation /** * Find related records. * - * @phpstan-return iterable&Collection - * - * @todo Fix phpstan-return after php5.4 to Collection or remove. + * @return Collection */ public function find(): Collection { @@ -205,7 +203,7 @@ class RDBRelation * @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 join($target, ?string $alias = null, $conditions = null): Builder { @@ -218,7 +216,7 @@ class RDBRelation * @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): Builder { @@ -249,8 +247,8 @@ class RDBRelation * * `where(array $clause)` * * `where(string $key, string $value)` * - * @param WhereItem|array|string $clause A key or where clause. - * @param array|string|null $value A value. Omitted if the first argument is not string. + * @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): Builder { @@ -265,8 +263,8 @@ class RDBRelation * * `having(array $clause)` * * `having(string $key, string $value)` * - * @param WhereItem|array|string $clause A key or where clause. - * @param array|string|null $value A value. Omitted if the first argument is not string. + * @param WhereItem|array|string $clause A key or where clause. + * @param mixed[]|string|null $value A value. Should be omitted if the first argument is not string. */ public function having($clause = [], $value = null): Builder { @@ -339,6 +337,7 @@ class RDBRelation /** * @deprecated Use `group` method. + * @param Expression|Expression[]|string|string[] $groupBy */ public function groupBy($groupBy): Builder { @@ -351,7 +350,7 @@ class RDBRelation * Usage example: * `->columnsWhere(['column' => $value])` * - * @param WhereItem|array $clause Where clause. + * @param WhereItem|array $clause Where clause. */ public function columnsWhere($clause): Builder { @@ -435,6 +434,9 @@ class RDBRelation /** * Relate with an entity by ID. + * + * @param array|null $columnData Role values. + * @param array $options */ public function relateById(string $id, ?array $columnData = null, array $options = []): void { @@ -458,6 +460,8 @@ class RDBRelation /** * Unrelate from an entity by ID. + * + * @param array $options */ public function unrelateById(string $id, array $options = []): void { @@ -481,6 +485,8 @@ class RDBRelation /** * Update relationship columns by ID. For many-to-many relationships. + * + * @param array $columnData Role values. */ public function updateColumnsById(string $id, array $columnData): void { @@ -504,6 +510,9 @@ class RDBRelation /** * Relate with an entity. + * + * @param array|null $columnData Role values. + * @param array $options */ public function relate(Entity $entity, ?array $columnData = null, array $options = []): void { @@ -522,6 +531,8 @@ class RDBRelation /** * Unrelate from an entity. + * + * @param array $options */ public function unrelate(Entity $entity, array $options = []): void { @@ -534,6 +545,11 @@ class RDBRelation $this->afterUnrelate($entity, $options); } + /** + * Mass-relate. + * + * @param array $options + */ public function massRelate(Select $query, array $options = []): void { if ($this->isBelongsToParentType()) { @@ -553,6 +569,8 @@ class RDBRelation /** * Update relationship columns. For many-to-many relationships. + * + * @param array $columnData Role values. */ public function updateColumns(Entity $entity, array $columnData): void { @@ -593,31 +611,51 @@ class RDBRelation return $this->getMapper()->getRelationColumn($this->entity, $this->relationName, $id, $column); } + /** + * @param array|null $columnData Role values. + * @param array $options + */ private function beforeRelate(Entity $entity, ?array $columnData, array $options): void { $this->hookMediator->beforeRelate($this->entity, $this->relationName, $entity, $columnData, $options); } + /** + * @param array|null $columnData Role values. + * @param array $options + */ private function afterRelate(Entity $entity, ?array $columnData, array $options): void { $this->hookMediator->afterRelate($this->entity, $this->relationName, $entity, $columnData, $options); } + /** + * @param array $options + */ private function beforeUnrelate(Entity $entity, array $options): void { $this->hookMediator->beforeUnrelate($this->entity, $this->relationName, $entity, $options); } + /** + * @param array $options + */ private function afterUnrelate(Entity $entity, array $options): void { $this->hookMediator->afterUnrelate($this->entity, $this->relationName, $entity, $options); } + /** + * @param array $options + */ private function beforeMassRelate(Select $query, array $options): void { $this->hookMediator->beforeMassRelate($this->entity, $this->relationName, $query, $options); } + /** + * @param array $options + */ private function afterMassRelate(Select $query, array $options): void { $this->hookMediator->afterMassRelate($this->entity, $this->relationName, $query, $options); diff --git a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php index bc17e5f357..ca26bbcd7a 100644 --- a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php @@ -51,24 +51,21 @@ use InvalidArgumentException; */ class RDBRelationSelectBuilder { - private $entityManager; + private EntityManager $entityManager; - private $entity; + private Entity $entity; - private $foreignEntityType; + private string $foreignEntityType; - private $relationName; + private string $relationName; - private $relationType = null; + private ?string $relationType = null; - /** - * @var SelectBuilder - */ - private $builder = null; + private SelectBuilder $builder; - private $middleTableAlias = null; + private ?string $middleTableAlias = null; - private $returnSthCollection = false; + private bool $returnSthCollection = false; public function __construct( EntityManager $entityManager, @@ -135,7 +132,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 { @@ -158,6 +155,10 @@ class RDBRelationSelectBuilder return $this; } + /** + * @param array $where + * @return array + */ protected function applyMiddleAliasToWhere(array $where): array { $transformedWhere = []; @@ -200,14 +201,12 @@ class RDBRelationSelectBuilder { $query = $this->builder->build(); - /** @var (iterable&\Espo\ORM\SthCollection)|Entity */ $related = $this->getMapper()->selectRelated($this->entity, $this->relationName, $query); if ($related instanceof Collection) { return $this->handleReturnCollection($related); } - /** @var iterable&\Espo\ORM\EntityCollection $collection */ $collection = $this->entityManager->getCollectionFactory()->create($this->foreignEntityType); $collection->setAsFetched(); @@ -249,7 +248,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 join($target, ?string $alias = null, $conditions = null): self { @@ -264,7 +263,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 { @@ -301,8 +300,8 @@ class RDBRelationSelectBuilder * * `where(array $clause)` * * `where(string $key, string $value)` * - * @param WhereItem|array|string $clause A key or where clause. - * @param array|string|null $value A value. Omitted if the first argument is not string. + * @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 { @@ -331,8 +330,8 @@ class RDBRelationSelectBuilder * * `having(array $clause)` * * `having(string $key, string $value)` * - * @param WhereItem|array|string $clause A key or where clause. - * @param array|string|null $value A value. Omitted if the first argument is not string. + * @param WhereItem|array|string $clause A key or where clause. + * @param mixed[]|string|null $value A value. Should be omitted if the first argument is not string. */ public function having($clause = [], $value = null): self { @@ -415,6 +414,7 @@ class RDBRelationSelectBuilder /** * @deprecated Use `group` method. + * @param Expression|Expression[]|string|string[] $groupBy */ public function groupBy($groupBy): self { @@ -451,6 +451,10 @@ class RDBRelationSelectBuilder return str_replace('@relation.', $alias . '.', $item); } + /** + * @param array $where + * @return array + */ protected function applyRelationAliasToWhereClause(array $where): array { if (!$this->isManyMany()) { @@ -487,6 +491,7 @@ class RDBRelationSelectBuilder } /** + * @param Collection $collection * @phpstan-return Collection */ protected function handleReturnCollection(Collection $collection): Collection diff --git a/application/Espo/ORM/Repository/RDBRepository.php b/application/Espo/ORM/Repository/RDBRepository.php index fe2a1fe088..55ecb27c53 100644 --- a/application/Espo/ORM/Repository/RDBRepository.php +++ b/application/Espo/ORM/Repository/RDBRepository.php @@ -873,7 +873,7 @@ class RDBRepository implements Repository * * `where(string $key, string $value)` * * @param WhereItem|array|string $clause A key or where clause. - * @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string. + * @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string. * * @return RDBSelectBuilder */ @@ -891,7 +891,7 @@ class RDBRepository implements Repository * * `having(string $key, string $value)` * * @param WhereItem|array|string $clause A key or where clause. - * @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string. + * @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string. * * @phpstan-return RDBSelectBuilder */ diff --git a/application/Espo/ORM/Repository/RDBSelectBuilder.php b/application/Espo/ORM/Repository/RDBSelectBuilder.php index e233d631c3..ecff665e49 100644 --- a/application/Espo/ORM/Repository/RDBSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBSelectBuilder.php @@ -282,7 +282,7 @@ class RDBSelectBuilder * * `where(string $key, string $value)` * * @param WhereItem|array|string $clause A key or where clause. - * @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string. + * @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string. * * @phpstan-return RDBSelectBuilder */ @@ -302,7 +302,7 @@ class RDBSelectBuilder * * `having(string $key, string $value)` * * @param WhereItem|array|string $clause A key or where clause. - * @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string. + * @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string. * * @phpstan-return RDBSelectBuilder */