Completed
Branch AUTOMATED_TESTING (09d9f2)
by Gordon
13:24
created

MapField   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 21 8
A Field() 0 16 1
1
<?php
2
/**
3
 * Map field to point for pois langitude and longitude positioning
4
 */
5
class MapField extends DatalessField {
6
7
		/**
8
		 * @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
9
		 */
10
		protected $headingLevel = 2;
11
		private $divId;
12
13
		function __construct($name, $title = null, $headingLevel = 2, $allowHTML = false, $form = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
			$this->divId = $name;
15
				// legacy handling for old parameters: $title, $heading, ...
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% 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...
16
				// instead of new handling: $name, $title, $heading, ...
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
17
				$args = func_get_args();
18
				if(!isset($args[1]) || is_numeric($args[1])) {
19
						$title = (isset($args[0])) ? $args[0] : null;
20
						// Use "HeaderField(title)" as the default field name for a HeaderField;
21
						// if it's just set to title then we risk causing accidental duplicate-field creation.
22
23
						// this means i18nized fields won't be easily accessible through fieldByName()
24
						$name = 'MapField' . $title;
25
						$headingLevel = (isset($args[1])) ? $args[1] : null;
26
						$allowHTML = (isset($args[2])) ? $args[2] : null;
27
						$form = (isset($args[3])) ? $args[3] : null;
28
				}
29
30
				if($headingLevel) $this->headingLevel = $headingLevel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $headingLevel can also be of type double or string. However, the property $headingLevel is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
31
				$this->allowHTML = $allowHTML;
32
				parent::__construct($name, $title, null, $allowHTML, $form);
0 ignored issues
show
Unused Code introduced by
The call to DatalessField::__construct() has too many arguments starting with $allowHTML.

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...
33
		}
34
35
		function Field($properties = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
				Requirements::javascript('framework/thirdparty/jquery/jquery.js');
37
				Requirements::javascript('framework/thirdparty/jquery-livequery/jquery.livequery.js');
38
				$attributes = array(
39
						'class' => 'middleColumn',
40
						'id' => $this->divId,
41
						'style' => "width:100%;height:300px;margin:5px 0px 5px 5px;position:relative;"
42
				);
43
44
				Requirements::css('mappable/css/mapField.css');
45
46
				return '<div class="editableMap">' . $this->createTag(
0 ignored issues
show
Deprecated Code introduced by
The method FormField::createTag() has been deprecated with message: 4.0 Use FormField::create_tag()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
47
						"div",
48
						$attributes
49
				) . '</div>';
50
		}
51
}
52