Stencil_Installables   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 107
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A add_installable() 0 3 1
A get_by_slug() 0 9 3
A get_plugins() 0 3 1
A get_themes() 0 3 1
A get_upgradable() 0 11 3
A get_installable_filtered() 0 11 3
1
<?php
2
/**
3
 * Stencil Installable package
4
 *
5
 * @package Stencil
6
 * @subpackage Upgrader
7
 */
8
9
/**
10
 * Class Stencil_Installable
11
 */
12
class Stencil_Installables {
13
14
	/**
15
	 * List of registered installables.
16
	 *
17
	 * @var array
18
	 */
19
	private $installables = array();
20
21
	/**
22
	 * Register all installable items.
23
	 */
24
	public function __construct() {
25
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil', 'Stencil' ) );
26
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-dwoo2', 'Dwoo 2', '5.4.0' ) );
27
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-mustache', 'Mustache' ) );
28
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-savant3', 'Savant 3' ) );
29
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-smarty2', 'Smarty 2.x' ) );
30
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-smarty3', 'Smarty 3.x' ) );
31
		$this->add_installable( new Stencil_Installable_Plugin( 'stencil-twig', 'Twig' ) );
32
33
		$this->add_installable( new Stencil_Installable_Theme( 'dwoo2', 'Dwoo' ) );
34
		$this->add_installable( new Stencil_Installable_Theme( 'mustache', 'Mustache' ) );
35
		$this->add_installable( new Stencil_Installable_Theme( 'smarty', 'Smarty' ) );
36
		$this->add_installable( new Stencil_Installable_Theme( 'twig', 'Twig' ) );
37
	}
38
39
	/**
40
	 * Add an installable to the list.
41
	 *
42
	 * @param Stencil_Installable_Interface $installable Installable to add.
43
	 */
44
	public function add_installable( Stencil_Installable_Interface $installable ) {
45
		$this->installables[] = $installable;
46
	}
47
48
	/**
49
	 * Get Installable by slug.
50
	 *
51
	 * @param string $slug Slug to find.
52
	 *
53
	 * @return mixed|null
54
	 */
55
	public function get_by_slug( $slug ) {
56
		foreach ( $this->installables as $installable ) {
57
			if ( $installable->get_slug() === $slug ) {
58
				return $installable;
59
			}
60
		}
61
62
		return null;
63
	}
64
65
	/**
66
	 * Retrieve all plugins
67
	 *
68
	 * @return Iterator list of Plugins.
69
	 */
70
	public function get_plugins() {
71
		return $this->get_installable_filtered( 'Stencil_Installable_Plugin' );
72
	}
73
74
	/**
75
	 * Get all registered themes.
76
	 *
77
	 * @return Iterator list of Themes.
78
	 */
79
	public function get_themes() {
80
		return $this->get_installable_filtered( 'Stencil_Installable_Theme' );
81
	}
82
83
	/**
84
	 * Get upgradable installables
85
	 *
86
	 * @return array of upgradable installables.
87
	 */
88
	public function get_upgradable() {
89
		$output = array();
90
91
		foreach ( $this->installables as $installable ) {
92
			if ( $installable->has_upgrade() ) {
93
				$output[] = $installable;
94
			}
95
		}
96
97
		return $output;
98
	}
99
100
	/**
101
	 * Get specific installables.
102
	 *
103
	 * @param string $class Class to get objects of.
104
	 *
105
	 * @return array
106
	 */
107
	private function get_installable_filtered( $class ) {
108
109
		$output = array();
110
		foreach ( $this->installables as $installable ) {
111
			if ( is_a( $installable, $class ) ) {
112
				$output[] = $installable;
113
			}
114
		}
115
116
		return $output;
117
	}
118
}
119