BaseEntry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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 2
    public function __construct()
22
    {
23 2
        $this->attributes = collect();
24 2
    }
25
26 2
    protected function set($key, $value)
27
    {
28 2
        $this->attributes->put($key, $value);
29
30 2
        return $this;
31
    }
32
33 2
    public function get($key, $default = null)
34
    {
35 2
        return $this->attributes->get($key, $default);
36
    }
37
38 2
    public function toArray()
39
    {
40 2
        return $this->attributes
41 2
            ->mapWithKeys(function ($item, $key) {
42 2
                return $item instanceof Collection || get_parent_class($item) === BaseEntry::class?
43 2
                    [$key => $item->toArray()] :
44 2
                    [$key => $item];
45 2
            })
46 2
            ->toArray();
47
    }
48
49
50 2
    public static function create()
51
    {
52 2
        return new static();
53
    }
54
55
}