Completed
Branch BUG-10381-asset-loading (f91422)
by
unknown
170:16 queued 157:41
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 46 6
1
<?php
2
namespace EventEspresso\core;
3
4
use EventEspresso\core\libraries\iframe_display\Iframe;
5
6
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
	exit( 'No direct script access allowed' );
8
}
9
10
11
12
/**
13
 * Class Factory
14
 * creates instantiations of classes
15
 *
16
 * @package       Event Espresso
17
 * @subpackage    core
18
 * @author        Brent Christensen
19
 * @since         4.9.0
20
 */
21
class Factory {
22
23
	/**
24
	 * @param string $class_name
25
	 * @param array  $arguments
26
	 * @return mixed|null
27
	 * @throws \EE_Error
28
	 */
29
	public static function create( $class_name, $arguments = array() ) {
30
		if ( empty( $class_name ) ) {
31
			throw new \EE_Error(
32
				__( 'You must provide a class name in order to instantiate it.', 'event_espresso' )
33
			);
34
		}
35
		// if ( ! class_exists( $class_name ) ) {
36
		// 	throw new \EE_Error(
37
		// 		sprintf(
38
		// 			__( 'The "%1$s" class was not found. Please include the correct file or set an autoloader for it', 'event_espresso' ),
39
		// 			$class_name
40
		// 		)
41
		// 	);
42
		// }
43
		$object = null;
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
		switch ( $class_name ) {
45
46
			case 'EE_Request' :
47
				$object = new \EE_Request( $_GET, $_POST, $_COOKIE );
48
				break;
49
50
			case 'Iframe' :
51
				$title = isset( $arguments['title'] ) ? $arguments['title'] : null;
52
				$content = isset( $arguments['content'] ) ? $arguments['content'] : null;
53
				$object = new Iframe( $title, $content );
54
				break;
55
56
			default :
57
				$object = new $class_name( $arguments );
58
59
		}
60
61
		// if ( ! $object instanceof $class_name ) {
62
		// 	throw new \EE_Error(
63
		// 		sprintf(
64
		// 			__(
65
		// 				'An error occurred during class instantiation and the requested object could not be created. The result was: %1$s %2$s',
66
		// 				'event_espresso'
67
		// 			),
68
		// 			'<br />',
69
		// 			var_export( $object, true )
70
		// 		)
71
		// 	);
72
		// }
73
		return $object;
74
	}
75
76
}
77
// End of file Factory.php
78
// Location: /Factory.php