Completed
Pull Request — master (#56)
by Sebastian
06:12
created

ModuleModel::defaultSeoValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Foundation\Models\Base;
4
5
use App\Foundation\Models\Traits\Draftable;
6
use App\Foundation\Models\Traits\Presentable;
7
use App\Foundation\Models\Traits\HasMedia as HasMediaTrait;
8
use App\HasMeta\HasSeoValues;
9
use Illuminate\Database\Eloquent\Model;
10
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions;
11
use Spatie\ModelCleanup\GetsCleanedUp;
12
use Illuminate\Database\Eloquent\Builder;
13
use Carbon\Carbon;
14
use Spatie\Translatable\HasTranslations;
15
16
abstract class ModuleModel extends Model implements HasMediaConversions, GetsCleanedUp
17
{
18
    use Draftable, Presentable, HasMediaTrait, HasSeoValues, HasTranslations;
19
20
    protected $guarded = ['id'];
21
22
    public function registerMediaConversions()
23
    {
24
        $this->addMediaConversion('admin')
25
            ->setWidth(368)
26
            ->setHeight(232)
27
            ->nonQueued();
28
29
        $this->addMediaConversion('redactor')
30
            ->setWidth(368)
31
            ->setHeight(232)
32
            ->nonQueued();
33
    }
34
35
    public static function cleanUp(Builder $query): Builder
36
    {
37
        return $query
38
            ->draft()
39
            ->where('created_at', '<', Carbon::now()->subWeek());
40
    }
41
42
    public function defaultSeoValues(): array
43
    {
44
        return [
45
            'title' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\Foundation\Models\Base\ModuleModel>. 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...
46
            'meta_title' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\Foundation\Models\Base\ModuleModel>. 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...
47
            'meta_description' => (string) string($this->text)->tease(155),
0 ignored issues
show
Documentation introduced by
The property text does not exist on object<App\Foundation\Models\Base\ModuleModel>. 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...
48
            'meta_og:title' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<App\Foundation\Models\Base\ModuleModel>. 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...
49
            'meta_og:type' => 'website',
50
            'meta_og:description' => (string) string($this->text)->tease(155),
0 ignored issues
show
Documentation introduced by
The property text does not exist on object<App\Foundation\Models\Base\ModuleModel>. 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
            'meta_og:image' => $this->hasMedia('images') ?
52
                url($this->getFirstMediaUrl('images')) :
53
                url('/images/og-image.png'),
54
        ];
55
    }
56
}
57