CreateParametresTable::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of BlitzPHP Parametres.
7
 *
8
 * (c) 2025 Dimitri Sitchet Tomkeu <[email protected]>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13
14
namespace BlitzPHP\Parametres\Database\Migrations;
15
16
use BlitzPHP\Database\Migration\Migration;
17
use BlitzPHP\Database\Migration\Structure;
18
use stdClass;
19
20
class CreateParametresTable extends Migration
21
{
22
    private stdClass $config;
23
24
    public function __construct()
25
    {
26
        $this->config = (object) config('parametres');
27
        $this->group  = $this->config->database['group'] ?? 'default';
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function up(): void
34
    {
35
        $this->create($this->config->database['table'], static function (Structure $table) {
36
            $table->id();
37
            $table->string('file');
38
            $table->string('key');
39
            $table->text('value')->nullable();
40
            $table->string('type', 31)->default('string');
41
            $table->string('context')->nullable();
42
            $table->timestamps();
43
44
            return $table;
45
        });
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function down(): void
52
    {
53
        $this->dropIfExists($this->config->database['table']);
54
    }
55
}
56