| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 13 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 39 | public function execute() { |
||
| 40 | global $wpdb; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Requirements. |
||
| 44 | */ |
||
| 45 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Table options. |
||
| 49 | * |
||
| 50 | * In MySQL 5.6, InnoDB is the default MySQL storage engine. Unless you |
||
| 51 | * have configured a different default storage engine, issuing a |
||
| 52 | * CREATE TABLE statement without an ENGINE= clause creates an InnoDB |
||
| 53 | * table. |
||
| 54 | * |
||
| 55 | * @link https://dev.mysql.com/doc/refman/5.6/en/innodb-introduction.html |
||
| 56 | * |
||
| 57 | * If a storage engine is specified that is not available, MySQL uses |
||
| 58 | * the default engine instead. Normally, this is MyISAM. For example, |
||
| 59 | * if a table definition includes the ENGINE=INNODB option but the MySQL |
||
| 60 | * server does not support INNODB tables, the table is created as a |
||
| 61 | * MyISAM table. |
||
| 62 | * |
||
| 63 | * @link https://dev.mysql.com/doc/refman/5.6/en/create-table.html |
||
| 64 | */ |
||
| 65 | $table_options = 'ENGINE=InnoDB ' . $wpdb->get_charset_collate(); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Queries. |
||
| 69 | * |
||
| 70 | * @link https://github.com/WordPress/WordPress/blob/5.3/wp-admin/includes/schema.php |
||
| 71 | */ |
||
| 72 | $queries = " |
||
| 73 | CREATE TABLE $wpdb->pronamic_pay_mollie_organizations ( |
||
| 74 | id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
||
| 75 | mollie_id varchar(16) NOT NULL, |
||
| 76 | name varchar(128) DEFAULT NULL, |
||
| 77 | email varchar(100) DEFAULT NULL, |
||
| 78 | PRIMARY KEY ( id ), |
||
| 79 | UNIQUE KEY mollie_id ( mollie_id ) |
||
| 80 | ) $table_options; |
||
| 81 | CREATE TABLE $wpdb->pronamic_pay_mollie_profiles ( |
||
| 82 | id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
||
| 83 | mollie_id varchar(16) NOT NULL, |
||
| 84 | organization_id bigint(20) unsigned DEFAULT NULL, |
||
| 85 | name varchar(128) DEFAULT NULL, |
||
| 86 | email varchar(100) DEFAULT NULL, |
||
| 87 | api_key_test varchar(35) DEFAULT NULL, |
||
| 88 | api_key_live varchar(35) DEFAULT NULL, |
||
| 89 | PRIMARY KEY ( id ), |
||
| 90 | UNIQUE KEY mollie_id ( mollie_id ), |
||
| 91 | KEY organization_id ( organization_id ) |
||
| 92 | ) $table_options; |
||
| 93 | CREATE TABLE $wpdb->pronamic_pay_mollie_customers ( |
||
| 94 | id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
||
| 95 | mollie_id varchar(16) NOT NULL, |
||
| 96 | organization_id bigint(20) unsigned DEFAULT NULL, |
||
| 97 | profile_id bigint(20) unsigned DEFAULT NULL, |
||
| 98 | test_mode tinyint(1) NOT NULL, |
||
| 99 | email varchar(100) DEFAULT NULL, |
||
| 100 | name varchar(255) DEFAULT NULL, |
||
| 101 | PRIMARY KEY ( id ), |
||
| 102 | UNIQUE KEY mollie_id ( mollie_id ), |
||
| 103 | KEY organization_id ( organization_id ), |
||
| 104 | KEY profile_id ( profile_id ), |
||
| 105 | KEY test_mode ( test_mode ), |
||
| 106 | KEY email ( email ) |
||
| 107 | ) $table_options; |
||
| 108 | CREATE TABLE $wpdb->pronamic_pay_mollie_customer_users ( |
||
| 109 | id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
||
| 110 | customer_id bigint(20) unsigned NOT NULL, |
||
| 111 | user_id bigint(20) unsigned NOT NULL, |
||
| 112 | PRIMARY KEY ( id ), |
||
| 113 | UNIQUE KEY customer_user ( customer_id, user_id ) |
||
| 114 | ) $table_options; |
||
| 115 | "; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Execute. |
||
| 119 | * |
||
| 120 | * @link https://developer.wordpress.org/reference/functions/dbdelta/ |
||
| 121 | * @link https://github.com/WordPress/WordPress/blob/5.3/wp-admin/includes/upgrade.php#L2538-L2915 |
||
| 122 | */ |
||
| 123 | \dbDelta( $queries ); |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Add foreign keys. |
||
| 127 | */ |
||
| 128 | $this->add_foreign_keys(); |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Convert user meta. |
||
| 132 | */ |
||
| 133 | $this->convert_user_meta(); |
||
| 134 | } |
||
| 365 |