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

IssuePresenter::formattedMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
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;
13
14
use Gitamin\Facades\Setting;
15
use Gitamin\Presenters\Traits\TimestampsTrait;
16
use GrahamCampbell\Markdown\Facades\Markdown;
17
18
class IssuePresenter extends AbstractPresenter
19
{
20
    use TimestampsTrait;
21
22
    /**
23
     * Renders the message from Markdown into HTML.
24
     *
25
     * @return string
26
     */
27
    public function formattedMessage()
28
    {
29
        return Markdown::convertToHtml($this->wrappedObject->description);
30
    }
31
32
    /**
33
     * Formats the created_at time ready to be used by bootstrap-datetimepicker.
34
     *
35
     * @return string
36
     */
37
    public function created_at_datetimepicker()
38
    {
39
        return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
40
    }
41
42
    /**
43
     * Returns a formatted timestamp for use within the timeline.
44
     *
45
     * @return string
46
     */
47
    public function timestamp_formatted()
48
    {
49
        return $this->created_at_formatted;
0 ignored issues
show
Documentation introduced by
The property created_at_formatted does not exist on object<Gitamin\Presenters\IssuePresenter>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
    }
51
52
    /**
53
     * Return the iso timestamp for use within the timeline.
54
     *
55
     * @return string
56
     */
57
    public function timestamp_iso()
58
    {
59
        return $this->created_at_iso;
0 ignored issues
show
Documentation introduced by
The property created_at_iso does not exist on object<Gitamin\Presenters\IssuePresenter>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
    }
61
62
    /**
63
     * Present the status with an icon.
64
     *
65
     * @return string
66
     */
67
    public function icon()
68
    {
69
        switch ($this->wrappedObject->state) {
70
            case 0: // Scheduled
71
                return 'fa fa-calendar';
72
            case 1: // Investigating
73
                return 'fa fa-flag oranges';
74
            case 2: // Identified
75
                return 'fa fa-warning yellows';
76
            case 3: // Watching
77
                return 'fa fa-eye blues';
78
            case 4: // Fixed
79
                return 'fa fa-wrench greens';
80
            default: // Something actually broke, this shouldn't happen.
81
                return '';
82
        }
83
    }
84
85
    /**
86
     * Convert the presenter instance to an array.
87
     *
88
     * @return string[]
89
     */
90
    public function toArray()
91
    {
92
        return array_merge($this->wrappedObject->toArray(), [
93
            'created_at' => $this->created_at(),
94
            'updated_at' => $this->updated_at(),
95
        ]);
96
    }
97
}
98