Completed
Push — taxonomy ( 5f7a67...5f1ac5 )
by Arnaud
02:15
created

Term::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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
class Term extends CecilCollection implements ItemInterface
18
{
19
    /**
20
     * Term's name.
21
     *
22
     * @var string
23
     */
24
    protected $name;
25
26
    /**
27
     * Set term's name.
28
     *
29
     * @param string $value
30
     *
31
     * @return self
32
     */
33
    public function setName(string $value): self
34
    {
35
        $this->name = $value;
36
37
        return $this;
38
    }
39
40
    /**
41
     * get term's name.
42
     *
43
     * @return string|null
44
     */
45
    public function getName(): ?string
46
    {
47
        return $this->name;
48
    }
49
50
    /**
51
     * Sort items by date.
52
     *
53
     * @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...
54
     */
55
    public function sortByDate(): self
56
    {
57
        return $this->usort(function ($a, $b) {
58
            if (!isset($a['date'])) {
59
                return -1;
60
            }
61
            if (!isset($b['date'])) {
62
                return 1;
63
            }
64
            if ($a['date'] == $b['date']) {
65
                return 0;
66
            }
67
68
            return ($a['date'] > $b['date']) ? -1 : 1;
69
        });
70
    }
71
}
72