Completed
Pull Request — master (#40)
by Dima
06:19
created

ColumnTypeExtended   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 69
ccs 0
cts 23
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B extendColumnTypes() 0 26 5
A getTypes() 0 4 1
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
use SetBased\Audit\MySql\Metadata\ColumnMetadata;
7
8
/**
9
 * Class for extended column type.
10
 */
11
class ColumnTypeExtended
12
{
13
  //--------------------------------------------------------------------------------------------------------------------
14
  /**
15
   * The metadata of the column.
16
   *
17
   * @var array[]
18
   */
19
  protected $columnTypes = [];
20
21
  //--------------------------------------------------------------------------------------------------------------------
22
  /**
23
   * Object constructor.
24
   *
25
   * @param array[]|ColumnMetadata $columnTypes The metadata of the column.
26
   * @param null|string            $typePrefix  Prefix for column type name.
27
   */
28
  public function __construct($columnTypes, $typePrefix)
29
  {
30
    $this->extendColumnTypes($columnTypes, $typePrefix);
31
  }
32
33
  //--------------------------------------------------------------------------------------------------------------------
34
  /**
35
   * Create array with all columns types.
36
   *
37
   * @param array[]|ColumnMetadata $columnTypes The metadata of the column.
38
   * @param null|string        $typePrefix  Prefix for column type name.
39
   */
40
  public function extendColumnTypes($columnTypes, $typePrefix)
41
  {
42
    $columnTypes = $columnTypes->getProperties();
43
    foreach ($columnTypes as $typeName => $typeValue)
44
    {
45
      if ($typeName=='column_name')
46
      {
47
        if (!isset($this->columnTypes['column_name']))
48
        {
49
          $this->columnTypes[$typeName] = $typeValue;
50
        }
51
      }
52
      else
53
      {
54
        $format = '%s_%s';
55
        if (isset($typePrefix))
56
        {
57
          $this->columnTypes[sprintf($format, $typePrefix, $typeName)] = $typeValue;
58
        }
59
        else
60
        {
61
          $this->columnTypes[$typeName] = $typeValue;
62
        }
63
      }
64
    }
65
  }
66
67
  //--------------------------------------------------------------------------------------------------------------------
68
  /**
69
   * Get columns type.
70
   *
71
   * @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...
72
   */
73
  public function getTypes()
74
  {
75
    return $this->columnTypes;
76
  }
77
78
  //--------------------------------------------------------------------------------------------------------------------
79
}
80
81
//----------------------------------------------------------------------------------------------------------------------
82