Completed
Push — master ( 44f5df...6e1f64 )
by Ariel
10:50
created

AppointmentPresenter::finishTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 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 10
    public function __construct(Appointment $resource)
11
    {
12 10
        $this->wrappedObject = $resource;
13 10
    }
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 1
    public function time()
39
    {
40 1
        $timeFormat = $this->timeFormat();
41
42 1
        return $this->wrappedObject
43 1
                    ->start_at
44 1
                    ->timezone($this->wrappedObject->business->timezone)
45 1
                    ->format($timeFormat);
46
    }
47
48 2
    public function arriveAt()
49
    {
50 2
        $timeFormat = $this->timeFormat();
51
52 2
        if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) {
53 1
            return ['at' => $this->time];
0 ignored issues
show
Documentation introduced by
The property time does not exist on object<Timegridio\Concie...s\AppointmentPresenter>. 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...
54
        }
55
56 1
        $fromTime = $this->wrappedObject
57 1
                         ->vacancy
58 1
                         ->start_at
59 1
                         ->timezone($this->wrappedObject->business->timezone)
60 1
                         ->format($timeFormat);
61
62 1
        $toTime = $this->wrappedObject
63 1
                       ->vacancy
64 1
                       ->finish_at
65 1
                       ->timezone($this->wrappedObject->business->timezone)
66 1
                       ->format($timeFormat);
67
68 1
        return ['from' => $fromTime, 'to' => $toTime];
69
    }
70
71 1
    public function finishTime()
72
    {
73 1
        $timeFormat = $this->timeFormat();
74
75
        return $this->wrappedObject
76 1
                    ->finish_at
77
                    ->timezone($this->wrappedObject->business->timezone)
78 1
                    ->format($timeFormat);
79
    }
80
81
    public function phone()
82
    {
83
        return $this->wrappedObject->business->phone;
84
    }
85
86
    public function location()
87
    {
88
        return $this->wrappedObject->business->postal_address;
89
    }
90
91 1
    public function statusLetter()
92
    {
93 1
        return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1);
94 1
    }
95 1
96
    public function status()
97 1
    {
98 1
        return trans('appointments.status.'.$this->wrappedObject->statusLabel);
99
    }
100 1
101 1
    public function statusToCssClass()
102
    {
103 1
        switch ($this->wrappedObject->status) {
104 1
            case Appointment::STATUS_ANNULATED:
105 1
                return 'danger';
106
                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...
107
            case Appointment::STATUS_CONFIRMED:
108
                return 'success';
109
                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...
110
            case Appointment::STATUS_RESERVED:
111
                return 'warning';
112
                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...
113
            case Appointment::STATUS_SERVED:
114
            default:
115
                return 'default';
116
        }
117
    }
118
119 2
    public function panel()
120
    {
121 2
        return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render();
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
122
    }
123
124
    public function row()
125
    {
126
        return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render();
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
    }
128
129
    protected function timeFormat()
130
    {
131
        return $this->wrappedObject->business->pref('time_format') ?: 'H:i a';
132
    }
133
}
134