RobotsRow::generateArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mguinea\Robots\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Mguinea\Robots\Robots;
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('laravel-robots.table_names.robot_rows'));
18
    }
19
20
    /**
21
     * Generates an array from DB data, compatible with Robots constructor.
22
     *
23
     * @return array
24
     */
25
    public static function generateArray(): array
26
    {
27
        return [
28
            'allows' => static::where('type', Robots::ALLOW)->get('action')->toArray(),
29
            'disallows' => static::where('type', Robots::DISALLOW)->get('action')->toArray(),
30
            'hosts' => static::where('type', Robots::HOST)->get('action')->toArray(),
31
            'sitemaps' => static::where('type', Robots::SITEMAP)->get('action')->toArray(),
32
            'userAgents' => static::where('type', Robots::USER_AGENT)->get('action')->toArray(),
33
        ];
34
    }
35
}
36