Presenter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 69
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A date() 0 4 1
A created() 0 4 1
A updated() 0 4 1
A presentors() 0 13 1
1
<?php
2
3
namespace App\Libraries\Presenterable\Presenters;
4
5
use Illuminate\Database\Eloquent\Model;
6
use ReflectionMethod;
7
8
abstract class Presenter
9
{
10
    /**
11
     * @var Model
12
     */
13
    public $model;
14
15
    /**
16
     * Presenter constructor.
17
     * @param Model $model
18
     */
19
    public function __construct(Model $model)
20
    {
21
        $this->model = $model;
22
    }
23
24
    /**
25
     * Format date.
26
     *
27
     * @param $date
28
     * @param string $format
29
     * @return mixed
30
     */
31
    public function date($date, $format = 'd.m.Y')
32
    {
33
        return $this->model->$date->format($format);
34
    }
35
36
    /**
37
     * Created at.
38
     *
39
     * @param string $format
40
     * @return mixed
41
     */
42
    public function created($format = 'd.m.Y')
43
    {
44
        return $this->date($this->model->created_at, $format);
45
    }
46
47
    /**
48
     * Updated at.
49
     *
50
     * @param string $format
51
     * @return mixed
52
     */
53
    public function updated($format = 'd.m.Y')
54
    {
55
        return $this->date($this->model->updated_at, $format);
56
    }
57
58
    /**
59
     * Get all presenter methods for current presentor instance.
60
     *
61
     * @return array
62
     */
63
    public function presentors()
64
    {
65
        $masks   = [];
66
        $methods = get_class_methods($this);
67
68
        array_walk($methods, function ($method) use (&$masks) {
69
            $r = new ReflectionMethod(get_class($this), $method);
70
71
            $masks[$method] = $r;
72
        });
73
74
        return $masks;
75
    }
76
}