StringParameter::setValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
	* StringParameter.php
5
	*/
6
	
7
namespace netfocusinc\argh;
8
9
use netfocusinc\argh\ArghException;
10
use netfocusinc\argh\Parameter;
11
12
13
/**
14
	* String parameter
15
	*
16
	* Subtype of Parameter that represents a string value.
17
	*
18
	* @api
19
	*
20
	* @author Benjamin Hough
21
	*
22
	* @since 1.0.0
23
	*/
24
class StringParameter extends Parameter
25
{
26
	
27
	//
28
	// STATIC FUNCTIONS
29
	//
30
	
31
	//
32
	// PUBLIC FUNCTIONS
33
	//
34
	
35
	/**
36
		* Returns ARGH_TYPE_STRING
37
		*
38
		* @since 1.0.0
39
		*
40
		* @return int
41
		*/
42
	public function getParameterType(): int
43
	{
44
		return Parameter::ARGH_TYPE_STRING;
45
	}
46
47
	/**
48
		* Sets the string value of this Parameter.
49
		*
50
		* Casts all values to string.
51
		*
52
		* @since 1.0.0
53
		*
54
		* @param mixed $value
55
		*
56
		* @throws ArghExpception If $value is an array.
57
		*/
58
	public function setValue($value)
59
	{		
60
		if(is_array($value))
61
		{
62
			throw(new ArghException('StringParameter values cannot be set to an array'));
63
		}
64
		
65
		$this->value = strval($value);
66
	}
67
	
68
}
69
70
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...