GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1139)
by
unknown
12:39
created

attachment.php ➔ showForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 61
rs 9.5147

How to fix   Long Method   

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
 * Attachment migration script
4
 *
5
 * PHP Version 5.4
6
 *
7
 * This Source Code Form is subject to the terms of the Mozilla Public License,
8
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
 * obtain one at http://mozilla.org/MPL/2.0/.
10
 *
11
 * @category  phpMyFAQ
12
 * @package   Setup
13
 * @author    Anatoliy Belsky <[email protected]>
14
 * @copyright 2009-2014 phpMyFAQ Team
15
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16
 * @link      http://www.phpmyfaq.de
17
 * @since     2009-09-13
18
 */
19
20
set_time_limit(0);
21
22
define('PMF_ROOT_DIR', dirname(__DIR__));
23
define('IS_VALID_PHPMYFAQ', null);
24
25
//
26
// Check if config/database.php exist -> if not, redirect to installer
27
//
28 View Code Duplication
if (!file_exists(PMF_ROOT_DIR . '/config/database.php')) {
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...
29
    header("Location: ".str_replace('admin/index.php', '', $_SERVER['SCRIPT_NAME']).'setup/index.php');
30
    exit();
31
}
32
33
//
34
// Bootstrapping
35
//
36
require PMF_ROOT_DIR . '/inc/Bootstrap.php';
37
38
?>
39
<!DOCTYPE html>
40
<html lang="en">
41
<head>
42
    <title>phpMyFAQ Attachment Migration</title>
43
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
44
    <link rel="shortcut icon" href="../assets/template/default/favicon.ico" type="image/x-icon" />
45
    <link rel="icon" href="../assets/template/default/favicon.ico" type="image/x-icon" />
46
    <style media="screen" type="text/css">@import url(css/setup.css);</style>
47
</head>
48
<body>
49
<h1 id="header">phpMyFAQ Attachment Migration</h1>
50
<?php 
51
    $migrationType = PMF_Filter::filterInput(
52
        INPUT_POST,
53
        'migrationType',
54
        FILTER_SANITIZE_STRING
55
    );
56
    
57
    $migration = new PMF_Attachment_Migration($faqConfig);
58
    $options   = [];
59
    
60
    switch ($migrationType) {
61
        case PMF_Attachment_Migration::MIGRATION_TYPE1:
62
            //TODO implenemt this
63
            break;
64
            
65
        case PMF_Attachment_Migration::MIGRATION_TYPE2:
66
/*        case PMF_Attachment_Migration::MIGRATION_TYPE3:
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
67
        case PMF_Attachment_Migration::MIGRATION_TYPE4:*/
68
            $options['defaultKey'] = PMF_Filter::filterInput(INPUT_POST,
69
                                                             'defaultKey',
70
                                                             FILTER_SANITIZE_STRING);                                 
71
            break;
72
            
73
        default:
74
            echo '<h2 style="color: red;">BACKUP YOUR FILES BEFORE PROCEED!!!</h2>';
75
            showForm();
76
            break;
77
            
78
    }
79
    
80
    if (!empty($migrationType)) {
81
        if ($migration->doMigrate($migrationType, $options)) {
82
            print '<br><h2 style="color: green;">Success</h2>';
83
        } else {
84
            print '<span style="color: red">Errors:</span><br>' . implode('<br>', $migration->getErrors());
85
            showForm();
86
        }
87
        
88
        $warnings = $migration->getWarnings();
89
        if(!empty($warnings)) {
90
            echo '<span style="color: yellow">Warnings:</span><br>' . implode('<br>', $migration->getWarnings());
91
        }
92
    }
93
    
94
function showForm()
95
{
96
?>
97
<script>
98
/**
99
 * Show option fields corresponding to attachment type
100
 *
101
 * @param integer migrationType to show options for
102
 *
103
 * @return void
104
 */
105
function showOptions(migrationType)
106
{
107
    var html = ''
108
     
109
    switch(migrationType*1) {
110
        case <?php echo PMF_Attachment_Migration::MIGRATION_TYPE1 ?>:
111
            // nothing to do yet
112
            break;
113
114
        case <?php echo PMF_Attachment_Migration::MIGRATION_TYPE2 ?>:
115
/*        case <?php echo PMF_Attachment_Migration::MIGRATION_TYPE3 ?>:
116
        case <?php echo PMF_Attachment_Migration::MIGRATION_TYPE4 ?>:*/
117
            html = 'Default Key: <input name="defaultKey" maxlength="256">'
118
            break;
119
    }
120
121
    document.getElementById('optionFields').innerHTML = html
122
}
123
</script>
124
<form method="post">
125
    <table>
126
        <tr>
127
            <td>
128
                <select id="migrationType" name="migrationType"
129
                        onchange="showOptions(this.options[this.selectedIndex].value)">
130
                    <option value="<?php echo PMF_Attachment_Migration::MIGRATION_TYPE1 ?>">
131
                        2.5.x ==> 2.6+ files without encryption
132
                    </option>
133
                    <option value="<?php echo PMF_Attachment_Migration::MIGRATION_TYPE2 ?>">
134
                        2.5.x ==> 2.6+ files with encryption
135
                    </option>
136
<!--                    <option value="<?php echo PMF_Attachment_Migration::MIGRATION_TYPE3 ?>">
137
                        2.6+ default encrypted files ==> unencrypted files
138
                    </option>
139
                    <option value="<?php echo PMF_Attachment_Migration::MIGRATION_TYPE4 ?>">
140
                        2.6+ unencrypted files ==> default encrypted files
141
                    </option>-->
142
                </select>
143
            </td>            
144
        </tr>
145
        <tr>
146
            <td id="optionFields">
147
            
148
            </td>
149
        </tr>
150
        <tr><td><input type="submit"></td></tr>
151
    </table>
152
</form>
153
<?php     
154
}   
155
    
156
?>
157
</body>
158
</html>