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

Upgrader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
dl 0
loc 31
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 run() 0 11 2
A upgrade_3_0_0() 0 2 1
A updateVersion() 0 8 3
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