Code Duplication    Length = 41-41 lines in 2 locations

lib/Doctrine/ODM/MongoDB/Query/Expr.php 2 locations

@@ 682-722 (lines=41) @@
679
     * @param object $document
680
     * @return Expr
681
     */
682
    public function includesReferenceTo($document)
683
    {
684
        $this->requiresCurrentField();
685
        $mapping = $this->getReferenceMapping();
686
        $reference = $this->dm->createReference($document, $mapping);
687
        $storeAs = array_key_exists('storeAs', $mapping) ? $mapping['storeAs'] : null;
688
        $keys = [];
689
690
        switch ($storeAs) {
691
            case ClassMetadataInfo::REFERENCE_STORE_AS_ID:
692
                $this->query[$mapping['name']] = $reference;
693
                return $this;
694
                break;
695
696
            case ClassMetadataInfo::REFERENCE_STORE_AS_REF:
697
                $keys = ['id' => true];
698
                break;
699
700
            case ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF:
701
            case ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF_WITH_DB:
702
                $keys = ['$ref' => true, '$id' => true, '$db' => true];
703
704
                if ($storeAs === ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF) {
705
                    unset($keys['$db']);
706
                }
707
708
                if (isset($mapping['targetDocument'])) {
709
                    unset($keys['$ref'], $keys['$db']);
710
                }
711
                break;
712
713
            default:
714
                throw new \InvalidArgumentException("Reference type {$storeAs} is invalid.");
715
        }
716
717
        foreach ($keys as $key => $value) {
718
            $this->query[$mapping['name']]['$elemMatch'][$key] = $reference[$key];
719
        }
720
721
        return $this;
722
    }
723
724
    /**
725
     * Set the $language option for $text criteria.
@@ 1080-1120 (lines=41) @@
1077
     * @param object $document
1078
     * @return Expr
1079
     */
1080
    public function references($document)
1081
    {
1082
        $this->requiresCurrentField();
1083
        $mapping = $this->getReferenceMapping();
1084
        $reference = $this->dm->createReference($document, $mapping);
1085
        $storeAs = array_key_exists('storeAs', $mapping) ? $mapping['storeAs'] : null;
1086
        $keys = [];
1087
1088
        switch ($storeAs) {
1089
            case ClassMetadataInfo::REFERENCE_STORE_AS_ID:
1090
                $this->query[$mapping['name']] = $reference;
1091
                return $this;
1092
                break;
1093
1094
            case ClassMetadataInfo::REFERENCE_STORE_AS_REF:
1095
                $keys = ['id' => true];
1096
                break;
1097
1098
            case ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF:
1099
            case ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF_WITH_DB:
1100
                $keys = ['$ref' => true, '$id' => true, '$db' => true];
1101
1102
                if ($storeAs === ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF) {
1103
                    unset($keys['$db']);
1104
                }
1105
1106
                if (isset($mapping['targetDocument'])) {
1107
                    unset($keys['$ref'], $keys['$db']);
1108
                }
1109
                break;
1110
1111
            default:
1112
                throw new \InvalidArgumentException("Reference type {$storeAs} is invalid.");
1113
        }
1114
1115
        foreach ($keys as $key => $value) {
1116
            $this->query[$mapping['name'] . '.' . $key] = $reference[$key];
1117
        }
1118
1119
        return $this;
1120
    }
1121
1122
    /**
1123
     * Rename the current field.