Completed
Push — master ( e0be30...eaeab3 )
by Алексей
05:57
created

BaseEntry::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: akeinhell
5
 * Date: 06.11.2016
6
 * Time: 11:37
7
 */
8
9
namespace Telegram\Base;
10
11
12
use Illuminate\Support\Collection;
13
14
class BaseEntry
15
{
16
    protected $attributes;
17
18
    /**
19
     * BaseEntry constructor.
20
     */
21
    public function __construct()
22
    {
23
        $this->attributes = collect();
24
    }
25
26
    protected function set($key, $value): BaseEntry
27
    {
28
        $this->attributes->put($key, $value);
29
30
        return $this;
31
    }
32
33
    public function get($key, $default = null)
34
    {
35
        return $this->attributes->get($key, $default);
36
    }
37
38
    public function toArray()
39
    {
40
        return $this->attributes
41
            ->mapWithKeys(function ($item, $key) {
42
                return $item instanceof Collection || get_parent_class($item) === BaseEntry::class?
43
                    [$key => $item->toArray()] :
44
                    [$key => $item];
45
            })
46
            ->toArray();
47
    }
48
49
50
    public static function create()
51
    {
52
        return new static();
53
    }
54
55
}