Issues (86)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Presenters/AppointmentPresenter.php (12 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Timegridio\Concierge\Presenters;
4
5
use McCool\LaravelAutoPresenter\BasePresenter;
6
use Timegridio\Concierge\Duration;
7
use Timegridio\Concierge\Models\Appointment;
8
9
class AppointmentPresenter extends BasePresenter
10
{
11
    protected $timezone = null;
12
13 10
    public function __construct(Appointment $resource)
14
    {
15 10
        $this->wrappedObject = $resource;
16
17 10
        $this->setTimezone(session()->get('timezone'));
18 10
    }
19
20 10
    public function setTimezone($timezone = false)
21
    {
22 10
        $this->timezone = $timezone;
23
24 10
        return $this;
25
    }
26
27 1
    public function timezone()
28
    {
29 1
        if ($this->timezone === null) {
30
            $this->timezone = $this->wrappedObject->business->timezone;
31
        }
32
33 1
        return $this->timezone;
34
    }
35
36 1
    public function code()
37
    {
38 1
        $length = $this->wrappedObject->business->pref('appointment_code_length');
39
40 1
        return strtoupper(substr($this->wrappedObject->hash, 0, $length));
41
    }
42
43 1
    public function date($format = 'Y-m-d')
44
    {
45
        // Translated text for friendly date should not be resposibility of this class
46
47
        // if ($this->wrappedObject->start_at->isToday()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
48
        //     return studly_case(trans('Concierge::appointments.text.today'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
49
        // }
50
51
        // if ($this->wrappedObject->start_at->isTomorrow()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
52
        //     return studly_case(trans('Concierge::appointments.text.tomorrow'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
53
        // }
54
55 1
        $dateFormat = $this->dateFormat($format);
56
57 1
        return $this->wrappedObject
58 1
                    ->start_at
59 1
                    ->timezone($this->timezone)
60 1
                    ->format($dateFormat);
61
    }
62
63 1
    public function time()
64
    {
65 1
        $timeFormat = $this->timeFormat();
66
67 1
        return $this->wrappedObject
68 1
                    ->start_at
69 1
                    ->timezone($this->timezone)
70 1
                    ->format($timeFormat);
71
    }
72
73 2
    public function arriveAt()
74
    {
75 2
        $timeFormat = $this->timeFormat();
76
77 2
        if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) {
78 1
            return ['at' => $this->time];
0 ignored issues
show
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...
79
        }
80
81 1
        $fromTime = $this->wrappedObject
82 1
                         ->vacancy
83 1
                         ->start_at
84 1
                         ->timezone($this->timezone)
85 1
                         ->format($timeFormat);
86
87 1
        $toTime = $this->wrappedObject
88 1
                       ->vacancy
89 1
                       ->finish_at
90 1
                       ->timezone($this->timezone)
91 1
                       ->format($timeFormat);
92
93 1
        return ['from' => $fromTime, 'to' => $toTime];
94
    }
95
96
    public function finishTime()
97
    {
98
        $timeFormat = $this->timeFormat();
99
100
        return $this->wrappedObject
101
                    ->finish_at
102
                    ->timezone($this->timezone)
103
                    ->format($timeFormat);
104
    }
105
106 1
    public function duration()
107
    {
108 1
        $duration = new Duration(intval($this->wrappedObject->duration()) * 60000);
109
        $format = [
110 1
            'template'  => '{hours} {minutes} {seconds}',
111
            '{hours}'   => '{hours} hours',
112
            '{minutes}' => '{minutes} minutes',
113
            '{seconds}' => '{seconds} seconds',
114
        ];
115
116 1
        return $duration->format($format);
117
    }
118
119 1
    public function phone()
120
    {
121 1
        return $this->wrappedObject->business->phone;
122
    }
123
124 1
    public function location()
125
    {
126 1
        return $this->wrappedObject->business->postal_address;
127
    }
128
129
    public function statusLetter()
130
    {
131
        return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1);
132
    }
133
134
    public function status()
135
    {
136
        return trans('appointments.status.'.$this->wrappedObject->statusLabel);
137
    }
138
139 1
    public function statusToCssClass()
140
    {
141 1
        switch ($this->wrappedObject->status) {
142
            case Appointment::STATUS_CANCELED:
143 1
                return 'danger';
144
                break;
0 ignored issues
show
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...
145
            case Appointment::STATUS_CONFIRMED:
146 1
                return 'success';
147
                break;
0 ignored issues
show
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...
148
            case Appointment::STATUS_RESERVED:
149 1
                return 'warning';
150
                break;
0 ignored issues
show
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...
151
            case Appointment::STATUS_SERVED:
152
            default:
153 1
                return 'default';
154
        }
155
    }
156
157
    public function panel()
158
    {
159
        return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render();
0 ignored issues
show
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...
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\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...
160
    }
161
162
    public function row()
163
    {
164
        return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render();
0 ignored issues
show
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...
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\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...
165
    }
166
167 2
    protected function timeFormat()
168
    {
169 2
        return $this->wrappedObject->business->pref('time_format') ?: 'h:i a';
170
    }
171
172 1
    protected function dateFormat($defaultFormat = 'Y-m-d')
173
    {
174 1
        return $this->wrappedObject->business->pref('date_format') ?: $defaultFormat;
175
    }
176
}
177