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.
Passed
Push — master ( 33ed65...dc0f35 )
by Christian
02:27
created

Migration::run_migrations_for_version()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
introduced by
Filenames should be all lowercase with hyphens as word separators. Expected migration.php, but found Migration.php.
Loading history...
introduced by
Class file names should be based on the class name with "class-" prepended. Expected class-migration.php, but found Migration.php.
Loading history...
2
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
3
 * @author    Podlove <[email protected]>
4
 * @copyright Copyright (c) 2014-2018, Podlove
5
 * @license   https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT
6
 * @package   Podlove\PodloveSubscribeButton
7
 */
8
9
/**
10
 * Version management for database migrations.
11
 *
12
 * Database changes require special care:
13
 * - the model has to be adjusted for users installing the plugin
14
 * - the current setup has to be migrated for current users
15
 *
16
 * These migrations are a way to handle current users. They do *not*
17
 * run on plugin activation.
18
 *
19
 * Pattern:
20
 *
21
 * - increment \PodloveSubscribeButton\DATABASE_VERSION constant by 1, e.g.
22
 * 		```php
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
23
 * 		define( __NAMESPACE__ . '\DATABASE_VERSION', 2 );
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
24
 * 		```
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
25
 *
26
 * - add a case in `\PodloveSubscribeButton\run_migrations_for_version`, e.g.
27
 * 		```php
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
28
 * 		function run_migrations_for_version( $version ) {
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
29
 *			global $wpdb;
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
30
 *			switch ( $version ) {
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
31
 *				case 2:
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
32
 *					$wbdb-> // run sql or whatever
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
33
 *					break;
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
34
 *			}
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
35
 *		}
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
36
 *		```
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
37
 *
38
 *		Feel free to move the migration code into a separate function if it's
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
39
 *		rather complex.
0 ignored issues
show
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
40
 *
41
 * - adjust the main model / setup process so new users installing the plugin
42
 *   will have these changes too
43
 *
44
 * - Test the migrations! :)
45
 */
46
47
namespace PodloveSubscribeButton;
48
use \PodloveSubscribeButton\Model;
49
50
define( __NAMESPACE__ . '\DATABASE_VERSION', 3 );
51
52
class Migration {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class Migration
Loading history...
53
54
	public static function eval_db() {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::eval_db" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function eval_db()
Loading history...
55
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Migration', 'maybe_run_database_migrations' ) );
56
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Migration', 'run_database_migrations' ), 5 );
57
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
58
59
	public static function maybe_run_database_migrations() {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::maybe_run_database_migrations" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function maybe_run_database_migrations()
Loading history...
60
		$database_version = get_option( 'podlove_subscribe_button_plugin_database_version' );
61
62
		if ( $database_version === false ) {
0 ignored issues
show
introduced by
Use Yoda Condition checks, you must.
Loading history...
63
			// plugin has just been installed or Plugin Version < 1.3
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
64
			update_option( 'podlove_subscribe_button_plugin_database_version', DATABASE_VERSION );
65
		}
66
67
	}
68
69
	public static function run_database_migrations() {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::run_database_migrations" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function run_database_migrations()
Loading history...
70
		if ( get_option( 'podlove_subscribe_button_plugin_database_version' ) >= DATABASE_VERSION ) {
71
			return;
72
		}
73
74
		if ( is_multisite() ) {
75
			set_time_limit( 0 ); // may take a while, depending on network size
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
76
			Helpers::for_every_podcast_blog( function() { self::migrate_for_current_blog(); });
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
Coding Style introduced by
Closing brace of nested function must be on a new line
Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
77
		} else {
78
			self::migrate_for_current_blog();
79
		}
80
81
		if ( isset( $_REQUEST[ '_wp_http_referer' ] ) && $_REQUEST[ '_wp_http_referer' ] ) {
0 ignored issues
show
introduced by
Processing form data without nonce verification.
Loading history...
introduced by
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
introduced by
Missing wp_unslash() before sanitization.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
82
			wp_redirect( $_REQUEST[ '_wp_http_referer' ] );
0 ignored issues
show
introduced by
wp_redirect() found. Using wp_safe_redirect(), along with the allowed_redirect_hosts filter if needed, can help avoid any chances of malicious redirects within code. It is also important to remember to call exit() after a redirect so that no other unwanted code is executed.
Loading history...
introduced by
Missing wp_unslash() before sanitization.
Loading history...
introduced by
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
83
			exit;
84
		}
85
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
86
87
	public static function migrate_for_current_blog() {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::migrate_for_current_blog" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function migrate_for_current_blog()
Loading history...
88
		$database_version = get_option( 'podlove_subscribe_button_plugin_database_version' );
89
90
		for ( $i = $database_version + 1; $i <= DATABASE_VERSION; $i++ ) {
91
			self::run_migrations_for_version( $i );
92
			update_option( 'podlove_subscribe_button_plugin_database_version', $i );
93
		}
94
95
	}
96
97
	/**
98
	 * Find and run migration for given version number.
99
	 *
100
	 * @todo  move migrations into separate files
101
	 *
102
	 * @param  int $version
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
103
	 */
104
	private static function run_migrations_for_version( $version ) {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::run_migrations_for_version" is not in camel caps format
Loading history...
105
		global $wpdb;
106
107
		switch ( $version ) {
108
			case 3:
109
				self::migration_case_3();
110
				break;
111
		}
112
113
	}
114
115
	private static function migration_case_3() {
0 ignored issues
show
Coding Style introduced by
Method name "Migration::migration_case_3" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function migration_case_3()
Loading history...
116
117
		/** @todo */
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
118
119
		// 1. multiple options -> 1 option as associative array
0 ignored issues
show
Coding Style introduced by
There should be no blank line after an inline comment.
Loading history...
120
121
		// 2. DB !?
0 ignored issues
show
Coding Style introduced by
There must be no blank line following an inline comment
Loading history...
122
123
	}
124
125
}
126