ListParameter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameterType() 0 3 1
A setValue() 0 9 2
A addValue() 0 19 4
1
<?php
2
3
/**
4
	* ListParameter.php
5
	*/
6
	
7
namespace netfocusinc\argh;
8
9
use netfocusinc\argh\ArghException;
10
use netfocusinc\argh\Parameter;
11
12
13
/**
14
	* A List Parameter.
15
	*
16
	* Subtype of Parameter that represents a list of text values.
17
	*
18
	* @api
19
	*
20
	* @author Benjamin Hough
21
	*
22
	* @since 1.0.0
23
	*/
24
class ListParameter extends Parameter
25
{
26
	
27
	//
28
	// STATIC FUNCTIONS
29
	//
30
	
31
	//
32
	// PUBLIC FUNCTIONS
33
	//
34
	
35
	/**
36
		* ReturnsParameter::ARGH_TYPE_LIST
37
		*
38
		* Identifies this Parameter subtype as a ListParameter by returning constant ARGH_TYPE_LIST
39
		*
40
		* @since 1.0.0
41
		*
42
		* @return int
43
		*/
44
	public function getParameterType(): int
45
	{
46
		return Parameter::ARGH_TYPE_LIST;
47
	}
48
49
	/**
50
		* Sets the array value of this Parameter.
51
		*
52
		* Forces all values into an array
53
		*
54
		* @since 1.0.0
55
		*/
56
	public function setValue($value)
57
	{		
58
		if(is_array($value))
59
		{
60
			$this->value = $value;
61
		}
62
		else
63
		{
64
			$this->value = array($value);
65
		}
66
	}
67
68
	/**
69
		* Adds an element to the value of this Parameter
70
		*
71
		* Forces all values into an array
72
		*
73
		* @since 1.0.0
74
		*
75
		* @return int
76
		*/	
77
	public function addValue($value)
78
	{
79
		// Check if this Parameter has a previously set value
80
		if($this->value === null)
81
		{
82
			// Initialize this Parameters value to a new array
83
			$this->value = array();
84
		}
85
		
86
		// Check if the new value is an array
87
		if(!is_array($value))
88
		{
89
			// Append new single value to this Parameters value array
90
			$this->value[] = $value;
91
		}
92
		else
93
		{
94
			// Append every new value to this Parameters value array
95
			foreach($value as $v) $this->value[] = $v;
96
		}
97
	}
98
	
99
}
100