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

BaseEntry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 42
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 6 1
A get() 0 4 1
A toArray() 0 10 3
A create() 0 4 1
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
}