Completed
Push — master ( ab4944...534e9c )
by Andrew
02:30
created

ClassyScope   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 87
rs 10
wmc 8
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_scope() 0 16 2
A extend_scope() 0 7 1
A get_common_scope() 0 11 2
A require_scope() 0 21 3
1
<?php 
2
3
/**
4
 * Template Scope
5
 *
6
 * Loads the scope (content) for requested template
7
 */
8
class ClassyScope {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
	protected static $common = null;
11
12
	/**
13
	 * Returns basic scope
14
	 * 
15
	 * @return array
16
	 */
17
	public static function get_scope($template_name = null) {
18
19
		global $paged;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
20
21
		$scope = self::require_scope('common');
22
23
		if ($template_name) {
24
25
			$scope = self::extend_scope($scope, $template_name);
26
			
27
		}
28
29
30
		return $scope;
31
32
	}
33
34
35
	/**
36
	 * Extends Scope with scope that is defined in theme_name/scope folder
37
	 * 
38
	 * @return array
39
	 */
40
	public static function extend_scope($scope, $template_name) {
41
42
		$scope = array_merge($scope, self::require_scope($template_name));
43
		
44
		return $scope;
45
46
	}
47
48
49
	/**
50
	 * Returns Common Scope
51
	 * 
52
	 * @return array
53
	 */
54
	public static function get_common_scope() {
55
		
56
		if ( null === self::$common ) {
57
58
			self::$common = self::require_scope('common');
59
60
		}
61
62
		return self::$common;
63
64
	}
65
66
	/**
67
	 * Requires file's scope
68
	 * 
69
	 * @param  string $filename
70
	 * @return array
71
	 */
72
	public static function require_scope($filename) {
73
74
		$return = array();
75
76
		$file = THEME_PATH . 'scope/' . $filename . '.php';
77
78
		if ( file_exists($file) ) {
79
80
			require $file;
81
			
82
		}
83
84
		if ( isset($data) ) {
0 ignored issues
show
Bug introduced by
The variable $data seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
85
			
86
			$return = $data;
87
88
		}
89
90
		return $return;
91
92
	}
93
94
}