Completed
Push — master ( af77e8...7d9d07 )
by Zack
11s
created

Field_Value_Context   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 12
cts 15
cp 0.8
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __set() 0 20 7
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The \GV\Field_Value_Context class.
11
 *
12
 * Houses context for \GV\Field::get_value() calls, which
13
 *  helps the field retrieve the value for itself.
14
 */
15
class Field_Value_Context extends Context {
16
	/**
17
	 * @var string The context identifier, used in filters.
18
	 */
19
	private $_identifier = 'field_value';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $_identifier is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
21
	/**
22
	 * Set a key to a value.
23
	 *
24
	 * @param mixed $key The key the value should be added under.
25
	 * @param mixed $value The value to be added to the key.
26
	 *
27
	 * @api
28
	 * @since future
29
	 *
30
	 * @throws \InvalidArgumentException If key type conditions are not met.
31
	 *
32
	 * @return void
33
	 */
34 1
	public function __set( $key, $value ) {
35
		switch ( $key ):
36 1
			case 'view':
37 1
				if ( ! $value instanceof \GV\View ) {
38 1
					throw new \InvalidArgumentException( '\GV\Field_Value_Context::$view has to be of type \GV\View' );
39
				}
40
				break;
41 1
			case 'form':
42 1
				if ( ! $value instanceof \GV\Form ) {
43 1
					throw new \InvalidArgumentException( '\GV\Field_Value_Context::$form has to be of type \GV\Form' );
44
				}
45
				break;
46 1
			case 'entry':
47 1
				if ( ! $value instanceof \GV\Entry ) {
48 1
					throw new \InvalidArgumentException( '\GV\Field_Value_Context::$entry has to be of type \GV\Entry' );
49
				}
50
				break;
51
		endswitch;
52 1
		parent::__set( $key, $value );
53 1
	}
54
}
55