Completed
Push — work-fleets ( 1f2a61...18e75e )
by SuperNova.WS
07:59
created

V2UnitModel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 20
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 65
ccs 0
cts 25
cp 0
crap 2
rs 9.3571

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oomelche
5
 * Date: 29.07.2016
6
 * Time: 13:18
7
 */
8
9
namespace V2Unit;
10
11
use Common\ContainerPlus;
12
13
/**
14
 * Class V2UnitModel
15
 *
16
 * Second iteration of revised Unit
17
 *
18
 * @property int $playerOwnerId
19
 * @property int $locationType
20
 * @property int $locationId
21
 * @property int $type
22
 * @property int $snId
23
 * @property int $dbLevel - level of unit for DB: $count for stackable units, $level - fon unstackable units
24
 * @property int $level // TODO
25
 * property int $count // TODO
26
 * property \DateTime $timeStart // TODO
27
 * property \DateTime $timeFinish  // TODO
28
 *
29
 * @package V2Unit
30
 *
31
 */
32
class V2UnitModel extends \Entity {
33
34
  protected static $tableName = 'unit';
35
  protected static $idField = 'unit_id';
36
37
  protected static $_properties = array(
38
    'dbId'          => array(
39
      P_DB_FIELD => 'unit_id',
40
    ),
41
    'playerOwnerId' => array(
42
      P_DB_FIELD => 'unit_player_id',
43
    ),
44
    'locationType'  => array(
45
      P_DB_FIELD => 'unit_location_type',
46
    ),
47
    'locationId'    => array(
48
      P_DB_FIELD => 'unit_location_id',
49
    ),
50
    'type'          => array(
51
      P_DB_FIELD => 'unit_type',
52
    ),
53
    'snId'          => array(
54
      P_DB_FIELD => 'unit_snid',
55
    ),
56
    // Order is important!
57
    'dbLevel'       => array(
58
      // TODO - aggregate function from Level/Count
59
      P_DB_FIELD => 'unit_level',
60
    ),
61
62
    // TODO - split dbLevel to level and count
63
    'level'         => array(),
64
    'count'         => array(),
65
66
    // TODO - move to child class
67
    'timeStart'     => array(
68
      P_DB_FIELD => 'unit_time_start',
69
    ),
70
    'timeFinish'    => array(
71
      P_DB_FIELD => 'unit_time_finish',
72
    ),
73
  );
74
75
  public function __construct(\Common\GlobalContainer $gc) {
76
    parent::__construct($gc);
77
78
    $this->_container = new static::$_containerName();
79
    $this->_container->setProperties(static::$_properties);
80
81
    $that = $this;
82
    $this->_container->assignAccessor(
83
      'type',
84
      P_CONTAINER_SETTER,
85
      function ($value) use ($that) {
86
        $that->type = $value;
87
      }
88
    );
89
    $this->_container->assignAccessor(
90
      'level',
91
      P_CONTAINER_IMPORTER,
92
      function (&$row) use ($that) {
93
//pdump('level setter is launched');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
//pdump($row, '$row');
95
//var_dump($that);
96
        $that->level = $row['unit_level'];
97
//var_dump($that);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
//pdie();
99
100
101
102
//pdump($row['unit_level'], '$row[\'unit_level\']');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
//pdump($that->level, '$that->level');
104
//pdump($that->_container, '$that->_container');
105
//        pdump($that);
106
//pdie('importer launched');
107
      }
108
    );
109
110
    $this->_container->assignAccessor(
111
      'dbLevel',
112
      P_CONTAINER_EXPORTER,
113
      function (&$row) use ($that) {
114
//pdump('level setter is launched');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
115
//pdump($row, '$row');
116
//var_dump($that);
117
        $row['unit_level'] = $that->dbLevel;
118
//var_dump($that);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
//pdie();
120
121
122
123
//pdump($row['unit_level'], '$row[\'unit_level\']');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
124
//pdump($that->level, '$that->level');
125
//pdump($that->_container, '$that->_container');
126
//        pdump($that);
127
//pdie('importer launched');
128
      }
129
    );
130
131
132
//    $this->_container->importRow(array('unit_level' => 5, 'unit_type' => 10,));
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
133
//
134
//    pdump($this->_container->level);
135
//    pdump($this->level);
136
////    pdump($this->type);
137
//
138
//    pdie();
139
  }
140
141
  /**
142
   * @param static $that
143
   * @param array  $row
144
   */
145
  protected function importLevel($that, &$row) {
146
    $that->level = $row['unit_level'];
147
  }
148
149
  /**
150
   * @param static $that
151
   * @param array  $row
152
   */
153
  protected function exportLevel($that, &$row) {
0 ignored issues
show
Unused Code introduced by
The parameter $that is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $row is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
154
    // $row['unit_level'] = $that->level;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
155
  }
156
157
  /**
158
   * @param ContainerPlus $cUnit
159
   */
160
  public function test($unitId, $cUnit = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $cUnit is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
    $this->dbId = $unitId;
162
    static::$rowOperator->getById($this);
163
  }
164
165
}
166