Completed
Push — milestone/2_0/container-condit... ( 3aa2e2...d923a5 )
by
unknown
04:55
created

Translator::fulfillable_to_foreign()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Container\Fulfillable\Translator;
4
5
use Carbon_Fields\Container\Fulfillable\Fulfillable;
6
use Carbon_Fields\Container\Fulfillable\Fulfillable_Collection;
7
use Carbon_Fields\Container\Condition\Condition;
8
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
9
10
abstract class Translator {
11
12
	/**
13
	 * Translate a Fulfillable to foreign data
14
	 * 
15
	 * @param  Fulfillable $fulfillable
16
	 * @return mixed
17
	 */
18
	public function fulfillable_to_foreign( Fulfillable $fulfillable ) {
19
		if ( is_a( $fulfillable, 'Carbon_Fields\\Container\\Condition\\Condition' ) ) {
20
			return $this->condition_to_foreign( $fulfillable );
1 ignored issue
show
Compatibility introduced by
$fulfillable of type object<Carbon_Fields\Con...ulfillable\Fulfillable> is not a sub-type of object<Carbon_Fields\Con...er\Condition\Condition>. It seems like you assume a concrete implementation of the interface Carbon_Fields\Container\Fulfillable\Fulfillable to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
21
		}
22
23
		if ( is_a( $fulfillable, 'Carbon_Fields\\Container\\Fulfillable\\Fulfillable_Collection' ) ) {
24
			return $this->fulfillable_collection_to_foreign( $fulfillable );
1 ignored issue
show
Compatibility introduced by
$fulfillable of type object<Carbon_Fields\Con...ulfillable\Fulfillable> is not a sub-type of object<Carbon_Fields\Con...Fulfillable_Collection>. It seems like you assume a concrete implementation of the interface Carbon_Fields\Container\Fulfillable\Fulfillable to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
25
		}
26
27
		Incorrect_Syntax_Exception::raise( 'Attempted to translate an unsupported object: ' . print_r( $fulfillable, true ) );
1 ignored issue
show
introduced by
The use of function print_r() is discouraged
Loading history...
28
	}
29
30
	/**
31
	 * Translate a Condition to foreign data
32
	 * 
33
	 * @param  Condition $condition
34
	 * @return mixed
35
	 */
36
	abstract protected function condition_to_foreign( Condition $condition );
37
38
	/**
39
	 * Translate a Fulfillable_Collection to foreign data
40
	 * 
41
	 * @param  Fulfillable_Collection $fulfillable_collection
42
	 * @return mixed
43
	 */
44
	abstract protected function fulfillable_collection_to_foreign( Fulfillable_Collection $fulfillable_collection );
45
46
	/**
47
	 * Translate foreign data to a Fulfillable
48
	 * 
49
	 * @param  mixed       $foreign
50
	 * @return Fulfillable
51
	 */
52
	abstract public function foreign_to_fulfillable( $foreign );
53
}
54