@@ -497,7 +497,7 @@ protected function joinExpression($expression, $joinOperation)
497497 *
498498 * @return string
499499 */
500- public function getQuery ()
500+ public function getQuery (): string
501501 {
502502 return $ this ->query ;
503503 }
@@ -511,7 +511,7 @@ public function getQuery()
511511 *
512512 * @return static $this
513513 */
514- public function addAnyExpression ($ expression )
514+ public function addAnyExpression (string $ expression ): self
515515 {
516516 $ this ->query .= " $ expression " ;
517517
@@ -537,7 +537,7 @@ public function addAnyExpression($expression)
537537 *
538538 * @return JqlQuery
539539 */
540- public function addExpression ($ field , $ operator , $ value , $ logicLinkKeyword = self ::KEYWORD_AND )
540+ public function addExpression (string $ field , string $ operator , string $ value , string $ logicLinkKeyword = self ::KEYWORD_AND ) : self
541541 {
542542 $ this ->joinExpression (
543543 self ::quoteField ($ field )." $ operator " .self ::quote ($ value ),
@@ -548,55 +548,73 @@ public function addExpression($field, $operator, $value, $logicLinkKeyword = sel
548548 }
549549
550550 /**
551- * Adds 'in' expression with any field to query.
551+ * Adds 'in' or 'not in' expression with any field to query.
552552 *
553553 * Example: $query->addInExpression({@see JqlQuery::FIELD_ASSIGNEE}, ['user1', 'user2'])
554554 *
555555 * @param string $field field name
556556 * @param string[] $values field values array
557557 * @param string $logicLinkKeyword use {@see JqlQuery::KEYWORD_AND} or {@see JqlQuery::KEYWORD_OR}
558558 * to set join logical operation. Default {@see JqlQuery::KEYWORD_AND}.
559+ * @param bool $needQuote if set to false, don't add quote to values param
559560 *
561+ * @param bool $notIn
560562 * @return JqlQuery
561563 */
562- public function addInExpression ( $ field , $ values , $ logicLinkKeyword = self ::KEYWORD_AND )
564+ private function _addExpression ( string $ field , array $ values , string $ logicLinkKeyword = self ::KEYWORD_AND , bool $ needQuote = true , bool $ notIn = true ): self
563565 {
564566 $ valuesQuoted = [];
565567 foreach ($ values as $ value ) {
566- $ valuesQuoted [] = self ::quote ($ value );
568+ if ($ needQuote ) {
569+ $ valuesQuoted [] = self ::quote ($ value );
570+ } else {
571+ $ valuesQuoted [] = $ value ;
572+ }
567573 }
574+ $ conStr = $ notIn == true ? ' not in ' : ' in ' ;
575+
568576 $ this ->joinExpression (
569- self ::quoteField ($ field ).' in ( ' .implode (', ' , $ valuesQuoted ).') ' ,
577+ sprintf ( self ::quoteField ($ field ).' %s ( ' .implode (', ' , $ valuesQuoted ).') ' , $ conStr ) ,
570578 $ logicLinkKeyword
571579 );
572580
573581 return $ this ;
574582 }
575583
576584 /**
577- * Adds 'not in' expression with any field to query.
585+ * Adds 'in' expression with any field to query.
578586 *
579- * Example: $query->addNotInExpression ({@see JqlQuery::FIELD_ASSIGNEE}, ['user1', 'user2'])
587+ * Example: $query->addInExpression ({@see JqlQuery::FIELD_ASSIGNEE}, ['user1', 'user2'])
580588 *
581589 * @param string $field field name
582590 * @param string[] $values field values array
583591 * @param string $logicLinkKeyword use {@see JqlQuery::KEYWORD_AND} or {@see JqlQuery::KEYWORD_OR}
584592 * to set join logical operation. Default {@see JqlQuery::KEYWORD_AND}.
593+ * @param bool $needQuote if set to false, don't add quote to values param
585594 *
586595 * @return JqlQuery
587596 */
588- public function addNotInExpression ( $ field , $ values , $ logicLinkKeyword = self ::KEYWORD_AND )
597+ public function addInExpression ( string $ field , array $ values , string $ logicLinkKeyword = self ::KEYWORD_AND , bool $ needQuote = true ): self
589598 {
590- $ valuesQuoted = [];
591- foreach ($ values as $ value ) {
592- $ valuesQuoted [] = self ::quote ($ value );
593- }
594- $ this ->joinExpression (
595- self ::quoteField ($ field ).' not in ( ' .implode (', ' , $ valuesQuoted ).') ' ,
596- $ logicLinkKeyword
597- );
599+ return $ this ->_addExpression ($ field , $ values , $ logicLinkKeyword , $ needQuote , false );
600+ }
598601
599- return $ this ;
602+ /**
603+ * Adds 'not in' expression with any field to query.
604+ *
605+ * Example: $query->addNotInExpression({@see JqlQuery::FIELD_ASSIGNEE}, ['user1', 'user2'])
606+ *
607+ * @param string $field field name
608+ * @param string[] $values field values array
609+ * @param string $logicLinkKeyword use {@see JqlQuery::KEYWORD_AND} or {@see JqlQuery::KEYWORD_OR}
610+ * to set join logical operation. Default {@see JqlQuery::KEYWORD_AND}.
611+ * @param bool $needQuote if set to false, don't add quote to values param
612+ *
613+ * @return JqlQuery
614+ */
615+ public function addNotInExpression (string $ field , array $ values , string $ logicLinkKeyword = self ::KEYWORD_AND , bool $ needQuote = true )
616+ {
617+ return $ this ->_addExpression ($ field , $ values , $ logicLinkKeyword , $ needQuote , true );
600618 }
601619
602620 /**
0 commit comments