Completed
Branch dev (0b2b90)
by Eric
01:41
created

Bitsy_Wrapping::wrap()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Enable the theme wrapper.
4
 *
5
 * Thanks to:
6
 * Scribu http://scribu.net/wordpress/theme-wrappers.html
7
 * Ben Word and the team at roots.io
8
 * 
9
 * @package bitsy
10
 */
11
12
	function bitsy_template_path() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
13
		return Bitsy_Wrapping::$main_template;
14
	}
15
16
	function bitsy_template_base() {
17
		return Bitsy_Wrapping::$base;
18
	}
19
20
21
	class Bitsy_Wrapping {
0 ignored issues
show
Coding Style introduced by
The class Bitsy_Wrapping is not named in CamelCase.

This check marks class names that have not been written in CamelCase.

In CamelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database connector becomes DatabaseConnector.

Loading history...
Coding Style introduced by
The property $main_template is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
22
23
		/**
24
		 * Stores the full path to the main template file
25
		 */
26
		static $main_template;
27
28
		/**
29
		 * Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
30
		 */
31
		static $base;
32
33
		static function wrap( $template ) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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...
Coding Style Naming introduced by
The variable $main_template is not named in camelCase.

This check marks variable names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
34
			self::$main_template = $template;
35
36
			self::$base = substr( basename( self::$main_template ), 0, -4 );
37
38
			if ( 'index' == self::$base )
0 ignored issues
show
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
39
				self::$base = false;
40
41
			$templates = array( 'wrapper.php' );
42
43
			if ( self::$base )
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$base of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
44
				array_unshift( $templates, sprintf( 'wrapper-%s.php', self::$base ) );
45
46
			return locate_template( $templates );
47
		}
48
	}
49
50
	add_filter( 'template_include', array( 'Bitsy_Wrapping', 'wrap' ), 99 );