StringParam   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 30.76%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 62
ccs 4
cts 13
cp 0.3076
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatValue() 0 9 2
A setArrayValues() 0 7 2
A setToLower() 0 3 1
1
<?php
2
3
namespace ParamProcessor\Definition;
4
5
use ParamProcessor\ParamDefinition;
6
use ParamProcessor\IParam;
7
8
/**
9
 * Defines the string parameter type.
10
 * Specifies the type specific validation and formatting logic.
11
 *
12
 * @deprecated since 1.7
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class StringParam extends ParamDefinition {
18
19
	/**
20
	 * Indicates if the parameter should be lowercased post validation.
21
	 *
22
	 * @since 1.0
23
	 *
24
	 * @var boolean
25
	 */
26
	protected $toLower = false;
27
28
	/**
29
	 * Formats the parameter value to it's final result.
30
	 * @see ParamDefinition::formatValue
31
	 *
32
	 * @since 1.0
33
	 *
34
	 * @param $value mixed
35
	 * @param $param IParam
36
	 * @param $definitions array of IParamDefinition
37
	 * @param $params array of IParam
38
	 *
39
	 * @return mixed
40
	 */
41 4
	protected function formatValue( $value, IParam $param, array &$definitions, array $params ) {
42 4
		$value = (string)$value;
43
44 4
		if ( $this->toLower ) {
45
			$value = strtolower( $value );
46
		}
47
48 4
		return $value;
49
	}
50
51
	/**
52
	 * Sets the parameter definition values contained in the provided array.
53
	 * @see ParamDefinition::setArrayValues
54
	 *
55
	 * @since 1.0
56
	 *
57
	 * @param array $param
58
	 */
59
	public function setArrayValues( array $param ) {
60
		parent::setArrayValues( $param );
0 ignored issues
show
Deprecated Code introduced by
The method ParamProcessor\ParamDefinition::setArrayValues() has been deprecated with message: since 1.7
TODO: provide alternative in ParamDefinitionFactory

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...
61
62
		if ( array_key_exists( 'tolower', $param ) ) {
63
			$this->toLower = $param['tolower'];
64
		}
65
	}
66
67
	/**
68
	 * Sets of the value should be lowercased.
69
	 *
70
	 * @since 1.0
71
	 *
72
	 * @param boolean $toLower
73
	 */
74
	public function setToLower( $toLower ) {
75
		$this->toLower = $toLower;
76
	}
77
78
}
79