Completed
Pull Request — master (#31)
by
unknown
02:42
created

ColumnTypesHelper::extendColumnTypes()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.439
cc 5
eloc 12
nc 5
nop 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
use SetBased\Audit\MySql\Table\Columns;
7
use SetBased\Audit\MySQl\Table\ColumnType;
8
9
/**
10
 * Class for metadata of (table) column types.
11
 */
12
class ColumnTypesHelper
13
{
14
  //--------------------------------------------------------------------------------------------------------------------
15
  /**
16
   * The metadata of the column.
17
   *
18
   * @var array[]
19
   */
20
  protected $columnTypes = [];
21
22
  //--------------------------------------------------------------------------------------------------------------------
23
  /**
24
   * Object constructor.
25
   *
26
   * @param array[]|ColumnType $columnTypes The metadata of the column.
27
   * @param null|string        $typePrefix  Prefix for column type name.
28
   */
29
  public function __construct($columnTypes, $typePrefix)
30
  {
31
    $this->extendColumnTypes($columnTypes, $typePrefix);
32
  }
33
34
  //--------------------------------------------------------------------------------------------------------------------
35
  /**
36
   * Create array with all columns types.
37
   *
38
   * @param array[]|ColumnType $columnTypes The metadata of the column.
39
   * @param null|string     $typePrefix  Prefix for column type name.
40
   */
41
  public function extendColumnTypes($columnTypes, $typePrefix)
42
  {
43
    $columnTypes = $columnTypes->getType();
44
    foreach ($columnTypes as $typeName => $typeValue)
45
    {
46
      if ($typeName=='column_name')
47
      {
48
        if (!isset($this->columnTypes['column_name']))
49
        {
50
          $this->columnTypes[$typeName] = $typeValue;
51
        }
52
      }
53
      else
54
      {
55
        $format = '%s_%s';
56
        if (isset($typePrefix))
57
        {
58
          $this->columnTypes[sprintf($format, $typePrefix, $typeName)] = $typeValue;
59
        }
60
        else
61
        {
62
          $this->columnTypes[$typeName] = $typeValue;
63
        }
64
      }
65
    }
66
  }
67
68
  //--------------------------------------------------------------------------------------------------------------------
69
  /**
70
   * Get columns type.
71
   *
72
   * @return \array[]
0 ignored issues
show
Documentation introduced by
Should the return type not be array[]?

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...
73
   */
74
  public function getTypes()
75
  {
76
    return $this->columnTypes;
77
  }
78
79
  //--------------------------------------------------------------------------------------------------------------------
80
}
81
82
//----------------------------------------------------------------------------------------------------------------------
83