Image   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 147
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 2

12 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 4 1
A path() 0 4 1
A name() 0 4 1
A caption() 0 4 1
A alt() 0 4 1
A thumbnail() 0 4 1
A small() 0 4 1
A medium() 0 4 1
A full() 0 4 1
A imageRoute() 0 4 1
A fileName() 0 4 1
A generateProps() 0 13 1
1
<?php
2
3
namespace Larafolio\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Image extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'images';
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = ['path', 'name', 'caption', 'alt'];
22
23
    /**
24
     * Return the image id.
25
     *
26
     * @return string
27
     */
28
    public function id()
29
    {
30
        return $this->id;
1 ignored issue
show
Documentation introduced by
The property id does not exist on object<Larafolio\Models\Image>. 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...
31
    }
32
33
    /**
34
     * Return the image path.
35
     *
36
     * @return string
37
     */
38
    public function path()
39
    {
40
        return $this->path;
1 ignored issue
show
Documentation introduced by
The property path does not exist on object<Larafolio\Models\Image>. 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...
41
    }
42
43
    /**
44
     * Return the image name.
45
     *
46
     * @return string
47
     */
48
    public function name()
49
    {
50
        return $this->name;
1 ignored issue
show
Documentation introduced by
The property name does not exist on object<Larafolio\Models\Image>. 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...
51
    }
52
53
    /**
54
     * Return the image caption.
55
     *
56
     * @return string
57
     */
58
    public function caption()
59
    {
60
        return $this->caption;
1 ignored issue
show
Documentation introduced by
The property caption does not exist on object<Larafolio\Models\Image>. 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...
61
    }
62
63
    /**
64
     * Return the alt value.
65
     *
66
     * @return string
67
     */
68
    public function alt()
69
    {
70
        return $this->alt;
1 ignored issue
show
Documentation introduced by
The property alt does not exist on object<Larafolio\Models\Image>. 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...
71
    }
72
73
    /**
74
     * Get route for thumbnail version of image.
75
     *
76
     * @return string
77
     */
78
    public function thumbnail()
79
    {
80
        return $this->imageRoute('thumbnail');
81
    }
82
83
    /**
84
     * Get route for small version of image.
85
     *
86
     * @return string
87
     */
88
    public function small()
89
    {
90
        return $this->imageRoute('small');
91
    }
92
93
    /**
94
     * Get route for medium version of image.
95
     *
96
     * @return string
97
     */
98
    public function medium()
99
    {
100
        return $this->imageRoute('medium');
101
    }
102
103
    /**
104
     * Get route for full size version of image.
105
     *
106
     * @return string
107
     */
108
    public function full()
109
    {
110
        return $this->imageRoute('full');
111
    }
112
113
    /**
114
     * Get route for given template image.
115
     *
116
     * @param string $templateName Name of image cache template.
117
     *
118
     * @return string
119
     */
120
    public function imageRoute($templateName)
121
    {
122
        return "/manager/images/{$templateName}/{$this->fileName()}";
123
    }
124
125
    /**
126
     * Get the file name of the image.
127
     *
128
     * @return string
129
     */
130
    public function fileName()
131
    {
132
        return collect(explode('/', $this->path()))->last();
133
    }
134
135
    /**
136
     * Return image properties to be passed to js.
137
     *
138
     * @return array
139
     */
140
    public function generateProps()
141
    {
142
        return [
143
            'thumbnail' => $this->thumbnail(),
144
            'small'     => $this->small(),
145
            'medium'    => $this->medium(),
146
            'full'      => $this->full(),
147
            'name'      => $this->name(),
148
            'caption'   => $this->caption(),
149
            'alt'       => $this->alt(),
150
            'id'        => $this->id(),
151
        ];
152
    }
153
}
154