Completed
Push — master ( 44b229...b8c9f6 )
by Stéphane
01:02
created

Collection::collect()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 1
1
<?php
2
3
namespace StephaneCoinon\SendGridActivity\Support;
4
5
use StephaneCoinon\SendGridActivity\Integrations\Framework;
6
7
/**
8
 * Cast an array into the framework native collection (or array for vanilla PHP).
9
 */
10
class Collection
11
{
12
    /**
13
     * Collection items.
14
     *
15
     * @var array|\Illuminate\Support\Collection
16
     */
17
    protected $items = [];
18
19
    /**
20
     * Get a new Collection instance.
21
     *
22
     * @param array $items
23
     */
24
    public function __construct(array $items)
25
    {
26
        $this->items = static::collect($items);
27
    }
28
29
    /**
30
     * Cast an array into the framework native collection.
31
     *
32
     * @param array $items
33
     * @return array|\Illuminate\Support\Collection
34
     */
35
    public static function collect(array $items)
36
    {
37
        return Framework::isLaravel() ? collect($items) : $items;
38
    }
39
40
    /**
41
     * Get a new Collection instance.
42
     *
43
     * @param array $items
44
     * @return self
45
     */
46
    public static function make(array $items): self
47
    {
48
        return new static($items);
49
    }
50
51
    /**
52
     * Undocumented function
53
     *
54
     * @param  array $items
0 ignored issues
show
Bug introduced by
There is no parameter named $items. 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...
55
     * @return array|\Illuminate\Support\Collection
56
     */
57
    public function mapInto(string $model)
58
    {
59
        if (Framework::isLaravel()) {
60
            return $this->items->mapInto($model);
61
        }
62
63
        return array_map(function ($item) use ($model) {
64
            return new $model($item);
65
        }, $this->items);
66
    }
67
}
68