Conditions | 3 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
61 | public function get_lsd_headerdata($data, $gamefile_id) |
||
62 | { |
||
63 | $data = base64_decode($data); |
||
64 | |||
65 | $br = new BinaryReader($data); |
||
66 | |||
67 | $array = []; |
||
68 | $br->setPosition(0); |
||
69 | |||
70 | $array['header']['length'] = $br->readInt8(); |
||
71 | $array['header']['data'] = $br->readString($array['header']['length']); |
||
72 | |||
73 | $cat = $br->readInt8(); |
||
74 | $br->readInt8(); |
||
75 | $br->readInt8(); |
||
76 | $array[$cat]['date']['length'] = $br->readInt8(); |
||
77 | $array[$cat]['date']['data'] = $br->readString($array[$cat]['date']['length']); |
||
78 | |||
79 | $array[$cat]['char1_name']['idx'] = $br->readInt8(); |
||
80 | $array[$cat]['char1_name']['length'] = $br->readInt8(); |
||
81 | $array[$cat]['char1_name']['data'] = $br->readString($array[$cat]['char1_name']['length']); |
||
82 | |||
83 | $array[$cat]['char1_level']['idx'] = $br->readInt8(); |
||
84 | $array[$cat]['char1_level']['length'] = $br->readInt8(); |
||
85 | $array[$cat]['char1_level']['data'] = $br->readInt8(); |
||
86 | |||
87 | $array[$cat]['char1_hp']['idx'] = $br->readInt8(); |
||
88 | $array[$cat]['char1_hp']['length'] = $br->readInt8(); |
||
89 | if ($array[$cat]['char1_hp']['length'] == 2) { |
||
90 | $array[$cat]['char1_hp']['data'] = $br->readInt16(); |
||
91 | } else { |
||
92 | $array[$cat]['char1_hp']['data'] = $br->readInt8(); |
||
93 | } |
||
94 | |||
95 | $array[$cat]['char1_face']['idx'] = $br->readInt8(); |
||
96 | $array[$cat]['char1_face']['length'] = $br->readInt8(); |
||
97 | $array[$cat]['char1_face']['data'] = $br->readString($array[$cat]['char1_face']['length']); |
||
98 | $array[$cat]['char1_face']['img_idx'] = $br->readInt8(); |
||
99 | |||
100 | if (! is_null($array[$cat]['char1_face']['img_idx'])) { |
||
101 | $pc = new Player2kController(); |
||
102 | $files = json_decode($pc->deliver_indexjson($gamefile_id), true); |
||
103 | |||
104 | $file = $files['faceset/'.strtolower($array[$cat]['char1_face']['data'])]; |
||
105 | |||
106 | $file = action('Player2kController@deliver_files', [$gamefile_id, $file]); |
||
107 | |||
108 | $array[$cat]['char1_face']['url'] = $file; |
||
109 | } else { |
||
110 | $array[$cat]['char1_face']['url'] = ''; |
||
111 | } |
||
112 | |||
113 | return $array; |
||
114 | } |
||
115 | |||
176 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: