Failed Conditions
Push — master ( 481c82...217341 )
by Ryan
02:09
created

DBCreateTable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 6 5
A __construct() 0 4 1
A __set() 0 7 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Godsgood33\Php_Db;
6
7
/**
8
 * Class to help creating new tables
9
 *
10
 * @author Ryan Prather <[email protected]>
11
 */
12
class DBCreateTable
13
{
14
15
    /**
16
     * Private variable to store the name of the field to create
17
     *
18
     * @var string
19
     */
20
    private $data;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param string $field
26
     * @param string $datatype
27
     */
28 1
    public function __construct(string $field, string $datatype)
29
    {
30 1
        $this->data['field'] = $field;
31 1
        $this->data['datatype'] = $datatype;
32 1
    }
33
34
    /**
35
     * Magic setter method
36
     *
37
     * @param string $name
38
     * @param string|int|null $value
39
     */
40 1
    public function __set(string $name, $value): DBCreateTable
41
    {
42 1
        if (in_array($name, ['field', 'datatype', 'default', 'option'])) {
43 1
            $this->data[$name] = $value;
44
        }
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * Magic method to convert the class to a string
51
     *
52
     * @return string
53
     */
54 1
    public function __toString(): string
55
    {
56 1
        $default = (isset($this->data['default']) ? $this->data['default'] : null);
57 1
        $option = (isset($this->data['option']) ? $this->data['option'] : null);
58
59 1
        return "`{$this->data['field']}` {$this->data['datatype']}" . (!is_null($default) ? " {$default}" : null) . (!is_null($option) ? " {$option}" : null);
60
    }
61
}
62