Conditions | 20 |
Paths | 16632 |
Total Lines | 60 |
Lines | 12 |
Ratio | 20 % |
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 |
||
63 | function xoops_module_update_smallworld(\XoopsModule $module) |
||
64 | { |
||
65 | $tables = new \Xmf\Database\Tables(); |
||
66 | |||
67 | $cTable = 'config'; |
||
68 | $criteria = new \Criteria('conf_name', 'smallworldprivorpub', '='); |
||
69 | if ($success = $tables->useTable($cTable)) { |
||
70 | $success = $tables->update($cTable, ['conf_value' => 1], $criteria); |
||
71 | } |
||
72 | |||
73 | $msgTable = 'smallworld_messages'; |
||
74 | $column = 'message'; |
||
75 | View Code Duplication | if ($successA = $tables->useTable($msgTable)) { // if this returns false, there is no table |
|
76 | $attributes = $tables->getColumnAttributes($msgTable, $column); |
||
77 | if (false === mb_strpos($attributes, ' TEXT')) { // assumes it's already been updated if TEXT found |
||
78 | $successA = $tables->alterColumn($msgTable, $column, ' TEXT '); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | $comTable = 'smallworld_comments'; |
||
83 | $column = 'comment'; |
||
84 | View Code Duplication | if ($successB = $tables->useTable($comTable)) { // if this returns false, there is no table |
|
85 | $attributes = $tables->getColumnAttributes($comTable, $column); |
||
86 | if (false === mb_strpos($attributes, ' TEXT')) { // assumes it's already been updated if 'TEXT' not found |
||
87 | $successB = $tables->alterColumn($comTable, $column, ' TEXT '); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | // now create smallworld_settings table if it doesn't exist |
||
92 | $sTable = 'smallworld_settings'; |
||
93 | if (false === ($successC = $tables->useTable($sTable))) { // if this returns true then the table exists already |
||
94 | // Table does not exist -> create |
||
95 | $successC = $tables->addTable($sTable); |
||
96 | $successC = $successC && ($tables->setTableOptions($sTable, 'ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1')); |
||
97 | $successC = $successC && ($tables->addColumn($sTable, 'id', 'INT(11) NOT NULL AUTO_INCREMENT')); |
||
98 | $successC = $successC && ($tables->addColumn($sTable, 'userid', 'INT(11) NOT NULL')); |
||
99 | $successC = $successC && ($tables->addColumn($sTable, 'value', 'TEXT')); |
||
100 | $successC = $successC && ($tables->addPrimaryKey($sTable, 'id')); |
||
101 | } |
||
102 | |||
103 | $successD = $tables->executeQueue(); // change the tables |
||
104 | |||
105 | // setup the criteria to update the avatar fields |
||
106 | $criteria = new \CriteriaCompo(); |
||
107 | $criteria->add(new \Criteria('userimage', 'blank.gif', '=')); |
||
108 | $criteria->add(new \Criteria('userimage', '\.(jpe?g|gif|png|bmp)', 'NOT REGEXP'), 'OR'); |
||
109 | |||
110 | // update the admin avatar |
||
111 | $aTable = 'smallworld_admin'; |
||
112 | if ($successE = $tables->useTable($aTable)) { |
||
113 | $successE = $tables->update($aTable, ['userimage' => ''], $criteria); |
||
114 | } |
||
115 | // update user table avatar |
||
116 | $uTable = 'smallworld_user'; |
||
117 | if ($successF = $tables->useTable($uTable)) { |
||
118 | $successF = $tables->update($uTable, ['userimage' => ''], $criteria); |
||
119 | } |
||
120 | |||
121 | return $success && $successA && $successB && $successC && $successD && $successE && $successF; |
||
122 | } |
||
123 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.