Test Failed
Pull Request — master (#3324)
by Devin
07:59
created

Give_Readme_Parser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A requires_at_least() 0 12 3
1
<?php
2
/**
3
 * Give Readme Parser
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Readme_Parser
7
 * @copyright   Copyright (c) 2018, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       2.1.4
10
 */
11
class Give_Readme_Parser{
0 ignored issues
show
Coding Style introduced by
Class name "" is not in camel caps format
Loading history...
12
	/**
13
	 * Readme file url
14
	 *
15
	 * @since  2.1.4
16
	 * @access private
17
	 * @var
18
	 */
19
	private $file_url;
20
21
	/**
22
	 * Readme file content
23
	 *
24
	 * @since  2.1.4
25
	 * @access private
26
	 * @var
27
	 */
28
	private $file_content;
29
30
	/**
31
	 * Give_Readme_Parser constructor.
32
	 *
33
	 * @param string $file_url
34
	 */
35
	function __construct( $file_url ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
		$this->file_url     = $file_url;
37
		$this->file_content = wp_remote_retrieve_body( wp_remote_get( $this->file_url ) );
0 ignored issues
show
introduced by
wp_remote_get is highly discouraged, please use vip_safe_wp_remote_get() instead.
Loading history...
38
	}
39
40
	/**
41
	 * Get required Give core minimum version for addon
42
	 *
43
	 * @since 2.1.4
44
	 * @access public
45
	 *
46
	 * @return string
47
	 */
48
	public function requires_at_least() {
49
		// Regex to extract Give core minimum version from the readme.txt file.
50
		preg_match('|Requires Give:(.*)|i', $this->file_content, $_requires_at_least );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
51
52
		if( is_array( $_requires_at_least ) && 1 < count( $_requires_at_least ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
53
			$_requires_at_least = trim( $_requires_at_least[1] );
54
		}else{
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
55
			$_requires_at_least = null;
56
		}
57
58
		return $_requires_at_least;
59
	}
60
}
61