Code Duplication    Length = 23-23 lines in 2 locations

app/Repository/Project/Fetcher.php 1 location

@@ 240-262 (lines=23) @@
237
     *
238
     * @return Eloquent\Collection
239
     */
240
    protected function sortByTag(HasMany $query, $tagGroup, $order = 'asc')
241
    {
242
        // If tag group is string prefixed with tag:
243
        if (!is_numeric($tagGroup)) {
244
            $tagGroup = substr($tagGroup, strlen('tag:'));
245
        }
246
247
        $results = $query->get()
248
            ->sort(function (Project\Issue $issue1, Project\Issue $issue2) use ($tagGroup, $order) {
249
                $tag1 = $issue1->tags->where('parent.id', $tagGroup)->first();
250
                $tag2 = $issue2->tags->where('parent.id', $tagGroup)->first();
251
                $tag1 = $tag1 ? $tag1->name : '';
252
                $tag2 = $tag2 ? $tag2->name : '';
253
254
                if ($order === 'asc') {
255
                    return strcmp($tag1, $tag2);
256
                }
257
258
                return strcmp($tag2, $tag1);
259
            });
260
261
        return $results;
262
    }
263
264
    /**
265
     * Returns projects with open issue count.

app/Repository/Traits/Project/SortTrait.php 1 location

@@ 50-72 (lines=23) @@
47
     *
48
     * @return Eloquent\Collection
49
     */
50
    public function sortByTag(HasMany $query, $tagGroup, $order = 'asc')
51
    {
52
        // If tag group is string prefixed with tag:
53
        if (!is_numeric($tagGroup)) {
54
            $tagGroup = substr($tagGroup, strlen('tag:'));
55
        }
56
57
        $results = $query->get()
58
            ->sort(function (Project\Issue $issue1, Project\Issue $issue2) use ($tagGroup, $order) {
59
                $tag1 = $issue1->tags->where('parent.id', $tagGroup)->first();
60
                $tag2 = $issue2->tags->where('parent.id', $tagGroup)->first();
61
                $tag1 = $tag1 ? $tag1->name : '';
62
                $tag2 = $tag2 ? $tag2->name : '';
63
64
                if ($order === 'asc') {
65
                    return strcmp($tag1, $tag2);
66
                }
67
68
                return strcmp($tag2, $tag1);
69
            });
70
71
        return $results;
72
    }
73
}
74