Completed
Push — master ( ac85d3...3c4aa1 )
by Kenji
11s
created

CIPHPUnitTestUnitTestCase::newLibrary()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 4
Ratio 28.57 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 4
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of ci-phpunit-test
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/ci-phpunit-test
9
 */
10
11
class CIPHPUnitTestUnitTestCase extends CIPHPUnitTestCase
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...
12
{
13
	/**
14
	 * Create a controller instance
15
	 *
16
	 * @param string $classname
17
	 * @return CI_Controller
18
	 */
19
	public function newController($classname)
20
	{
21
		reset_instance();
22
		$controller = new $classname;
23
		$this->CI =& get_instance();
24
		return $controller;
25
	}
26
27
	/**
28
	 * Create a model instance
29
	 *
30
	 * @param string $classname
31
	 * @return CI_Model
32
	 */
33
	public function newModel($classname)
34
	{
35
		$this->resetInstance();
36
		$this->CI->load->model($classname);
37
38
		// Is the model in a sub-folder?
39 View Code Duplication
		if (($last_slash = strrpos($classname, '/')) !== FALSE)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
		{
41
			$classname = substr($classname, ++$last_slash);
42
		}
43
44
		return $this->CI->$classname;
45
	}
46
47
	/**
48
	 * Create a library instance
49
	 *
50
	 * @param string $classname
51
	 * @param array  $args
52
	 * @return object
53
	 */
54
	public function newLibrary($classname, $args = null)
55
	{
56
		$this->resetInstance();
57
		$this->CI->load->library($classname, $args);
58
59
		// Is the library in a sub-folder?
60 View Code Duplication
		if (($last_slash = strrpos($classname, '/')) !== FALSE)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
		{
62
			$classname = substr($classname, ++$last_slash);
63
		}
64
		$classname = strtolower($classname);
65
66
		return $this->CI->$classname;
67
	}
68
}
69