Completed
Pull Request — master (#29)
by
unknown
02:32
created

ColumnTypes::appendColumnTypes()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 25
rs 8.439
cc 5
eloc 11
nc 5
nop 2
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  $typePrefix  Prefix for column type name.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $typePrefix not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
37
   *
38
   * @return \array[]
0 ignored issues
show
Documentation introduced by
Should the return type not be \array[]|null?

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