Completed
Push — work-fleets ( bd15ac...5c3a01 )
by SuperNova.WS
06:16
created

V2UnitContainer::__construct()   C

Complexity

Conditions 7
Paths 1

Size

Total Lines 37
Code Lines 24

Duplication

Lines 20
Ratio 54.05 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 7
Bugs 1 Features 0
Metric Value
cc 7
eloc 24
nc 1
nop 1
dl 20
loc 37
rs 6.7272
c 7
b 1
f 0
ccs 0
cts 28
cp 0
crap 56
1
<?php
2
/**
3
 * Created by Gorlum 10.08.2016 14:25
4
 */
5
6
namespace V2Unit;
7
use Common\GlobalContainer;
8
9
/**
10
 * Class V2UnitContainer
11
 *
12
 * @method V2UnitModel getModel()
13
 *
14
 * @property int       $playerOwnerId
15
 * @property int       $locationType
16
 * @property int       $locationId
17
 * @property int       $type
18
 * @property int       $snId
19
 * @property int       $level - level of unit for DB: $count for stackable units, $level - fon unstackable units
20
 * property int $count // TODO
21
 * @property \DateTime $timeStart
22
 * @property \DateTime $timeFinish
23
 *
24
 * @property bool      $isStackable
25
 * @property string    $locationDefaultType
26
 * @property int       $bonusType // TODO - Optional?
27
 * @property array     $unitInfo - full info about unit
28
 *
29
 * @package V2Unit
30
 */
31
class V2UnitContainer extends \EntityContainer {
32
  /**
33
   * @var V2UnitModel $model
34
   */
35
  protected $model;
36
37
//  protected static $exceptionClass = 'EntityException';
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
38
  protected static $modelClass = 'V2Unit\V2UnitModel';
39
40
  /**
41
   * Property list
42
   *
43
   * @var array $properties
44
   */
45
  protected $properties = array(
46
    'dbId'                => array(
47
      P_DB_FIELD => 'unit_id',
48
    ),
49
    'playerOwnerId'       => array(
50
      P_DB_FIELD => 'unit_player_id',
51
    ),
52
    'locationType'        => array(
53
      P_DB_FIELD => 'unit_location_type',
54
    ),
55
    'locationId'          => array(
56
      P_DB_FIELD => 'unit_location_id',
57
    ),
58
    'type'                => array(
59
      P_DB_FIELD => 'unit_type',
60
    ),
61
    'snId'                => array(
62
      P_DB_FIELD => 'unit_snid',
63
    ),
64
    // Order is important!
65
    // TODO - split dbLevel to level and count
66
    'level'               => array(
67
      P_DB_FIELD => 'unit_level',
68
    ),
69
    'count'               => array(),
70
    // TODO - move to child class
71
    'timeStart'           => array(
72
      P_DB_FIELD => 'unit_time_start',
73
    ),
74
    'timeFinish'          => array(
75
      P_DB_FIELD => 'unit_time_finish',
76
    ),
77
    // Do we need it? Or internal no info/getters/setters should be ignored?
78
    'unitInfo'            => array(),
79
    'isStackable'         => array(),
80
    'locationDefaultType' => array(),
81
    'bonusType'           => array(),
82
  );
83
84
  /**
85
   * BuddyContainer constructor.
86
   *
87
   * @param GlobalContainer $gc
88
   */
89
  public function __construct($gc) {
90
    parent::__construct();
91
92
    $this->assignAccessor('type', P_CONTAINER_SET,
93 View Code Duplication
      function (V2UnitContainer $that, $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
        $that->setDirect('type', $value);
95
        $array = get_unit_param($value);
96
        $that->unitInfo = $array;
97
        // Mandatory
98
        $that->isStackable = empty($array[P_STACKABLE]) ? false : true;
99
        $that->locationDefaultType = empty($array[P_LOCATION_DEFAULT]) ? LOC_NONE : $array[P_LOCATION_DEFAULT];
100
        // Optional
101
        $that->bonusType = empty($array[P_BONUS_TYPE]) ? BONUS_NONE : $array[P_BONUS_TYPE];
102
      }
103
    );
104
    $this->assignAccessor('type', P_CONTAINER_UNSET,
105 View Code Duplication
      function (V2UnitContainer $that, $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
        $that->setDirect('type', $value);
107
        $array = get_unit_param($value);
108
        $that->unitInfo = $array;
109
        // Mandatory
110
        $that->isStackable = empty($array[P_STACKABLE]) ? false : true;
111
        $that->locationDefaultType = empty($array[P_LOCATION_DEFAULT]) ? LOC_NONE : $array[P_LOCATION_DEFAULT];
112
        // Optional
113
        $that->bonusType = empty($array[P_BONUS_TYPE]) ? BONUS_NONE : $array[P_BONUS_TYPE];
114
      }
115
    );
116
117
    // This crap code is until php 5.4+. There we can use $this binding for lambdas
118
    $propertyName = 'timeStart';
119
    $this->assignAccessor($propertyName, P_CONTAINER_IMPORT, array($gc->types, 'dateTimeImport'));
120
    $this->assignAccessor($propertyName, P_CONTAINER_EXPORT, array($gc->types, 'dateTimeExport'));
121
122
    $propertyName = 'timeFinish';
123
    $this->assignAccessor($propertyName, P_CONTAINER_IMPORT, array($gc->types, 'dateTimeImport'));
124
    $this->assignAccessor($propertyName, P_CONTAINER_EXPORT, array($gc->types, 'dateTimeExport'));
125
  }
126
127
  public function isEmpty() {
128
    return
129
      empty($this->playerOwnerId)
130
      ||
131
      is_null($this->locationType)
132
      ||
133
      $this->locationType === LOC_NONE
134
      ||
135
      empty($this->locationId)
136
      ||
137
      empty($this->type)
138
      ||
139
      empty($this->snId)
140
      ||
141
      empty($this->level);
142
  }
143
144
}
145