Completed
Push — master ( 869a2b...d02afe )
by Zack
11:33 queued 03:17
created

Field_Value_Context   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C __set() 0 23 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
	 * @return void
31
	 */
32 1
	public function __set( $key, $value ) {
33
		switch ( $key ):
34 1
			case 'view':
35 1
				if ( ! $value instanceof \GV\View ) {
36 1
					gravityview()->log->error( '\GV\Field_Value_Context::$view has to be of type \GV\View' );
37 1
					return;
38
				}
39
				break;
40 1
			case 'form':
41 1
				if ( ! $value instanceof \GV\Form ) {
42 1
					gravityview()->log->error( '\GV\Field_Value_Context::$form has to be of type \GV\Form' );
43 1
					return;
44
				}
45
				break;
46 1
			case 'entry':
47 1
				if ( ! $value instanceof \GV\Entry ) {
48 1
					gravityview()->log->error( '\GV\Field_Value_Context::$entry has to be of type \GV\Entry' );
49 1
					return;
50
				}
51
				break;
52
		endswitch;
53 1
		parent::__set( $key, $value );
54 1
	}
55
}
56