Completed
Push — update/show-recurring-payments... ( 106a5e...b030b6 )
by
unknown
415:44 queued 407:29
created

Version_Selector::is_version_update_required()   B

Complexity

Conditions 8
Paths 12

Size

Total Lines 25

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 8
nc 12
nop 2
dl 25
loc 25
rs 8.4444
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file was automatically generated by automattic/jetpack-autoloader.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
namespace Automattic\Jetpack\Autoloader\jp02f167abb8e9ed34472e5bd963af3d06;
9
10
 // phpcs:ignore
11
12
/**
13
 * Used to select package versions.
14
 */
15 View Code Duplication
class Version_Selector {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
17
	/**
18
	 * Checks whether the selected package version should be updated. Composer development
19
	 * package versions ('9999999-dev' or versions that start with 'dev-') are favored
20
	 * when the JETPACK_AUTOLOAD_DEV constant is set to true.
21
	 *
22
	 * @param String $selected_version The currently selected package version.
23
	 * @param String $compare_version The package version that is being evaluated to
24
	 *                                determine if the version needs to be updated.
25
	 *
26
	 * @return Boolean Returns true if the selected package version should be updated,
27
	 *                 else false.
28
	 */
29
	public function is_version_update_required( $selected_version, $compare_version ) {
30
		$use_dev_versions = defined( 'JETPACK_AUTOLOAD_DEV' ) && JETPACK_AUTOLOAD_DEV;
31
32
		if ( is_null( $selected_version ) ) {
33
			return true;
34
		}
35
36
		if ( $use_dev_versions && $this->is_package_version_dev( $selected_version ) ) {
37
			return false;
38
		}
39
40
		if ( $this->is_package_version_dev( $compare_version ) ) {
41
			if ( $use_dev_versions ) {
42
				return true;
43
			} else {
44
				return false;
45
			}
46
		}
47
48
		if ( version_compare( $selected_version, $compare_version, '<' ) ) {
49
			return true;
50
		}
51
52
		return false;
53
	}
54
55
	/**
56
	 * Checks whether the given package version is a development version.
57
	 *
58
	 * @param String $version The package version.
59
	 *
60
	 * @return Boolean True if the version is a dev version, else false.
61
	 */
62
	private function is_package_version_dev( $version ) {
63
		if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) {
64
			return true;
65
		}
66
67
		return false;
68
	}
69
}
70