Conditions | 17 |
Paths | 41 |
Total Lines | 111 |
Code Lines | 53 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
45 | public function addDumpToMedia( |
||
46 | $media_id, |
||
47 | $format, |
||
48 | $file_name, |
||
49 | $tempfilename, |
||
50 | $info, |
||
51 | $game_file_temp_path, |
||
52 | $game_file_path, |
||
53 | $filesize |
||
54 | ) { |
||
55 | //check the extension of the file, is it zipped or not? |
||
56 | $file_ext = strrchr($file_name, "."); |
||
57 | $file_ext = explode(".", $file_ext); |
||
58 | $file_ext = strtolower($file_ext[1]); |
||
59 | |||
60 | // If it is ZIP, do all the zippidy zip stuff |
||
61 | if ($file_ext == 'zip') { |
||
62 | // Time for zip magic |
||
63 | $zip = new \PclZip("$tempfilename"); |
||
64 | |||
65 | // Obtain the contentlist of the zip file. |
||
66 | if (($list = $zip->listContent()) == 0) { |
||
67 | die("Error : " . $zip->errorInfo(true)); |
||
68 | } |
||
69 | |||
70 | // Get the filename from the returned array |
||
71 | $filename = $list[0]['filename']; |
||
72 | |||
73 | // Split the filename to get the extention |
||
74 | $ext = strrchr($filename, "."); |
||
75 | |||
76 | // Get rid of the . in the extention |
||
77 | $ext = explode(".", $ext); |
||
78 | |||
79 | // convert to lowercase just incase.... |
||
80 | $ext = strtolower($ext[1]); |
||
81 | |||
82 | // check if the extention is valid. |
||
83 | if ($ext == "stx" || $ext == "msa" || $ext == "st" || $file_ext == "scp") { // pretty isn't it? ;) |
||
84 | } else { |
||
85 | exit("Try uploading a diskimage type that is allowed, like stx or msa not $ext"); |
||
86 | } |
||
87 | } else { |
||
88 | if ($file_ext == "stx" || $file_ext == "msa" || |
||
89 | $file_ext == "st" || $file_ext == "scp") { // pretty isn't it? ;) |
||
90 | } else { |
||
91 | exit("Try uploading a diskimage type that is allowed $file_ext"); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | // create a timestamp for the date of upload |
||
96 | $timestamp = time(); |
||
97 | |||
98 | $stmt = \AL\Db\execute_query( |
||
99 | "DumpDAO: addDumptoMedia", |
||
100 | $this->mysqli, |
||
101 | "INSERT INTO dump (`media_id`, `format`, `info`, `date`, `size`, user_id ) VALUES (?, ?, ?, ?, ?, ?)", |
||
102 | "issiii", $media_id, $format, $info, $timestamp, $filesize, $_SESSION['user_id'] |
||
103 | ); |
||
104 | |||
105 | //get the new dump id |
||
106 | $new_dump_id = $this->mysqli->insert_id; |
||
107 | |||
108 | if ($file_ext == 'zip') { |
||
109 | // Time to unzip the file to the temporary directory |
||
110 | $archive = new \PclZip("$tempfilename"); |
||
111 | |||
112 | if ($archive->extract(PCLZIP_OPT_PATH, "$game_file_temp_path") == 0) { |
||
113 | die("Error : " . $archive->errorInfo(true)); |
||
114 | } |
||
115 | |||
116 | // rename diskimage to increment number |
||
117 | rename("$game_file_temp_path$filename", "$game_file_temp_path$new_dump_id.$ext") |
||
118 | or die("couldn't rename the file"); |
||
119 | } else { |
||
120 | $file_data = rename("$tempfilename", "$game_file_temp_path$new_dump_id.$file_ext"); |
||
121 | } |
||
122 | |||
123 | //Time to rezip file and place it in the proper location. |
||
124 | $archive = new \PclZip("$game_file_path$new_dump_id.zip"); |
||
125 | if ($file_ext == 'zip') { |
||
126 | $v_list = $archive->create("$game_file_temp_path$new_dump_id.$ext", PCLZIP_OPT_REMOVE_ALL_PATH); |
||
127 | } else { |
||
128 | $v_list = $archive->create("$game_file_temp_path$new_dump_id.$file_ext", PCLZIP_OPT_REMOVE_ALL_PATH); |
||
129 | } |
||
130 | if ($v_list == 0) { |
||
131 | die("Error : " . $archive->errorInfo(true)); |
||
132 | } |
||
133 | |||
134 | // Time to do the safeties, here we do a sha512 file hash that we later enter into |
||
135 | // the database, this will be used in the download function to check everytime the file |
||
136 | // is being downloaded... if the hashes don't match, then datacorruption have changed the file. |
||
137 | $crc = openssl_digest("$game_file_path$new_dump_id.zip", 'sha512'); |
||
138 | |||
139 | $stmt = \AL\Db\execute_query( |
||
140 | "DumpDAO: addDumptoMedia", |
||
141 | $this->mysqli, |
||
142 | "UPDATE dump SET sha512 = ? WHERE id = ?", |
||
143 | "si", $crc, $new_dump_id |
||
144 | ); |
||
145 | |||
146 | // Chmod file so that we can backup/delete files through ftp. |
||
147 | chmod("$game_file_path$new_dump_id.zip", 0777); |
||
148 | |||
149 | // Delete the unzipped file in the temporary directory |
||
150 | if ($file_ext == 'zip') { |
||
151 | unlink("$game_file_temp_path$new_dump_id.$ext"); |
||
152 | } else { |
||
153 | unlink("$game_file_temp_path$new_dump_id.$file_ext"); |
||
154 | } |
||
155 | $stmt->close(); |
||
156 | } |
||
210 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths