Completed
Pull Request — master (#2)
by ARCANEDEV
11:13
created

Seo::seoable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelSeo\Models;
2
3
use Arcanedev\LaravelSeo\Bases\Model;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Arcanedev\LaravelSeo\Models\Model.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
/**
6
 * Class     Seo
7
 *
8
 * @package  Arcanedev\LaravelSeo\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  int                                  id
12
 * @property  int                                  seoable_id
13
 * @property  string                               seoable_type
14
 * @property  string                               title
15
 * @property  string                               description
16
 * @property  string                               keywords
17
 * @property  \Illuminate\Support\Collection       metas
18
 * @property  boolean                              noindex
19
 * @property  \Carbon\Carbon                       created_at
20
 * @property  \Carbon\Carbon                       updated_at
21
 *
22
 * @property  \Illuminate\Database\Eloquent\Model  seoable
23
 */
24
class Seo extends Model
25
{
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Properties
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    /**
31
     * The table associated with the model.
32
     *
33
     * @var string
34
     */
35
    protected $table = 'seo';
36
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = ['title', 'description', 'keywords', 'metas', 'noindex'];
43
44
    /**
45
     * The attributes that should be casted to native types.
46
     *
47
     * @var array
48
     */
49
    protected $casts = [
50
        'id'         => 'integer',
51
        'seoable_id' => 'integer',
52
        'metas'      => 'collection',
53
        'noindex'    => 'boolean',
54
    ];
55
56
    /* ------------------------------------------------------------------------------------------------
57
     |  Constructor
58
     | ------------------------------------------------------------------------------------------------
59
     */
60
    /**
61
     * Create a new Eloquent model instance.
62
     *
63
     * @param  array  $attributes
64
     */
65
    public function __construct(array $attributes = [])
66
    {
67
        $this->setTable(config('laravel-seo.database.table', 'seo'));
68
69
        parent::__construct($attributes);
70
    }
71
72
    /* ------------------------------------------------------------------------------------------------
73
     |  Relationships
74
     | ------------------------------------------------------------------------------------------------
75
     */
76
    /**
77
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
78
     */
79
    public function seoable()
80
    {
81
        return $this->morphTo();
82
    }
83
}
84