Code Duplication    Length = 40-40 lines in 2 locations

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

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