Issues (20)

src/Model/PageSetting.php (5 issues)

1
<?php
2
3
namespace Thinkone\NovaPageSettings\Model;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Factories\Factory;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Model;
9
use Thinkone\NovaPageSettings\Factories\PageSettingFactory;
10
11
class PageSetting extends Model
12
{
13
    use HasFactory;
14
15
    protected $guarded = [];
16
17 4
    public function getTable(): string
18
    {
19 4
        return config('nova-page-settings.default.settings_table');
20
    }
21
22 1
    protected static function newFactory(): Factory
23
    {
24 1
        return PageSettingFactory::new();
25
    }
26
27 3
    public function newCollection(array $models = []): PageSettingsCollection
28
    {
29 3
        return new PageSettingsCollection($models);
0 ignored issues
show
$models of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $items of Thinkone\NovaPageSetting...llection::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        return new PageSettingsCollection(/** @scrutinizer ignore-type */ $models);
Loading history...
30
    }
31
32 3
    public function scopePage(Builder $query, string $slug)
33
    {
34 3
        return $query->where('page', '=', $slug);
35
    }
36
37 2
    public function scopeKey(Builder $query, string $key)
38
    {
39 2
        return $query->where('key', '=', $key);
40
    }
41
42 1
    public function valueArray(): array
43
    {
44 1
        if(is_array($this->value)) {
0 ignored issues
show
The property value does not seem to exist on Thinkone\NovaPageSettings\Model\PageSetting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
45 1
            return $this->value;
46
        }
47
48 1
        $data = json_decode($this->value, true);
49
50 1
        return is_array($data) ? $data : [];
51
    }
52
53 1
    public function valueBool(): bool
54
    {
55 1
        return (bool) ($this->value);
0 ignored issues
show
The property value does not seem to exist on Thinkone\NovaPageSettings\Model\PageSetting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
    }
57
58 1
    public function valueString(): string
59
    {
60
        try {
61 1
            return (string) ($this->value);
0 ignored issues
show
The property value does not seem to exist on Thinkone\NovaPageSettings\Model\PageSetting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
62 1
        } catch (\Exception $e) {
0 ignored issues
show
catch (\Exception $e) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63 1
            return '';
64
        }
65
    }
66
}
67