| 1 | <?php |
| 2 | |
| 3 | namespace Wikimedia\Rdbms; |
| 4 | |
| 5 | /** |
| 6 | * Representing a group of expressions chained via AND |
| 7 | * |
| 8 | * @since 1.42 |
| 9 | */ |
| 10 | class AndExpressionGroup extends ExpressionGroup { |
| 11 | protected function getType(): string { |
| 12 | return 'AND'; |
| 13 | } |
| 14 | |
| 15 | // While these methods are not actually "side-effect-free" (they mutate the object), |
| 16 | // we annotate them with @phan-side-effect-free for consistency with Expression. |
| 17 | |
| 18 | /** |
| 19 | * @param string $field |
| 20 | * @param-taint $field exec_sql |
| 21 | * @param string $op One of '>', '<', '!=', '=', '>=', '<=', IExpression::LIKE, IExpression::NOT_LIKE |
| 22 | * @phan-param '\x3E'|'\x3C'|'!='|'='|'\x3E='|'\x3C='|'LIKE'|'NOT LIKE' $op |
| 23 | * @param-taint $op exec_sql |
| 24 | * @param ?scalar|RawSQLValue|Blob|LikeValue|non-empty-list<scalar|Blob> $value |
| 25 | * @param-taint $value escapes_sql |
| 26 | * @phan-side-effect-free |
| 27 | */ |
| 28 | public function and( string $field, string $op, $value ): AndExpressionGroup { |
| 29 | $expr = new Expression( $field, $op, $value ); |
| 30 | $this->add( $expr ); |
| 31 | return $this; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @param IExpression $expr |
| 36 | * @return AndExpressionGroup |
| 37 | * @phan-side-effect-free |
| 38 | */ |
| 39 | public function andExpr( IExpression $expr ): AndExpressionGroup { |
| 40 | $this->add( $expr ); |
| 41 | return $this; |
| 42 | } |
| 43 | } |