Endpoint::isBackUp()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Infinitypaul\LaravelUptime;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Config;
7
8
class Endpoint extends Model
9
{
10
    protected $table;
11
12
    protected $fillable = ['uri', 'frequency'];
13
14
    public function __construct(array $attributes = [])
15
    {
16
        parent::__construct($attributes);
17
18
        $this->table = Config::get('uptime.endpoints_table');
19
    }
20
21
    public function statuses()
22
    {
23
        return $this->hasMany(Status::class)->orderBy('created_at', 'desc');
24
    }
25
26
    public function status()
27
    {
28
        return $this->hasOne(Status::class)->orderBy('created_at', 'desc');
29
    }
30
31
    public function isBackUp()
32
    {
33
        return $this->status->isUp() && ($this->statuses->get(1) && $this->statuses->get(1)->isDown());
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<Infinitypaul\LaravelUptime\Endpoint>. 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...
Documentation introduced by
The property statuses does not exist on object<Infinitypaul\LaravelUptime\Endpoint>. 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...
34
    }
35
}
36