Passed
Pull Request — main (#96)
by Andrey
50:33 queued 35:34
created

ArrayProcessor::push()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\Support\Facades\Helpers\Arr as ArrHelper;
6
use Illuminate\Contracts\Support\Arrayable;
7
8
class ArrayProcessor implements Arrayable
9
{
10
    protected $items = [];
11
12
    public function of(array $items): self
13
    {
14
        $this->items = $items;
15
16
        return $this;
17
    }
18
19
    public function push($value): self
20
    {
21
        array_push($this->items, $value);
22
23
        return $this;
24
    }
25
26
    public function unique(): self
27
    {
28
        $this->items = array_unique($this->items);
29
30
        return $this;
31
    }
32
33
    public function values(): self
34
    {
35
        $this->items = array_values($this->items);
36
37
        return $this;
38
    }
39
40
    public function sort(): self
41
    {
42
        $this->items = ArrHelper::sort($this->items);
43
44
        return $this;
45
    }
46
47
    public function filter(callable $callback): self
48
    {
49
        $this->items = array_filter($this->items, $callback);
50
51
        return $this;
52
    }
53
54
    public function toArray(): array
55
    {
56
        return $this->items;
57
    }
58
}
59