10
10
use MongoDB \BSON \ObjectID ;
11
11
use MongoDB \BSON \Regex ;
12
12
use MongoDB \Collection ;
13
- use MongoDB \Model \ BSONArray ;
13
+ use MongoDB \Driver \ Exception \ RuntimeException as DriverRuntimeException ;
14
14
use MongoDB \Model \BSONDocument ;
15
15
use MongoDB \Model \IndexInfoIteratorIterator ;
16
- use MongoDB \Driver \Exception \RuntimeException as DriverRuntimeException ;
17
16
use MongoDB \Operation \FindOneAndUpdate ;
18
17
use PHPUnit \Framework \Constraint \Constraint ;
19
18
@@ -378,7 +377,7 @@ public function deleteOne($filter, array $options = [])
378
377
$ deletedIds = [];
379
378
foreach ($ this ->documents as $ i => $ doc ) {
380
379
if ($ matcher ($ doc )) {
381
- $ deletedIds []= $ doc ['_id ' ];
380
+ $ deletedIds [] = $ doc ['_id ' ];
382
381
unset($ this ->documents [$ i ]);
383
382
$ this ->documents = array_values ($ this ->documents );
384
383
$ count ++;
@@ -393,7 +392,7 @@ public function distinct($fieldName, $filter = [], array $options = [])
393
392
$ values = [];
394
393
395
394
$ matcher = $ this ->matcherFromQuery ($ filter );
396
- foreach ($ this ->documents as $ document ){
395
+ foreach ($ this ->documents as $ document ) {
397
396
if ($ matcher ($ document ) && isset ($ document [$ fieldName ])) {
398
397
$ values [] = $ document [$ fieldName ];
399
398
}
@@ -678,20 +677,19 @@ function ($acc, $op) use ($val) {
678
677
$ result = !$ operand ;
679
678
}
680
679
break ;
681
- case '$regex ' :{
682
- if ($ operand instanceof \ MongoDB \ BSON \ Regex){
683
- $ regex = "/ " . $ operand ->getPattern () . "/ " . $ operand ->getFlags ();
684
- $ result = preg_match ($ regex ,$ val ) === 1 ;
685
- }else if (is_string ($ operand )){
686
- if (@preg_match ($ operand , '' ) === false ){
680
+ case '$regex ' :
681
+ if ($ operand instanceof Regex) {
682
+ $ regex = "/ " . $ operand ->getPattern () . "/ " . $ operand ->getFlags ();
683
+ $ result = preg_match ($ regex , $ val ) === 1 ;
684
+ } else if (is_string ($ operand )) {
685
+ if (@preg_match ($ operand , '' ) === false ) {
687
686
throw new Exception ("Invalid constraint for operator ' " . $ type . "' " );
688
687
}
689
- $ result = preg_match ($ operand ,$ val ) === 1 ;
690
- }else {
688
+ $ result = preg_match ($ operand , $ val ) === 1 ;
689
+ } else {
691
690
throw new Exception ("Invalid constraint for operator ' " . $ type . "' " );
692
691
}
693
692
break ;
694
- }
695
693
// Custom operators
696
694
case '$instanceOf ' :
697
695
$ result = is_a ($ val , $ operand );
0 commit comments