Completed
Push — master ( 9dd912...8bf78f )
by Ryan
07:27
created

EntryCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sorted() 0 17 3
A labels() 0 17 2
1
<?php namespace Anomaly\Streams\Platform\Entry;
2
3
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
4
use Anomaly\Streams\Platform\Model\EloquentCollection;
5
use Anomaly\Streams\Platform\Support\Decorator;
6
7
/**
8
 * Class EntryCollection
9
 *
10
 * @link    http://anomaly.is/streams-platform
11
 * @author  AnomalyLabs, Inc. <[email protected]>
12
 * @author  Ryan Thompson <[email protected]>
13
 * @package Anomaly\Streams\Platform\Entry
14
 */
15
class EntryCollection extends EloquentCollection
16
{
17
18
    /**
19
     * Return the sorted entries.
20
     *
21
     * @param bool|false $reverse
0 ignored issues
show
Bug introduced by
There is no parameter named $reverse. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
22
     * @return static
23
     */
24
    public function sorted($direction = 'asc')
25
    {
26
        $items = [];
27
28
        /* @var EntryInterface $item */
29
        foreach ($this->items as $item) {
30
            $items[$item->getSortOrder()] = $item;
31
        }
32
33
        ksort($items);
34
35
        if (strtolower($direction) == 'desc') {
36
            $items = array_reverse($items);
37
        }
38
39
        return self::make($items);
40
    }
41
42
    /**
43
     * Return labels for each entry.
44
     *
45
     * @param null   $text
46
     * @param string $context
47
     * @param string $size
48
     * @return array
49
     */
50
    public function labels($text = null, $context = null, $size = null)
51
    {
52
        $decorator = new Decorator();
53
54
        return array_map(
55
            function ($entry) use ($decorator, $text, $context, $size) {
56
57
                /* @var EntryPresenter $entry */
58
                if (!$entry instanceof EntryPresenter) {
59
                    $entry = $decorator->decorate($entry);
60
                }
61
62
                return $entry->label($text, $context, $size);
63
            },
64
            $this->all()
65
        );
66
    }
67
}
68