| Conditions | 1 |
| Paths | 1 |
| Total Lines | 81 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 38 | public function execute() { |
||
| 39 | global $wpdb; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Requirements. |
||
| 43 | */ |
||
| 44 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Other. |
||
| 48 | */ |
||
| 49 | $charset_collate = $wpdb->get_charset_collate(); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Queries. |
||
| 53 | */ |
||
| 54 | $queries = " |
||
| 55 | CREATE TABLE $wpdb->pronamic_pay_mollie_organisations ( |
||
| 56 | id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 57 | mollie_id VARCHAR( 16 ) NOT NULL, |
||
| 58 | |||
| 59 | PRIMARY KEY ( id ), |
||
| 60 | UNIQUE KEY mollie_id ( mollie_id ) |
||
| 61 | ) $charset_collate; |
||
| 62 | |||
| 63 | CREATE TABLE $wpdb->pronamic_pay_mollie_customers ( |
||
| 64 | id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 65 | mollie_id VARCHAR( 16 ) NOT NULL, |
||
| 66 | organisation_id BIGINT( 20 ) NOT NULL, |
||
| 67 | test_mode BOOL NOT NULL, |
||
| 68 | email VARCHAR( 100 ) DEFAULT NULL, |
||
| 69 | |||
| 70 | PRIMARY KEY ( id ), |
||
| 71 | UNIQUE KEY mollie_id ( mollie_id ), |
||
| 72 | KEY organisation_id ( organisation_id ), |
||
| 73 | KEY test_mode ( test_mode ), |
||
| 74 | KEY email ( email ) |
||
| 75 | ) $charset_collate; |
||
| 76 | |||
| 77 | CREATE TABLE $wpdb->pronamic_pay_mollie_customer_users ( |
||
| 78 | id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 79 | customer_id BIGINT( 20 ) UNSIGNED NOT NULL, |
||
| 80 | user_id BIGINT( 20 ) UNSIGNED NOT NULL, |
||
| 81 | |||
| 82 | PRIMARY KEY ( id ), |
||
| 83 | UNIQUE KEY customer_user ( customer_id, user_id ) |
||
| 84 | ) $charset_collate; |
||
| 85 | "; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Execute. |
||
| 89 | */ |
||
| 90 | \dbDelta( $queries ); |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Foreign keys. |
||
| 94 | * |
||
| 95 | * @link https://core.trac.wordpress.org/ticket/19207 |
||
| 96 | */ |
||
| 97 | $wpdb->query( " |
||
| 98 | ALTER TABLE $wpdb->pronamic_pay_mollie_customers |
||
| 99 | ADD FOREIGN KEY ( organisation_id ) |
||
| 100 | REFERENCES $wpdb->pronamic_pay_mollie_organisations ( id ) |
||
| 101 | ON DELETE RESTRICT |
||
| 102 | ON UPDATE RESTRICT |
||
| 103 | ; |
||
| 104 | " ); |
||
| 105 | |||
| 106 | $wpdb->query( " |
||
| 107 | ALTER TABLE $wpdb->pronamic_pay_mollie_customer_users |
||
| 108 | ADD FOREIGN KEY ( customer_id ) |
||
| 109 | REFERENCES $wpdb->pronamic_pay_mollie_customers ( id ) |
||
| 110 | ON DELETE RESTRICT |
||
| 111 | ON UPDATE RESTRICT |
||
| 112 | ; |
||
| 113 | " ); |
||
| 114 | |||
| 115 | $wpdb->query( " |
||
| 116 | ALTER TABLE $wpdb->pronamic_pay_mollie_customer_users |
||
| 117 | ADD FOREIGN KEY ( user_id ) |
||
| 118 | REFERENCES $wpdb->users ( id ) |
||
| 119 | ON DELETE RESTRICT |
||
| 125 |