StringConfigSetting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 6
c 0
b 0
f 0
dl 0
loc 40
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeValue() 0 3 2
A convertToStorageFormat() 0 3 1
A validate() 0 5 2
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Config;
12
13
14
class StringConfigSetting extends AbstractConfigSetting
15
{
16
17
	/**
18
	 * Normalizes value.
19
	 *
20
	 * @param mixed $value Value.
21
	 *
22
	 * @return mixed
23
	 */
24 36
	protected function normalizeValue($value)
25
	{
26 36
		return is_string($value) ? trim($value) : $value;
27
	}
28
29
	/**
30
	 * Converts value into scalar for used for storage.
31
	 *
32
	 * @param mixed $value Value.
33
	 *
34
	 * @return mixed
35
	 */
36 36
	protected function convertToStorageFormat($value)
37
	{
38 36
		return (string)$value;
39
	}
40
41
	/**
42
	 * Performs value validation.
43
	 *
44
	 * @param mixed $value Value.
45
	 *
46
	 * @return void
47
	 * @throws \InvalidArgumentException When validation failed.
48
	 */
49 17
	protected function validate($value)
50
	{
51 17
		if ( !is_string($value) ) {
52 2
			throw new \InvalidArgumentException(
53 2
				'The "' . $this->getName() . '" config setting value must be a string.'
54 2
			);
55
		}
56
	}
57
58
}
59