StringConfigSetting::convertToStorageFormat()   A
last analyzed

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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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