Completed
Push — master ( cf3a28...b21e6b )
by P.R.
03:40
created

TableHelper::appendRows()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
use SetBased\Audit\MySql\DataLayer;
7
use Symfony\Component\Console\Helper\TableSeparator;
8
9
/**
10
 * A helper class for creating printing Tables.
11
 */
12
class TableHelper
13
{
14
  //--------------------------------------------------------------------------------------------------------------------
15
  /**
16
   * Array with rows for table.
17
   *
18
   * @var \array[]
19
   */
20
  private $rows = [];
21
22
  /**
23
   * Table options from audit schema.
24
   *
25
   * @var array
26
   */
27
  private $auditTableOptions;
28
29
  /**
30
   * Table options from data schema.
31
   *
32
   * @var array
33
   */
34
  private $dataTableOptions;
35
36
  //--------------------------------------------------------------------------------------------------------------------
37
  /**
38
   * Object constructor.
39
   *
40
   * @param string $dataSchema  Data schema name.
41
   * @param string $auditSchema Audit schema name.
42
   * @param string $tableName   The table name.
43
   */
44
  public function __construct($dataSchema, $auditSchema, $tableName)
45
  {
46
    $this->auditTableOptions = DataLayer::getTableOptions($auditSchema, $tableName);
47
    $this->dataTableOptions  = DataLayer::getTableOptions($dataSchema, $tableName);
48
  }
49
50
  //--------------------------------------------------------------------------------------------------------------------
51
  /**
52
   * Append row with table option.
53
   *
54
   * @param string $theOption
55
   */
56
  public function appendTableOption($theOption)
57
  {
58
    $this->rows[$theOption] = ['column_name'      => $theOption,
59
                               'data_table_type'  => $this->dataTableOptions[$theOption],
60
                               'audit_table_type' => $this->auditTableOptions[$theOption],
61
                               'config_type'      => null];
62
  }
63
64
  //--------------------------------------------------------------------------------------------------------------------
65
  /**
66
   * Appends rows.
67
   *
68
   * @param \array[] $theRows
69
   */
70
  public function appendRows($theRows)
71
  {
72
    foreach ($theRows as $row)
73
    {
74
      $this->rows[] = $row;
75
    }
76
    $this->rows[] = new TableSeparator();
77
    $this->appendTableOption('engine');
78
    $this->appendTableOption('character_set_name');
79
  }
80
81
  //--------------------------------------------------------------------------------------------------------------------
82
  /**
83
   * Get rows.
84
   *
85
   * @return \array[]
86
   */
87
  public function getRows()
88
  {
89
    return $this->rows;
90
  }
91
92
93
  //--------------------------------------------------------------------------------------------------------------------
94
}
95
96
//----------------------------------------------------------------------------------------------------------------------
97