Completed
Push — master ( ecee01...2fa4c6 )
by Ariel
08:31
created

AppointmentPresenter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.77%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 12
c 5
b 0
f 0
lcom 1
cbo 1
dl 0
loc 125
ccs 30
cts 31
cp 0.9677
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A code() 0 6 1
A date() 0 15 3
B statusToCssClass() 0 17 5
A phone() 0 4 1
A location() 0 4 1
1
<?php
2
3
namespace Timegridio\Concierge\Presenters;
4
5
use McCool\LaravelAutoPresenter\BasePresenter;
6
use Timegridio\Concierge\Models\Appointment;
7
8
class AppointmentPresenter extends BasePresenter
9
{
10 8
    public function __construct(Appointment $resource)
11
    {
12 8
        $this->wrappedObject = $resource;
13 8
    }
14
15 1
    public function code()
16
    {
17 1
        $length = $this->wrappedObject->business->pref('appointment_code_length');
18
19 1
        return strtoupper(substr($this->wrappedObject->hash, 0, $length));
20
    }
21
22 3
    public function date($format = 'Y-m-d')
23
    {
24 3
        if ($this->wrappedObject->start_at->isToday()) {
25 1
            return studly_case(trans('Concierge::appointments.text.today'));
0 ignored issues
show
Bug introduced by
It seems like trans('Concierge::appointments.text.today') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, studly_case() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
26
        }
27
28 2
        if ($this->wrappedObject->start_at->isTomorrow()) {
29 1
            return studly_case(trans('Concierge::appointments.text.tomorrow'));
0 ignored issues
show
Bug introduced by
It seems like trans('Concierge::appointments.text.tomorrow') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, studly_case() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
30
        }
31
32 1
        return $this->wrappedObject
33 1
                    ->start_at
34 1
                    ->timezone($this->wrappedObject->business->timezone)
35 1
                    ->format($format);
36
    }
37
38
//    public function arriveAt()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
//    {
40
//        if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) {
41
//            return $this->time;
42
//        }
43
//
44
//        $fromTime = $this->wrappedObject
45
//                         ->vacancy
46
//                         ->start_at
47
//                         ->timezone($this->wrappedObject->business->timezone)
48
//                         ->format(config('root.time.format'));
49
//
50
//        $toTime = $this->wrappedObject
51
//                       ->vacancy
52
//                       ->finish_at
53
//                       ->timezone($this->wrappedObject->business->timezone)
54
//                       ->format(config('root.time.format'));
55
//
56
//        return ucwords(trans('Concierge::appointments.text.from_to', ['from' => $fromTime, 'to' => $toTime]));
57
//    }
58
59
//    public function time()
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
//    {
61
//        return $this->wrappedObject
62
//                    ->start_at
63
//                    ->timezone($this->wrappedObject->business->timezone)
64
//                    ->format(config('root.time.format'));
65
//    }
66
67
//    public function finishTime()
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
//    {
69
//        return $this->wrappedObject
70
//                    ->finish_at
71
//                    ->timezone($this->wrappedObject->business->timezone)
72
//                    ->format(config('root.time.format'));
73
//    }
74
75
//    public function diffForHumans()
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
//    {
77
//        return $this->wrappedObject->start_at->timezone($this->wrappedObject->business->timezone)->diffForHumans();
78
//    }
79
80 1
    public function phone()
81
    {
82 1
        return $this->wrappedObject->business->phone;
83
    }
84
85 1
    public function location()
86
    {
87 1
        return $this->wrappedObject->business->postal_address;
88
    }
89
90
//    public function statusLetter()
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
//    {
92
//        return substr(trans('Concierge::appointments.status.'.$this->wrappedObject->statusLabel), 0, 1);
93
//    }
94
95
//    public function status()
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
//    {
97
//        return trans('Concierge::appointments.status.'.$this->wrappedObject->statusLabel);
98
//    }
99
100
//    public function statusIcon()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
//    {
102
//        return '<span class="label label-'.$this->statusToCssClass().'">'.$this->statusLetter.'</span>';
103
//    }
104
105 1
    public function statusToCssClass()
106
    {
107 1
        switch ($this->wrappedObject->status) {
108 1
            case Appointment::STATUS_ANNULATED:
109 1
                return 'danger';
110
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
111 1
            case Appointment::STATUS_CONFIRMED:
112 1
                return 'success';
113
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
114 1
            case Appointment::STATUS_RESERVED:
115 1
                return 'warning';
116
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
117 1
            case Appointment::STATUS_SERVED:
118 1
            default:
119 1
                return 'default';
120
        }
121
    }
122
123
//    public function panel()
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
124
//    {
125
//        return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render();
126
//    }
127
128
//    public function row()
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
129
//    {
130
//        return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render();
131
//    }
132
}
133