Completed
Push — master ( b7efbe...08e0f6 )
by P.R.
01:05
created

DiffTableColumns::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 3
crap 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
use SetBased\Audit\MySql\Metadata\ColumnMetadata;
6
use SetBased\Audit\MySql\Metadata\TableColumnsMetadata;
7
8
//----------------------------------------------------------------------------------------------------------------------
9
/**
10
 * Class container for all column types like audit,data and config.
11
 */
12
class DiffTableColumns
13
{
14
  //--------------------------------------------------------------------------------------------------------------------
15
  /**
16
   * Contains all column types from audit and data schemas.
17
   *
18
   * @var array[]
19
   */
20
  private $columnTypes = [];
21
22
  //--------------------------------------------------------------------------------------------------------------------
23
  /**
24
   * Object constructor
25
   *
26
   * @param TableColumnsMetadata $configColumns The table columns from config file.
27
   * @param TableColumnsMetadata $auditColumns  The table columns from audit schema.
28
   * @param TableColumnsMetadata $dataColumns   The table columns from data schema.
29
   */
30
  public function __construct($configColumns, $auditColumns, $dataColumns)
31
  {
32
    $auditConfigTypes = $configColumns;
33
    $auditTypes       = $auditColumns;
34
    $dataTypes        = $dataColumns;
35
    $allTypes         = ['config' => $auditConfigTypes, 'audit' => $auditTypes, 'data' => $dataTypes];
36
37
    $this->appendColumnTypes($allTypes);
38
  }
39
40
  //--------------------------------------------------------------------------------------------------------------------
41
  /**
42
   * Get columns types.
43
   *
44
   * @return array[]
45
   */
46
  public function getTypes()
47
  {
48
    return $this->columnTypes;
49
  }
50
51
  //--------------------------------------------------------------------------------------------------------------------
52
  /**
53
   * Add to array all columns types.
54
   *
55
   * @param array<string,object> $allTypes The metadata of the column.
56
   */
57
  private function appendColumnTypes($allTypes)
58
  {
59
    /** @var TableColumnsMetadata $typesArray */
60
    foreach ($allTypes as $typePrefix => $typesArray)
61
    {
62
      $typesArray = $typesArray->getColumns();
63
      /** @var ColumnMetadata $type */
64
      foreach ($typesArray as $type)
65
      {
66
        if (isset($this->columnTypes[$type->getProperty('column_name')]))
67
        {
68
          /** @var ColumnMetadataExtended */
69
          $this->columnTypes[$type->getProperty('column_name')]->extendColumnTypes($type, $typePrefix);
70
        }
71
        else
72
        {
73
          $this->columnTypes[$type->getProperty('column_name')] = new ColumnMetadataExtended($type, $typePrefix);
74
        }
75
      }
76
    }
77
  }
78
79
  //--------------------------------------------------------------------------------------------------------------------
80
}
81
82
//----------------------------------------------------------------------------------------------------------------------
83