Stencil_Cached_Subclass_Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create_or_null() 0 13 3
1
<?php
2
/**
3
 * Cache layer for the subclass factory
4
 *
5
 * @package Stencil
6
 */
7
8
/**
9
 * Class CachedSubclassFactory
10
 */
11
class Stencil_Cached_Subclass_Factory extends Stencil_Subclass_Factory {
12
	/**
13
	 * Return cached object if exists
14
	 *
15
	 * @param string $page The name of the page.
16
	 * @param string $prefix Prefix to use in class structure.
17
	 *
18
	 * @return mixed
19
	 */
20
	public static function create_or_null( $page, $prefix ) {
21
		static $cache = array();
22
23
		if ( ! isset( $cache[ $prefix ] ) ) {
24
			$cache[ $prefix ] = array();
25
		}
26
27
		if ( ! isset( $cache[ $prefix ][ $page ] ) ) {
28
			$cache[ $prefix ][ $page ] = parent::create_or_null( $page, $prefix );
29
		}
30
31
		return $cache[ $prefix ][ $page ];
32
	}
33
}
34