Completed
Push — master ( 23de65...877ae8 )
by Ariel
11:07
created

AppointmentPresenter::statusToCssClass()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
rs 8.8571
cc 5
eloc 14
nc 5
nop 0
crap 5.0144
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 1
    public function phone()
39
    {
40 1
        return $this->wrappedObject->business->phone;
41
    }
42
43 1
    public function location()
44
    {
45 1
        return $this->wrappedObject->business->postal_address;
46
    }
47
48
    public function statusLetter()
49
    {
50
        return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1);
51
    }
52
53
    public function status()
54
    {
55
        return trans('appointments.status.'.$this->wrappedObject->statusLabel);
56
    }
57
58 1
    public function statusToCssClass()
59
    {
60 1
        switch ($this->wrappedObject->status) {
61 1
            case Appointment::STATUS_ANNULATED:
62 1
                return 'danger';
63
                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...
64 1
            case Appointment::STATUS_CONFIRMED:
65 1
                return 'success';
66
                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...
67 1
            case Appointment::STATUS_RESERVED:
68 1
                return 'warning';
69
                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...
70 1
            case Appointment::STATUS_SERVED:
71 1
            default:
72 1
                return 'default';
73
        }
74
    }
75
76
    public function panel()
77
    {
78
        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...
79
    }
80
81
    public function row()
82
    {
83
        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...
84
    }
85
}
86