Completed
Push — master ( 1ef690...5e5bda )
by Phecho
03:54
created

TimestampsTrait::created_at_formatted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Presenters\Traits;
13
14
use Jenssegers\Date\Date;
15
16
trait TimestampsTrait
17
{
18
    /**
19
     * Present formatted date time.
20
     *
21
     * @return string
22
     */
23
    public function created_at()
24
    {
25
        return (new Date($this->wrappedObject->created_at))
0 ignored issues
show
Bug introduced by
The property wrappedObject does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
            ->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
0 ignored issues
show
Bug introduced by
The property setting does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
    }
28
29
    /**
30
     * Present diff for humans date time.
31
     *
32
     * @return string
33
     */
34
    public function created_at_diff()
35
    {
36
        return (new Date($this->wrappedObject->created_at))
37
            ->setTimezone($this->setting->get('app_timezone'))
38
            ->diffForHumans();
39
    }
40
41
    /**
42
     * Present formatted date time.
43
     *
44
     * @return string
45
     */
46
    public function created_at_formatted()
47
    {
48
        return ucfirst((new Date($this->wrappedObject->created_at))
49
            ->setTimezone($this->setting->get('app_timezone'))
50
            ->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s')));
51
    }
52
53
    /**
54
     * Present formatted date time.
55
     *
56
     * @return string
57
     */
58
    public function created_at_iso()
59
    {
60
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String();
61
    }
62
63
    /**
64
     * Present formatted date time.
65
     *
66
     * @return string
67
     */
68
    public function updated_at()
69
    {
70
        return (new Date($this->wrappedObject->updated_at))
71
            ->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
72
    }
73
74
    /**
75
     * Present formatted date time.
76
     *
77
     * @return string
78
     */
79
    public function deleted_at()
80
    {
81
        return (new Date($this->wrappedObject->deleted_at))
82
            ->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
83
    }
84
85
    /**
86
     * Present formatted date time.
87
     *
88
     * @return string
89
     */
90
    public function verified_at()
91
    {
92
        return (new Date($this->wrappedObject->verified_at))
93
            ->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
94
    }
95
}
96