Completed
Push — master ( eaba5d...273ac0 )
by Marc
03:48 queued 01:30
created

RobotsRow::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Robots\Models;
4
5
use Robots\Robots;
6
use Illuminate\Database\Eloquent\Model;
7
8
class RobotsRow extends Model
9
{
10
    protected $fillable = ['action', 'type'];
11
12
    protected $guarded = ['id'];
13
14
    public function __construct(array $attributes = [])
15
    {
16
        parent::__construct($attributes);
17
        $this->setTable(config('robots.table_names.robot_rows'));
18
    }
19
20
    /**
21
     *
22
     * Generates an array from DB data, compatible with Robots constructor
23
     *
24
     * @return array
25
     */
26
    public static function generateArray(): array
27
    {
28
        $response = [];
29
30
        $response['allows'] = static::where('type', Robots::ALLOW)->get('action')->toArray();
0 ignored issues
show
Bug introduced by
'action' of type string is incompatible with the type array expected by parameter $columns of Illuminate\Database\Eloquent\Builder::get(). ( Ignorable by Annotation )

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

30
        $response['allows'] = static::where('type', Robots::ALLOW)->get(/** @scrutinizer ignore-type */ 'action')->toArray();
Loading history...
31
        $response['disallows'] = static::where('type', Robots::DISALLOW)->get('action')->toArray();
32
        $response['hosts'] = static::where('type', Robots::HOST)->get('action')->toArray();
33
        $response['sitemaps'] = static::where('type', Robots::SITEMAP)->get('action')->toArray();
34
        $response['userAgents'] = static::where('type', Robots::USER_AGENT)->get('action')->toArray();
35
36
        return $response;
37
    }
38
}