Code Duplication    Length = 24-24 lines in 2 locations

Classes/Domain/Repository/ContentRepository.php 2 locations

@@ 104-127 (lines=24) @@
101
     * @param Matcher $matcher
102
     * @return Content[]
103
     */
104
    public function findDistinctValues($propertyName, Matcher $matcher = null)
105
    {
106
        $query = $this->createQuery();
107
        $query->setDistinct($propertyName);
108
109
        // Remove empty values from selection.
110
        $constraint = $query->logicalNot($query->equals($propertyName, ''));
111
112
        // Add some additional constraints from the Matcher object.
113
        $matcherConstraint = null;
114
        if (!is_null($matcher)) {
115
            $matcherConstraint = $this->computeConstraints($query, $matcher);
116
        }
117
118
        // Assemble the final constraints or not.
119
        if ($matcherConstraint) {
120
            $query->logicalAnd($matcherConstraint, $constraint);
121
            $query->matching($query->logicalAnd($matcherConstraint, $constraint));
122
        } else {
123
            $query->matching($constraint);
124
        }
125
126
        return $query->execute();
127
    }
128
129
    /**
130
     * Returns all "distinct" values for a given property.
@@ 136-159 (lines=24) @@
133
     * @param Matcher $matcher
134
     * @return int
135
     */
136
    public function countDistinctValues($propertyName, Matcher $matcher = null)
137
    {
138
        $query = $this->createQuery();
139
        $query->setDistinct($propertyName);
140
141
        // Remove empty values from selection.
142
        $constraint = $query->logicalNot($query->equals($propertyName, ''));
143
144
        // Add some additional constraints from the Matcher object.
145
        $matcherConstraint = null;
146
        if (!is_null($matcher)) {
147
            $matcherConstraint = $this->computeConstraints($query, $matcher);
148
        }
149
150
        // Assemble the final constraints or not.
151
        if ($matcherConstraint) {
152
            $query->logicalAnd($matcherConstraint, $constraint);
153
            $query->matching($query->logicalAnd($matcherConstraint, $constraint));
154
        } else {
155
            $query->matching($constraint);
156
        }
157
158
        return $query->count();
159
    }
160
161
    /**
162
     * Finds an object matching the given identifier.