Completed
Push — trunk ( c5d539...959c53 )
by SuperNova.WS
04:43
created

MissionData::buildFromArray()   C

Complexity

Conditions 13
Paths 4096

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 0
Metric Value
cc 13
eloc 9
nc 4096
nop 1
dl 0
loc 12
rs 5.2936
c 0
b 0
f 0
ccs 0
cts 10
cp 0
crap 182

How to fix   Complexity   

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 Gorlum 11.10.2017 13:17
4
 */
5
6
namespace Fleet;
7
8
9
class MissionData {
10
  /**
11
   * @var array|null
12
   */
13
  public $fleet;
14
15
  /**
16
   * @var array|null
17
   */
18
  public $dst_user;
19
20
  /**
21
   * @var array|null
22
   */
23
  public $dst_planet;
24
25
  /**
26
   * @var array|null
27
   */
28
  public $src_user;
29
30
  /**
31
   * @var array|null
32
   */
33
  public $src_planet;
34
35
  /**
36
   * @var array|null
37
   */
38
  public $fleet_event;
39
40
  /**
41
   * @param $mission_data
42
   *
43
   * @return static
44
   */
45
  public static function buildFromArray($mission_data) {
46
    $that = new static();
47
48
    $that->fleet = is_array($mission_data['fleet']) && !empty($mission_data['fleet']) ? $mission_data['fleet'] : null;
49
    $that->dst_user = is_array($mission_data['dst_user']) && !empty($mission_data['dst_user']) ? $mission_data['dst_user'] : null;
50
    $that->dst_planet = is_array($mission_data['dst_planet']) && !empty($mission_data['dst_planet']) ? $mission_data['dst_planet'] : null;
51
    $that->src_user = is_array($mission_data['src_user']) && !empty($mission_data['src_user']) ? $mission_data['src_user'] : null;
52
    $that->src_planet = is_array($mission_data['src_planet']) && !empty($mission_data['src_planet']) ? $mission_data['src_planet'] : null;
53
    $that->fleet_event = is_array($mission_data['fleet_event']) && !empty($mission_data['fleet_event']) ? $mission_data['fleet_event'] : null;
54
55
    return $that;
56
  }
57
58
}
59