Passed
Push — master ( ceec33...d1be46 )
by Paul
05:18
created

Upgrader::updateVersion()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Application;
6
use GeminiLabs\SiteReviews\Database\OptionManager;
7
use ReflectionClass;
8
use ReflectionMethod;
9
10
class Upgrader
11
{
12 7
	public function run()
13
	{
14 7
		$routines = (new ReflectionClass( __CLASS__ ))->getMethods( ReflectionMethod::IS_PROTECTED );
15 7
		$routines = array_column( $routines, 'name' );
16 7
		natsort( $routines );
17 7
		array_walk( $routines, function( $routine ) {
18 7
			$version = str_replace( strtolower( __CLASS__ ).'_', '', $routine );
19 7
			if( version_compare( glsr()->version, $version, '>=' ))return;
20
			call_user_func( [$this, $routine] );
21 7
		});
22 7
		$this->updateVersion();
23 7
	}
24
25
	/**
26
	 * @return void
27
	 */
28 7
	public function updateVersion()
29
	{
30 7
		$currentVersion = glsr( OptionManager::class )->get( 'version' );
31 7
		if( version_compare( $currentVersion, glsr()->version, '<' )) {
32 7
			glsr( OptionManager::class )->set( 'version', glsr()->version );
33
		}
34 7
		if( $currentVersion != glsr()->version ) {
35 7
			glsr( OptionManager::class )->set( 'version_upgraded_from', $currentVersion );
36
		}
37 7
	}
38
39
	protected function upgrade_3_0_0()
40
	{}
41
}
42