Completed
Push — master ( 94b62d...da3388 )
by P.R.
9s
created

ColumnTypes::getTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
/**
7
 * Class for metadata of (table) column types.
8
 */
9
class ColumnTypes
10
{
11
  //--------------------------------------------------------------------------------------------------------------------
12
  /**
13
   * The metadata of the columns.
14
   *
15
   * @var array[]
16
   */
17
  private $columnTypes = [];
18
19
  //--------------------------------------------------------------------------------------------------------------------
20
  /**
21
   * Object constructor.
22
   *
23
   * @param array[]     $columnTypes The metadata of the column.
24
   * @param null|string $typePrefix  Prefix for column type name.
25
   */
26
  public function __construct($columnTypes, $typePrefix = null)
27
  {
28
    $this->appendColumnTypes($columnTypes, $typePrefix);
29
  }
30
31
  //--------------------------------------------------------------------------------------------------------------------
32
  /**
33
   * Return array with all columns types.
34
   *
35
   * @param array[] $columnTypes The metadata of the column.
36
   * @param string}null  $typePrefix  Prefix for column type name.
0 ignored issues
show
Documentation introduced by
The doc-type string}null could not be parsed: Unknown type name "string}null" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
37
   */
38
  public function appendColumnTypes($columnTypes, $typePrefix = null)
39
  {
40
    foreach ($columnTypes as $typeName => $typeValue)
41
    {
42
      if ($typeName=='column_name')
43
      {
44
        if (!isset($this->columnTypes['column_name']))
45
        {
46
          $this->columnTypes[$typeName] = $typeValue;
47
        }
48
      }
49
      else
50
      {
51
        $format = '%s_%s';
52
        if (isset($typePrefix))
53
        {
54
          $this->columnTypes[sprintf($format, $typePrefix, $typeName)] = $typeValue;
55
        }
56
        else
57
        {
58
          $this->columnTypes[$typeName] = $typeValue;
59
        }
60
      }
61
    }
62
  }
63
64
  //--------------------------------------------------------------------------------------------------------------------
65
  /**
66
   * Get columns types.
67
   *
68
   * @return array[]
69
   */
70
  public function getTypes()
71
  {
72
    return $this->columnTypes;
73
  }
74
75
  //--------------------------------------------------------------------------------------------------------------------
76
}
77
78
//----------------------------------------------------------------------------------------------------------------------
79