Completed
Branch master (098997)
by
unknown
28:44
created

DateTimeInputWidget   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 5
A getJavaScriptClassName() 0 3 1
A getConfig() 0 13 4
A getInputElement() 0 3 1
1
<?php
2
/**
3
 * MediaWiki Widgets – DateTimeInputWidget class.
4
 *
5
 * @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt
6
 * @license The MIT License (MIT); see LICENSE.txt
7
 */
8
namespace MediaWiki\Widget;
9
10
use OOUI\Tag;
11
12
/**
13
 * Date-time input widget.
14
 */
15
class DateTimeInputWidget extends \OOUI\InputWidget {
16
17
	protected $type = null;
18
	protected $min = null;
19
	protected $max = null;
20
	protected $clearable = null;
21
22
	/**
23
	 * @param array $config Configuration options
24
	 * @param string $config['type'] 'date', 'time', or 'datetime'
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['type']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
25
	 * @param string $config['min'] Minimum date, time, or datetime
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['min']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
26
	 * @param string $config['max'] Maximum date, time, or datetime
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['max']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
27
	 * @param bool $config['clearable'] Whether to provide for blanking the value.
0 ignored issues
show
Documentation introduced by
There is no parameter named $config['clearable']. Did you maybe mean $config?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
28
	 */
29
	public function __construct( array $config = [] ) {
30
		// We need $this->type set before calling the parent constructor
31
		if ( isset( $config['type'] ) ) {
32
			$this->type = $config['type'];
33
		} else {
34
			throw new \InvalidArgumentException( '$config[\'type\'] must be specified' );
35
		}
36
37
		// Parent constructor
38
		parent::__construct( $config );
39
40
		// Properties, which are ignored in PHP and just shipped back to JS
41
		if ( isset( $config['min'] ) ) {
42
			$this->min = $config['min'];
43
		}
44
		if ( isset( $config['max'] ) ) {
45
			$this->max = $config['max'];
46
		}
47
		if ( isset( $config['clearable'] ) ) {
48
			$this->clearable = $config['clearable'];
49
		}
50
51
		// Initialization
52
		$this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] );
53
	}
54
55
	protected function getJavaScriptClassName() {
56
		return 'mw.widgets.datetime.DateTimeInputWidget';
57
	}
58
59
	public function getConfig( &$config ) {
60
		$config['type'] = $this->type;
61
		if ( $this->min !== null ) {
62
			$config['min'] = $this->min;
63
		}
64
		if ( $this->max !== null ) {
65
			$config['max'] = $this->max;
66
		}
67
		if ( $this->clearable !== null ) {
68
			$config['clearable'] = $this->clearable;
69
		}
70
		return parent::getConfig( $config );
71
	}
72
73
	protected function getInputElement( $config ) {
74
		return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type ] );
75
	}
76
}
77