Passed
Push — 9.x ( 55b0ab...1730b8 )
by Andrey
14:27
created

ArrayProcessor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 5 1
A unique() 0 5 1
A filter() 0 5 1
A push() 0 5 1
A toArray() 0 3 1
A sort() 0 5 1
A values() 0 5 1
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