FakeCallbackContainer::addCallbackHandlers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace Onoi\CallbackContainer\Fixtures;
4
5
use Onoi\CallbackContainer\CallbackContainer;
6
use Onoi\CallbackContainer\ContainerBuilder;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class FakeCallbackContainer implements CallbackContainer {
15
16
	public function register( ContainerBuilder $containerBuilder ) {
17
		$this->addCallbackHandlers( $containerBuilder );
18
19
		return array(
20
			'service.one'   => array( $this, 'getServiceOne' ),
21
			'isNotCallable' => 'thereforeWontRegister'
22
		);
23
	}
24
25
	private function addCallbackHandlers( $containerBuilder ) {
26
27
		$containerBuilder->registerCallback( 'Foo', function( $containerBuilder ) {
0 ignored issues
show
Unused Code introduced by
The parameter $containerBuilder is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
			return new \stdClass;
29
		} );
30
31
		$containerBuilder->registerExpectedReturnType( 'Foo', '\stdClass' );
32
33
		$containerBuilder->registerCallback( 'FooWithArgument', function( $containerBuilder, $argument ) {
34
			$containerBuilder->registerExpectedReturnType( 'FooWithArgument', '\stdClass' );
35
36
			$stdClass = new \stdClass;
37
			$stdClass->argument = $argument;
38
39
			return $stdClass;
40
		} );
41
42
		$containerBuilder->registerCallback( 'FooWithNullArgument', array( $this, 'newFooWithNullArgument' ) );
43
	}
44
45
	public static function getServiceOne( $containerBuilder, $argument = null ) {
46
		return $containerBuilder->singleton( 'FooWithNullArgument', $argument );
47
	}
48
49
	public static function newFooWithNullArgument( $containerBuilder, $argument = null ) {
50
		$containerBuilder->registerExpectedReturnType( 'FooWithNullArgument', '\stdClass' );
51
52
		$stdClass = new \stdClass;
53
		$stdClass->argument = $argument;
54
		$stdClass->argumentWithArgument = $containerBuilder->create( 'FooWithArgument', $argument );
55
56
		return $stdClass;
57
	}
58
59
}
60