Passed
Pull Request — main (#54)
by
unknown
02:35
created

Post::slug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CSlant\Blog\Core\Models;
4
5
use AllowDynamicProperties;
6
use Carbon\Carbon;
7
use CSlant\Blog\Core\Models\Base\BasePost;
8
use CSlant\LaravelLike\HasLike;
9
use FriendsOfBotble\Comment\Models\Comment;
0 ignored issues
show
Bug introduced by
The type FriendsOfBotble\Comment\Models\Comment was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
This use statement conflicts with another class in this namespace, CSlant\Blog\Core\Models\Comment. Consider defining an alias.

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...
10
use Illuminate\Database\Eloquent\Builder;
11
use Illuminate\Database\Eloquent\Relations\HasOne;
12
use Illuminate\Database\Eloquent\Relations\MorphMany;
13
14
/**
15
 * Class Post
16
 *
17
 * @package CSlant\Blog\Core\Models
18
 *
19
 * @property int $id
20
 * @property string $name
21
 * @property string $description
22
 * @property string $content
23
 * @property string $status
24
 * @property int $author_id
25
 * @property string $author_type
26
 * @property int $is_featured
27
 * @property int $views
28
 * @property string $format_type
29
 * @property Carbon $created_at
30
 * @property Carbon $updated_at
31
 * @property Slug $slug
32
 * @property string $url
33
 * @property Tag[] $tags
34
 * @property Category[] $categories
35
 * @property Comment[] $comments
36
 * @property string $image
37
 * @property string $author
38
 *
39
 * @method static Builder|Post newModelQuery()
40
 * @method static Builder|Post newQuery()
41
 * @method static Builder|Post query()
42
 * @method static Builder|Post first()
43
 * @method static Builder|Post find($id)
44
 * @method static Builder|Post with($relations)
45
 * @method static Builder|Post whereId($value)
46
 * @method static Builder|Post whereIn($column, $values)
47
 * @method static Builder|Post where($column, $operator = null, $value = null, $boolean = 'and')
48
 * @method static Post findOrFail($id)
49
 * @method static Post create($data)
50
 *
51
 * @mixin BasePost
52
 */
53
#[AllowDynamicProperties]
54
class Post extends BasePost
55
{
56
    use HasLike;
57
58
    public function slug(): HasOne
59
    {
60
        return $this->hasOne(Slug::class, 'reference_id', 'id')
61
            ->where('reference_type', $this->getBaseModel());
62
    }
63
64
    /**
65
     * Post has many relationship with the Comment.
66
     *
67
     * @return MorphMany
68
     */
69
    public function comments(): MorphMany
70
    {
71
        return $this->morphMany(\CSlant\Blog\Core\Models\Comment::class, 'reference');
72
    }
73
}
74