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

WPUpdatePhp::does_it_meet_required_php_version()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
cc 2
eloc 5
c 3
b 2
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
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