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

ColumnType::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Table;
4
5
//----------------------------------------------------------------------------------------------------------------------
6
/**
7
 * Class for column type metadata.
8
 */
9
class ColumnType
10
{
11
  //--------------------------------------------------------------------------------------------------------------------
12
  /**
13
   * The metadata of the column.
14
   *
15
   * @var array[]
16
   */
17
  protected $columnType = [];
18
19
  //--------------------------------------------------------------------------------------------------------------------
20
  /**
21
   * Object constructor.
22
   *
23
   * @param array[]|Columns $columnProperties The metadata of the column.
24
   */
25
  public function __construct($columnProperties)
26
  {
27
    $this->columnType = $columnProperties;
0 ignored issues
show
Documentation Bug introduced by
It seems like $columnProperties can also be of type object<SetBased\Audit\MySql\Table\Columns>. However, the property $columnType is declared as type array<integer,array>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
28
29
    if (isset($this->columnType['column_type']))
30
    {
31
      if ($this->columnType['column_type']==='timestamp')
32
      {
33
        $this->columnType['column_type'] = $this->columnType['column_type'].' NULL';
34
      }
35
    }
36
  }
37
38
  //--------------------------------------------------------------------------------------------------------------------
39
  /**
40
   * Get columns type.
41
   *
42
   * @return array[]
43
   */
44
  public function getType()
45
  {
46
    return $this->columnType;
47
  }
48
49
  //--------------------------------------------------------------------------------------------------------------------
50
  /**
51
   * Get column property.
52
   *
53
   * @param string $propertyName The property name.
54
   *
55
   * @return string|null
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? Also, consider making the array more specific, something like array<String>, or 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.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
56
   */
57
  public function getProperty($propertyName)
58
  {
59
    if (isset($this->columnType[$propertyName]))
60
    {
61
      return $this->columnType[$propertyName];
62
    }
63
64
    return null;
65
  }
66
67
  //--------------------------------------------------------------------------------------------------------------------
68
}
69
70
//----------------------------------------------------------------------------------------------------------------------
71