Test Failed
Push — main ( 894963...0f30b5 )
by Rafael
05:41
created

Seeder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
dl 0
loc 27
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base;
20
21
use Alxarafe\Base\Model\Model;
22
23
/**
24
 * Create a PDO database connection
25
 *
26
 * @package Alxarafe\Base
27
 */
28
abstract class Seeder
29
{
30
    public function __construct($truncate = false)
31
    {
32
        $model = static::model();
33
34
        if ($truncate) {
35
            $model::truncate();
36
        }
37
38
        if ($model::count() === 0) {
39
            $this->run($model);
40
        }
41
    }
42
43
    /**
44
     * Returns the name of the seeder table.
45
     */
46
    abstract protected static function model();
47
48
    /**
49
     * Execute the seeder
50
     *
51
     * @param string $model
52
     * @return mixed
53
     */
54
    abstract protected function run(string $model): void;
55
}
56