Level::toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PHPSemVerChecker\SemanticVersioning;
4
5
class Level
6
{
7
	const NONE = 0; // TODO: Get rid of this *level* <[email protected]>
8
	const PATCH = 1;
9
	const MINOR = 2;
10
	const MAJOR = 3;
11
12
	/**
13
	 * @param string $order
14
	 * @return array
15
	 */
16 152
	public static function asList($order = 'asc')
17
	{
18
		$levels = [
19 152
			self::PATCH,
20 152
			self::MINOR,
21 152
			self::MAJOR,
22
		];
23 152
		if ($order === 'asc') {
24 150
			return $levels;
25
		} else {
26 6
			rsort($levels);
27 6
			return $levels;
28
		}
29
	}
30
31
	/**
32
	 * @param int $level
33
	 * @return string
34
	 */
35 2 View Code Duplication
	public static function toString($level)
36
	{
37
		$mapping = [
38 2
			self::NONE  => 'NONE',
39 2
			self::PATCH => 'PATCH',
40 2
			self::MINOR => 'MINOR',
41 2
			self::MAJOR => 'MAJOR',
42
		];
43
44 2
		return $mapping[$level];
45
	}
46
47
	/**
48
	 * @param string $level
49
	 * @return int
50
	 */
51 4 View Code Duplication
	public static function fromString($level)
52
	{
53
		$mapping = [
54 4
			'NONE'  => self::NONE,
55 4
			'PATCH' => self::PATCH,
56 4
			'MINOR' => self::MINOR,
57 4
			'MAJOR' => self::MAJOR,
58
		];
59
60 4
		return $mapping[strtoupper($level)];
61
	}
62
}
63