Passed
Push — master ( 211fe0...c1039b )
by Paul
03:43
created

Upgrader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 36
ccs 17
cts 20
cp 0.85
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateVersion() 0 8 3
A run() 0 11 2
A setReviewCounts__3_0_0() 0 4 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Controllers\AdminController;
6
use GeminiLabs\SiteReviews\Database\CountsManager;
7
use GeminiLabs\SiteReviews\Database\OptionManager;
8
use ReflectionClass;
9
use ReflectionMethod;
10
11
class Upgrader
12
{
13 7
	public function run()
14
	{
15 7
		$routines = (new ReflectionClass( __CLASS__ ))->getMethods( ReflectionMethod::IS_PROTECTED );
16 7
		$routines = array_column( $routines, 'name' );
17 7
		natsort( $routines );
18 7
		array_walk( $routines, function( $routine ) {
19 7
			$parts = explode( '__', $routine );
20 7
			if( version_compare( glsr()->version, end( $parts ), '<' ))return;
21
			call_user_func( [$this, $routine] );
22 7
		});
23 7
		$this->updateVersion();
24 7
	}
25
26
	/**
27
	 * @return void
28
	 */
29 7
	public function updateVersion()
30
	{
31 7
		$currentVersion = glsr( OptionManager::class )->get( 'version' );
32 7
		if( version_compare( $currentVersion, glsr()->version, '<' )) {
33 6
			glsr( OptionManager::class )->set( 'version', glsr()->version );
34
		}
35 7
		if( $currentVersion != glsr()->version ) {
36 6
			glsr( OptionManager::class )->set( 'version_upgraded_from', $currentVersion );
37
		}
38 7
	}
39
40
	/**
41
	 * @return void
42
	 */
43
	protected function setReviewCounts__3_0_0()
44
	{
45
		add_action( 'admin_init', function() {
46
			glsr( AdminController::class )->routerCountReviews();
47
		});
48
	}
49
}
50