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

ColumnTypes   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 7
c 2
b 2
f 0
lcom 1
cbo 0
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B appendColumnTypes() 0 25 5
A getTypes() 0 4 1
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
  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