| Conditions | 5 |
| Paths | 6 |
| Total Lines | 84 |
| Code Lines | 29 |
| 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 |
||
| 41 | function execute() { |
||
| 42 | $this->dbw = $this->getDB( DB_MASTER ); |
||
| 43 | $logging = $this->dbw->tableName( 'logging' ); |
||
| 44 | $logging_1_10 = $this->dbw->tableName( 'logging_1_10' ); |
||
| 45 | $logging_pre_1_10 = $this->dbw->tableName( 'logging_pre_1_10' ); |
||
| 46 | |||
| 47 | if ( $this->dbw->tableExists( 'logging_pre_1_10' ) && !$this->dbw->tableExists( 'logging' ) ) { |
||
| 48 | # Fix previous aborted run |
||
| 49 | echo "Cleaning up from previous aborted run\n"; |
||
| 50 | $this->dbw->query( "RENAME TABLE $logging_pre_1_10 TO $logging", __METHOD__ ); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ( $this->dbw->tableExists( 'logging_pre_1_10' ) ) { |
||
| 54 | echo "This script has already been run to completion\n"; |
||
| 55 | |||
| 56 | return; |
||
| 57 | } |
||
| 58 | |||
| 59 | # Create the target table |
||
| 60 | if ( !$this->dbw->tableExists( 'logging_1_10' ) ) { |
||
| 61 | global $wgDBTableOptions; |
||
| 62 | |||
| 63 | $sql = <<<EOT |
||
| 64 | CREATE TABLE $logging_1_10 ( |
||
| 65 | -- Log ID, for referring to this specific log entry, probably for deletion and such. |
||
| 66 | log_id int unsigned NOT NULL auto_increment, |
||
| 67 | |||
| 68 | -- Symbolic keys for the general log type and the action type |
||
| 69 | -- within the log. The output format will be controlled by the |
||
| 70 | -- action field, but only the type controls categorization. |
||
| 71 | log_type varbinary(10) NOT NULL default '', |
||
| 72 | log_action varbinary(10) NOT NULL default '', |
||
| 73 | |||
| 74 | -- Timestamp. Duh. |
||
| 75 | log_timestamp binary(14) NOT NULL default '19700101000000', |
||
| 76 | |||
| 77 | -- The user who performed this action; key to user_id |
||
| 78 | log_user int unsigned NOT NULL default 0, |
||
| 79 | |||
| 80 | -- Key to the page affected. Where a user is the target, |
||
| 81 | -- this will point to the user page. |
||
| 82 | log_namespace int NOT NULL default 0, |
||
| 83 | log_title varchar(255) binary NOT NULL default '', |
||
| 84 | |||
| 85 | -- Freeform text. Interpreted as edit history comments. |
||
| 86 | log_comment varchar(255) NOT NULL default '', |
||
| 87 | |||
| 88 | -- LF separated list of miscellaneous parameters |
||
| 89 | log_params blob NOT NULL, |
||
| 90 | |||
| 91 | -- rev_deleted for logs |
||
| 92 | log_deleted tinyint unsigned NOT NULL default '0', |
||
| 93 | |||
| 94 | PRIMARY KEY log_id (log_id), |
||
| 95 | KEY type_time (log_type, log_timestamp), |
||
| 96 | KEY user_time (log_user, log_timestamp), |
||
| 97 | KEY page_time (log_namespace, log_title, log_timestamp), |
||
| 98 | KEY times (log_timestamp) |
||
| 99 | |||
| 100 | ) $wgDBTableOptions |
||
| 101 | EOT; |
||
| 102 | echo "Creating table logging_1_10\n"; |
||
| 103 | $this->dbw->query( $sql, __METHOD__ ); |
||
| 104 | } |
||
| 105 | |||
| 106 | # Synchronise the tables |
||
| 107 | echo "Doing initial sync...\n"; |
||
| 108 | $this->sync( 'logging', 'logging_1_10' ); |
||
| 109 | echo "Sync done\n\n"; |
||
| 110 | |||
| 111 | # Rename the old table away |
||
| 112 | echo "Renaming the old table to $logging_pre_1_10\n"; |
||
| 113 | $this->dbw->query( "RENAME TABLE $logging TO $logging_pre_1_10", __METHOD__ ); |
||
| 114 | |||
| 115 | # Copy remaining old rows |
||
| 116 | # Done before the new table is active so that $copyPos is accurate |
||
| 117 | echo "Doing final sync...\n"; |
||
| 118 | $this->sync( 'logging_pre_1_10', 'logging_1_10' ); |
||
| 119 | |||
| 120 | # Move the new table in |
||
| 121 | echo "Moving the new table in...\n"; |
||
| 122 | $this->dbw->query( "RENAME TABLE $logging_1_10 TO $logging", __METHOD__ ); |
||
| 123 | echo "Finished.\n"; |
||
| 124 | } |
||
| 125 | |||
| 218 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.