Completed
Push — develop ( fc0354...e2ac27 )
by Zack
11:27 queued 07:24
created

GravityView_Fields::create()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 8.8571
cc 5
eloc 9
nc 8
nop 1
1
<?php
2
3
class GravityView_Fields extends GF_Fields {
4
5
	/* @var GravityView_Field[] */
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6
	private static $_fields = array();
7
8
	public static function register( $field ) {
9
		if ( ! is_subclass_of( $field, 'GravityView_Field' ) ) {
10
			throw new Exception( 'Must be a subclass of GravityView_Field' );
11
		}
12
		if ( empty( $field->type ) ) {
13
			throw new Exception( 'The type must be set' );
14
		}
15
		if ( isset( self::$_fields[ $field->type ] ) ) {
16
			throw new Exception( 'Field type already registered: ' . $field->type );
17
		}
18
		self::$_fields[ $field->type ] = $field;
19
	}
20
21
	/**
22
	 * @param $properties
23
	 *
24
	 * @return GravityView_Field | bool
25
	 */
26
	public static function create( $properties ) {
27
		$type = isset($properties['type']) ? $properties['type'] : '';
28
		$type = empty( $properties['inputType'] ) ? $type : $properties['inputType'];
29
		if ( empty($type) || ! isset( self::$_fields[ $type ] ) ) {
30
			return new GravityView_Field( $properties );
0 ignored issues
show
Unused Code introduced by
The call to GravityView_Field::__construct() has too many arguments starting with $properties.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
31
		}
32
		$class      = self::$_fields[ $type ];
33
		$class_name = get_class( $class );
34
		$field      = new $class_name( $properties );
35
36
		return $field;
37
38
	}
39
}
40