PlayerHelper::getSavegameValidation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Helpers;
9
10
use PhpBinaryReader\BinaryReader;
11
12
class PlayerHelper
13
{
14
    public static function getSavegameValidation($data)
15
    {
16
        $br = new BinaryReader($data);
17
18
        $br->setPosition(0);
19
20
        $datalength = $br->readInt8();
21
        $returned = $br->readString($datalength);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
22
23
        if ($returned == 'LcfSaveData') {
24
            return true;
25
        } else {
26
            return false;
27
        }
28
    }
29
30 View Code Duplication
    public function getZipRootPath($zipfilepath)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
31
    {
32
        $dirarray = [
33
            'backdrop',
34
            'battle',
35
            'battle2',
36
            'battlecharset',
37
            'battleweapon',
38
            'charset',
39
            'chipset',
40
            'faceset',
41
            'frame',
42
            'gameover',
43
            'monster',
44
            'panorama',
45
            'picture',
46
            'system',
47
            'system2',
48
            'title',
49
            'music',
50
            'sound',
51
        ];
52
53
        $rootarray = [
54
            'harmony.dll',
55
            'rpg_rt.exe',
56
            'rpg_rt.ini',
57
            'rpg_rt.ldb',
58
            'rpg_rt.lmt',
59
            'rpg_rt.dat',
60
        ];
61
62
        $mapparray = [];
63
        for ($i = 0; $i < 2000; $i++) {
64
            $mapparray[] = 'map'.sprintf('%04d', $i).'.lmu';
65
        }
66
67
        $filearray = array_merge($rootarray, $mapparray);
68
69
        $searcharray = array_merge($dirarray, $filearray);
70
71
        if (starts_with(strtolower($zipfilepath), $searcharray)) {
72
            $imp = str_replace('/', '\\/', $zipfilepath);
73
        } else {
74
            if (str_contains(strtolower($zipfilepath), $searcharray)) {
75
                $exp = explode('/', $zipfilepath);
76
                $res = array_shift($exp);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
                $imp = implode('/', $exp);
78
                $imp = $this->getZipRootPath($imp);
79
            } else {
80
                $imp = '';
81
            }
82
        }
83
84
        if ($imp != '') {
85
            if (array_search(strtolower($imp), $filearray)) {
86
                $imp = '.\\/'.$imp;
87
            }
88
        }
89
90
        return $imp;
91
    }
92
}
93