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

RowHelper::createTableRow()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 9
rs 8.8571
cc 5
eloc 6
nc 16
nop 1
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 \string
0 ignored issues
show
Documentation introduced by
Should the return type not be array<string,null|string>?

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...
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[]
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