Completed
Branch MetaCharacters (da2f1d)
by Josh
01:29
created

BaseImplementation::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
* @package   s9e\RegexpBuilder
5
* @copyright Copyright (c) 2016-2018 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\RegexpBuilder\Output;
9
10
use InvalidArgumentException;
11
12
abstract class BaseImplementation implements OutputInterface
13
{
14
	/**
15
	* @var integer
16
	*/
17
	protected $maxValue = 0;
18
19
	/**
20
	* @var integer
21
	*/
22
	protected $minValue = 0;
23
24
	/**
25
	* @param array $options
26
	*/
27 53
	public function __construct(array $options = [])
28
	{
29 53
		$this->setOptions($options);
30 53
	}
31
32
	/**
33
	* {@inheritdoc}
34
	*/
35 53
	public function output($value)
36
	{
37 53
		$this->validate($value);
38
39 47
		return $this->outputValidValue($value);
40
	}
41
42
	/**
43
	* Set the options associated via this output interface
44
	*
45
	* @param  array $options
46
	* @return void
47
	*/
48 19
	protected function setOptions(array $options)
49
	{
50 19
	}
51
52
	/**
53
	* Validate given value
54
	*
55
	* @param  integer $value
56
	* @return void
57
	*/
58 51
	protected function validate($value)
59
	{
60 51
		if ($value < $this->minValue || $value > $this->maxValue)
61
		{
62 4
			throw new InvalidArgumentException('Value ' . $value . ' is out of bounds (' . $this->minValue . '..' . $this->maxValue . ')');
63
		}
64 47
	}
65
66
	/**
67
	* Serialize a valid value into a character
68
	*
69
	* @param  integer $value
70
	* @return string
71
	*/
72
	abstract protected function outputValidValue($value);
73
}