Fragment   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescriptionForEvent() 0 6 1
A getNameAttribute() 0 4 1
A registerMediaConversions() 0 12 1
1
<?php
2
3
namespace App\Models;
4
5
use Spatie\Blender\Model\Traits\HasMedia;
6
use Spatie\TranslationLoader\LanguageLine;
7
use App\Models\Presenters\FragmentPresenter;
8
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions;
9
10
class Fragment extends LanguageLine implements HasMediaConversions
11
{
12
    use FragmentPresenter, HasMedia;
13
14
    protected static $logAttributes = ['name', 'text'];
15
16
    protected static $recordEvents = ['updated'];
17
18
    protected $mediaLibraryCollections = ['images'];
19
20
    public $casts = [
21
        'contains_html' => 'boolean',
22
        'hidden' => 'boolean',
23
        'text' => 'array',
24
    ];
25
26
    public $table = 'fragments';
27
28
    public function getDescriptionForEvent(string $eventName): string
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $link = link_to_action('Back\\FragmentController@edit', $this->full_name, [$this->id]);
0 ignored issues
show
Documentation introduced by
The property full_name does not exist on object<App\Models\Fragment>. 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 id does not exist on object<App\Models\Fragment>. 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
        return "Fragment '{$link}' werd bijgewerkt";
33
    }
34
35
    public function getNameAttribute(): string
36
    {
37
        return "{$this->group}.{$this->key}";
0 ignored issues
show
Documentation introduced by
The property group does not exist on object<App\Models\Fragment>. 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 key does not exist on object<App\Models\Fragment>. 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...
38
    }
39
40
    public function registerMediaConversions()
41
    {
42
        $this->addMediaConversion('admin')
43
            ->setWidth(368)
44
            ->setHeight(232)
45
            ->nonQueued();
46
47
        $this->addMediaConversion('thumb')
48
            ->setWidth(368)
49
            ->setHeight(232)
50
            ->performOnCollections('images');
51
    }
52
}
53