Completed
Push — collection ( 08980f )
by Arnaud
01:58
created

Term::sortByDate()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4222
c 0
b 0
f 0
cc 5
nc 1
nop 0
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Collection\Taxonomy;
10
11
use Cecil\Collection\Collection as CecilCollection;
12
use Cecil\Collection\ItemInterface;
13
14
/**
15
 * Class Term.
16
 */
17 View Code Duplication
class Term extends CecilCollection implements ItemInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * Sort items by date.
21
     *
22
     * @return self
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
23
     */
24
    public function sortByDate(): self
25
    {
26
        return $this->usort(function ($a, $b) {
27
            if (!isset($a['date'])) {
28
                return -1;
29
            }
30
            if (!isset($b['date'])) {
31
                return 1;
32
            }
33
            if ($a['date'] == $b['date']) {
34
                return 0;
35
            }
36
37
            return ($a['date'] > $b['date']) ? -1 : 1;
38
        });
39
    }
40
}
41