Completed
Pull Request — master (#30)
by Sebastian
03:42
created

Person   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 24
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMediaConversions() 0 9 1
A generateSlug() 0 4 1
1
<?php
2
3
namespace App\Models;
4
5
use App\Foundation\Models\Base\ModuleModel;
6
use App\Foundation\Models\Traits\HasSlug;
7
use Spatie\EloquentSortable\Sortable;
8
use Spatie\EloquentSortable\SortableInterface;
9
10
class Person extends ModuleModel implements SortableInterface
11
{
12
    use Sortable, HasSlug;
13
14
    protected $with = ['media'];
15
16
    public $mediaLibraryCollections = ['images'];
17
    public $translatable = ['text'];
18
19
    public function registerMediaConversions()
20
    {
21
        parent::registerMediaConversions();
22
23
        $this->addMediaConversion('thumb')
24
            ->setWidth(368)
25
            ->setHeight(232)
26
            ->performOnCollections('images');
27
    }
28
29
    protected function generateSlug() : string
30
    {
31
        return str_slug($this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\Models\Person>. 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...
32
    }
33
}
34