88use FQL \Conditions \SimpleCondition ;
99use FQL \Enum ;
1010use FQL \Exception ;
11- use FQL \Interface \ Query ;
11+ use FQL \Interface ;
1212
13+ /**
14+ * @phpstan-import-type ConditionValue from Interface\Query
15+ */
1316trait Conditions
1417{
1518 private BaseConditionGroup $ whereConditions ;
1619 private BaseConditionGroup $ havingConditions ;
1720 private GroupCondition $ currentGroup ;
1821
19- private function initialize (): Query
22+ private function initialize (): Interface \ Query
2023 {
21- // Výchozí skupiny pro WHERE a HAVING
24+ // Default groups for WHERE and HAVING
2225 $ this ->whereConditions = new BaseConditionGroup (Condition::WHERE );
2326 $ this ->havingConditions = new BaseConditionGroup (Condition::HAVING );
2427
25- // Nastavení výchozí aktuální skupiny na WHERE
28+ // Setting the default current group to WHERE
2629 $ this ->currentGroup = $ this ->whereConditions ;
2730 return $ this ;
2831 }
2932
3033 /**
3134 * Switch context to WHERE and optionally add condition
35+ * @param ConditionValue $value
3236 */
33- public function where (string $ key , Enum \Operator $ operator , null |array |float |int |string $ value ): Query
34- {
37+ public function where (
38+ string $ key ,
39+ Enum \Operator $ operator ,
40+ null |array |float |int |string |Enum \Type $ value
41+ ): Interface \Query {
3542 $ this ->addCondition (Enum \LogicalOperator::AND , $ key , $ operator , $ value );
3643 return $ this ;
3744 }
3845
3946 /**
4047 * Switch context to HAVING and optionally add condition
48+ * @param ConditionValue $value
4149 */
42- public function having (string $ key , Enum \Operator $ operator , null |array |float |int |string $ value ): Query
43- {
50+ public function having (
51+ string $ key ,
52+ Enum \Operator $ operator ,
53+ null |array |float |int |string |Enum \Type $ value
54+ ): Interface \Query {
4455 $ this ->currentGroup = $ this ->havingConditions ;
4556 $ this ->addCondition (Enum \LogicalOperator::AND , $ key , $ operator , $ value );
4657 return $ this ;
4758 }
4859
4960 /**
5061 * Add AND condition to current context
62+ * @param ConditionValue $value
5163 */
52- public function and (string $ key , Enum \Operator $ operator , mixed $ value ): Query
53- {
64+ public function and (
65+ string $ key ,
66+ Enum \Operator $ operator ,
67+ null |array |float |int |string |Enum \Type $ value
68+ ): Interface \Query {
5469 $ this ->addCondition (Enum \LogicalOperator::AND , $ key , $ operator , $ value );
5570 return $ this ;
5671 }
5772
5873 /**
5974 * Add OR condition to current context
75+ * @param ConditionValue $value
6076 */
61- public function or (string $ key , Enum \Operator $ operator , mixed $ value ): Query
62- {
77+ public function or (
78+ string $ key ,
79+ Enum \Operator $ operator ,
80+ null |array |float |int |string |Enum \Type $ value
81+ ): Interface \Query {
6382 $ this ->addCondition (Enum \LogicalOperator::OR , $ key , $ operator , $ value );
6483 return $ this ;
6584 }
6685
6786 /**
6887 * Add XOR condition to current context
88+ * @param ConditionValue $value
6989 */
70- public function xor (string $ key , Enum \Operator $ operator , mixed $ value ): Query
71- {
90+ public function xor (
91+ string $ key ,
92+ Enum \Operator $ operator ,
93+ null |array |float |int |string |Enum \Type $ value
94+ ): Interface \Query {
7295 $ this ->addCondition (Enum \LogicalOperator::XOR , $ key , $ operator , $ value );
7396 return $ this ;
7497 }
7598
76- public function whereGroup (): Query
99+ public function whereGroup (): Interface \ Query
77100 {
78101 return $ this ->andGroup ();
79102 }
80103
81- public function havingGroup (): Query
104+ public function havingGroup (): Interface \ Query
82105 {
83106 $ this ->currentGroup = $ this ->havingConditions ;
84107 return $ this ->andGroup ();
85108 }
86109
87- public function orGroup (): Query
110+ public function orGroup (): Interface \ Query
88111 {
89112 return $ this ->beginGroup (Enum \LogicalOperator::OR );
90113 }
91114
92- public function andGroup (): Query
115+ public function andGroup (): Interface \ Query
93116 {
94117 return $ this ->beginGroup (Enum \LogicalOperator::AND );
95118 }
@@ -108,7 +131,7 @@ public function beginGroup(Enum\LogicalOperator $logicalOperator): self
108131 /**
109132 * Ends the current group of conditions in the current context.
110133 */
111- public function endGroup (): Query
134+ public function endGroup (): Interface \ Query
112135 {
113136 if ($ this ->currentGroup instanceof BaseConditionGroup) {
114137 throw new Exception \UnexpectedValueException ('No group to end ' );
@@ -120,9 +143,14 @@ public function endGroup(): Query
120143
121144 /**
122145 * Add condition to the actual group context
146+ * @param ConditionValue $value
123147 */
124- private function addCondition (Enum \LogicalOperator $ type , string $ key , Enum \Operator $ operator , mixed $ value ): void
125- {
148+ private function addCondition (
149+ Enum \LogicalOperator $ type ,
150+ string $ key ,
151+ Enum \Operator $ operator ,
152+ null |array |float |int |string |Enum \Type $ value
153+ ): void {
126154 $ this ->currentGroup ->addCondition ($ type , new SimpleCondition ($ type , $ key , $ operator , $ value ));
127155 }
128156
0 commit comments