Completed
Pull Request — master (#40)
by Dima
03:24
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);
0 ignored issues
show
Documentation introduced by
$allTypes is of type array<string,object<SetB...ableColumnsMetadata>"}>, 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
   * 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[] $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();
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...
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