Completed
Branch dev (58959f)
by
unknown
02:54
created

WPUpdatePhp   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 49
rs 10
wmc 8
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A does_it_meet_required_php_version() 0 8 2
A is_minimum_php_version() 0 3 1
A load_minimum_required_version_notice() 0 5 3
A admin_notice() 0 5 1
1
<?php
2
class WPUpdatePhp {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
	/** @var String */
4
	private $minimum_version;
5
6
	/**
7
	 * @param $minimum_version
8
	 */
9
	public function __construct($minimum_version) {
10
		$this->minimum_version = $minimum_version;
11
	}
12
13
	/**
14
	 * @param $version
15
	 *
16
	 * @return bool
17
	 */
18
	public function does_it_meet_required_php_version($version) {
19
		if ($this->is_minimum_php_version($version)) {
20
			return true;
21
		}
22
23
		$this->load_minimum_required_version_notice();
24
		return false;
25
	}
26
27
	/**
28
	 * @param $version
29
	 *
30
	 * @return boolean
31
	 */
32
	private function is_minimum_php_version($version) {
33
		return version_compare($this->minimum_version, $version, '<=');
34
	}
35
36
	/**
37
	 * @return void
38
	 */
39
	private function load_minimum_required_version_notice() {
40
		if (is_admin() && ! defined('DOING_AJAX')) {
41
			add_action('admin_notices', array($this, 'admin_notice'));
42
		}
43
	}
44
45
	public function admin_notice() {
46
		echo '<div class="error">';
47
		echo '<p>'.sprintf(__('Unfortunately, <strong>%s</strong> can not run on PHP versions older than '.$this->minimum_version.'. Read more information about <a href="http://www.wpupdatephp.com/update/" target="_blank">how you can update</a>'), 'Auto Load Next Post').'.</p>';
48
		echo '</div>';
49
	}
50
}
51