Completed
Push — master ( 8e94f8...744b49 )
by P.R.
04:26
created

ColumnMetadata::getProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Metadata;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
/**
7
 * Metadata of table columns.
8
 */
9
class ColumnMetadata
10
{
11
  //--------------------------------------------------------------------------------------------------------------------
12
  /**
13
   * The properties of the column that are stored by this class.
14
   *
15
   * var string[]
16
   */
17
  protected static $fields = ['column_name',
18
                              'column_type',
19
                              'is_nullable',
20
                              'character_set_name',
21
                              'collation_name'];
22
23
  /**
24
   * The the properties of this table column.
25
   *
26
   * @var array<string,string>
27
   */
28
  protected $properties = [];
29
30
  //--------------------------------------------------------------------------------------------------------------------
31
  /**
32
   * Object constructor.
33
   *
34
   * @param array[] $properties The metadata of the column.
35
   */
36 10
  public function __construct($properties)
37
  {
38 10
    foreach (static::$fields as $field)
39
    {
40 10
      if (isset($properties[$field]))
41 10
      {
42 10
        $this->properties[$field] = $properties[$field];
43 10
      }
44 10
    }
45 10
  }
46
47
  //--------------------------------------------------------------------------------------------------------------------
48
  /**
49
   * Returns the properties of this table column as an array.
50
   *
51
   * @return array[]
0 ignored issues
show
Documentation introduced by
Should the return type not be array<string,string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
   */
53 8
  public function getProperties()
54
  {
55 8
    return $this->properties;
56
  }
57
58
  //--------------------------------------------------------------------------------------------------------------------
59
  /**
60
   * Returns a property of this table column.
61
   *
62
   * @param string $name The name of the property.
63
   *
64
   * @return string|null
65
   */
66 10
  public function getProperty($name)
67
  {
68 10
    if (isset($this->properties[$name]))
69 10
    {
70 10
      return $this->properties[$name];
71
    }
72
73 5
    return null;
74
  }
75
76
  //--------------------------------------------------------------------------------------------------------------------
77
  /**
78
   * Make this column nullable.
79
   */
80 5
  public function makeNullable()
81
  {
82 5
    $this->properties['is_nullable'] = 'YES';
83 5
  }
84
85
  //--------------------------------------------------------------------------------------------------------------------
86
}
87
88
//----------------------------------------------------------------------------------------------------------------------
89