Completed
Push — master ( f37ab5...9ec323 )
by T
20:09
created

Level::fromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PHPSemVerChecker\SemanticVersioning;
4
5
class Level {
6
	const NONE = 0; // TODO: Get rid of this *level* <[email protected]>
7
	const PATCH = 1;
8
	const MINOR = 2;
9
	const MAJOR = 3;
10
11
	/**
12
	 * @param string $order
13
	 * @return array
14
	 */
15 61
	public static function asList($order = 'asc')
16
	{
17
		$levels = [
18 61
			self::PATCH,
19 61
			self::MINOR,
20 61
			self::MAJOR,
21 61
		];
22 61
		if ($order === 'asc') {
23 59
			return $levels;
24
		} else {
25 6
			rsort($levels);
26 6
			return $levels;
27
		}
28
	}
29
30
	/**
31
	 * @param int $level
32
	 * @return string
33
	 */
34 2 View Code Duplication
	public static function toString($level)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
	{
36
		$mapping = [
37 2
			self::NONE  => 'NONE',
38 2
			self::PATCH => 'PATCH',
39 2
			self::MINOR => 'MINOR',
40 2
			self::MAJOR => 'MAJOR',
41 2
		];
42
43 2
		return $mapping[$level];
44
	}
45
46
	/**
47
	 * @param string $level
48
	 * @return int
49
	 */
50 4 View Code Duplication
	public static function fromString($level)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		$mapping = [
53 4
			'NONE'  => self::NONE,
54 4
			'PATCH' => self::PATCH,
55 4
			'MINOR' => self::MINOR,
56 4
			'MAJOR' => self::MAJOR,
57 4
		];
58
59 4
		return $mapping[strtoupper($level)];
60
	}
61
}
62