Completed
Push — master ( 5d62cd...a400a0 )
by P.R.
04:25
created

ColumnTypesExtended   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A appendColumnTypes() 0 20 4
A getTypes() 0 4 1
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Helper;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
use SetBased\Audit\MySql\Table\Columns;
7
use SetBased\Audit\MySQl\Table\ColumnType;
8
9
/**
10
 * A helper class for column types.
11
 */
12
class ColumnTypesExtended
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 array[] $configColumns The table columns from config file.
27
   * @param Columns $auditColumns  The table columns from audit schema.
28
   * @param Columns $dataColumns   The table columns from data schema.
29
   */
30
  public function __construct($configColumns, $auditColumns, $dataColumns)
31
  {
32
    $auditConfigTypes = new Columns($configColumns);
33
    $auditTypes       = $auditColumns;
34
    $dataTypes        = $dataColumns;
35
    $allTypes         = ['config' => $auditConfigTypes, 'audit' => $auditTypes, 'data' => $dataTypes];
36
37
    $this->appendColumnTypes($allTypes);
0 ignored issues
show
Documentation introduced by
$allTypes is of type array<string,object<SetB...Sql\\Table\\Columns>"}>, but the function expects a array<integer,array>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
  }
39
40
  //--------------------------------------------------------------------------------------------------------------------
41
  /**
42
   * Add to array all columns types.
43
   *
44
   * @param array[] $columnTypes The metadata of the column.
45
   */
46
  private function appendColumnTypes($columnTypes)
47
  {
48
    /** @var Columns $typesArray */
49
    foreach ($columnTypes as $typePrefix => $typesArray)
50
    {
51
      $typesArray = $typesArray->getColumns();
0 ignored issues
show
Bug introduced by
The method getColumns cannot be called on $typesArray (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
52
      /** @var ColumnType $type */
53
      foreach ($typesArray as $type)
54
      {
55
        if (isset($this->columnTypes[$type->getProperty('column_name')]))
56
        {
57
          $this->columnTypes[$type->getProperty('column_name')]->extendColumnTypes($type, $typePrefix);
58
        }
59
        else
60
        {
61
          $this->columnTypes[$type->getProperty('column_name')] = new ColumnTypesHelper($type, $typePrefix);
62
        }
63
      }
64
    }
65
  }
66
67
  //--------------------------------------------------------------------------------------------------------------------
68
  /**
69
   * Get columns types.
70
   *
71
   * @return array[]
72
   */
73
  public function getTypes()
74
  {
75
    return $this->columnTypes;
76
  }
77
78
  //--------------------------------------------------------------------------------------------------------------------
79
}
80
81
//----------------------------------------------------------------------------------------------------------------------
82