Completed
Push — master ( 94b62d...da3388 )
by P.R.
9s
created

RowHelper   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 4 Features 0
Metric Value
wmc 20
c 4
b 4
f 0
lcom 1
cbo 1
dl 0
loc 112
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B createColumnOptionsRow() 0 16 5
A styledOptionsRow() 0 7 3
B createTableRow() 0 9 5
B checkOptions() 0 21 5
A appendRow() 0 10 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
6
//----------------------------------------------------------------------------------------------------------------------
7
use SetBased\Audit\ColumnTypes;
8
9
/**
10
 * A helper class for column types.
11
 */
12
class RowHelper
13
{
14
  //--------------------------------------------------------------------------------------------------------------------
15
  /**
16
   * Create table row.
17
   *
18
   * @param array[] $theRow Data for table row.
19
   *
20
   * @return array<string,null|string>
21
   */
22
  public static function createColumnOptionsRow($theRow)
23
  {
24
    $dataCharsetName   = isset($theRow['data_character_set_name']) ? $theRow['data_character_set_name'] : null;
25
    $dataCollationName = isset($theRow['data_collation_name']) ? $theRow['data_collation_name'] : null;
26
27
    $auditCharsetName   = isset($theRow['audit_character_set_name']) ? $theRow['audit_character_set_name'] : null;
28
    $auditCollationName = isset($theRow['audit_collation_name']) ? $theRow['audit_collation_name'] : null;
29
30
31
    $tableRow = ['column_name'      => null,
32
                 'data_table_type'  => self::styledOptionsRow($dataCharsetName, $dataCollationName),
33
                 'audit_table_type' => self::styledOptionsRow($auditCharsetName, $auditCollationName),
34
                 'config_type'      => null];
35
36
    return $tableRow;
37
  }
38
39
  //--------------------------------------------------------------------------------------------------------------------
40
  /**
41
   * Create table row.
42
   *
43
   * @param $theCharacterSetName
44
   * @param $theCollationName
45
   *
46
   * @return string
47
   */
48
  public static function styledOptionsRow($theCharacterSetName, $theCollationName)
49
  {
50
    $charsetName   = isset($theCharacterSetName) ? '['.$theCharacterSetName.']' : null;
51
    $collationName = isset($theCollationName) ? '['.$theCollationName.']' : null;
52
53
    return trim(sprintf('%s %s', $charsetName, $collationName));
54
  }
55
56
  //--------------------------------------------------------------------------------------------------------------------
57
  /**
58
   * Create table row.
59
   *
60
   * @param array[] $theRow Data for table row.
61
   *
62
   * @return array<string,null|string>
0 ignored issues
show
Documentation introduced by
Should the return type not be array<string,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...
63
   */
64
  public static function createTableRow($theRow)
65
  {
66
    $tableRow = ['column_name'      => isset($theRow['column_name']) ? $theRow['column_name'] : null,
67
                 'data_table_type'  => isset($theRow['data_column_type']) ? $theRow['data_column_type'] : null,
68
                 'audit_table_type' => isset($theRow['audit_column_type']) ? $theRow['audit_column_type'] : null,
69
                 'config_type'      => isset($theRow['config_column_type']) ? $theRow['config_column_type'] : null];
70
71
    return $tableRow;
72
  }
73
74
  //--------------------------------------------------------------------------------------------------------------------
75
  /**
76
   * Check isset options(collation, character set name) from row.
77
   *
78
   * @param array[] $theRow Row for append.
79
   *
80
   * @return bool
81
   */
82
  private static function checkOptions($theRow)
83
  {
84
    if (isset($theRow['audit_character_set_name']))
85
    {
86
      return true;
87
    }
88
    if (isset($theRow['data_character_set_name']))
89
    {
90
      return true;
91
    }
92
    if (isset($theRow['audit_collation_name']))
93
    {
94
      return true;
95
    }
96
    if (isset($theRow['data_collation_name']))
97
    {
98
      return true;
99
    }
100
101
    return false;
102
  }
103
104
  //--------------------------------------------------------------------------------------------------------------------
105
  /**
106
   * Append a row.
107
   *
108
   * @param \array[]    $theExistRows Exist rows array for appending.
109
   * @param ColumnTypes $theRow       Row for append.
110
   */
111
  public static function appendRow(&$theExistRows, $theRow)
112
  {
113
    $theRow         = $theRow->getTypes();
114
    $theExistRows[] = self::createTableRow($theRow);
115
    if (self::checkOptions($theRow))
116
    {
117
      $theRow         = self::createColumnOptionsRow($theRow);
118
      $theExistRows[] = $theRow;
119
    }
120
  }
121
122
  //--------------------------------------------------------------------------------------------------------------------
123
}
124
125
//----------------------------------------------------------------------------------------------------------------------
126