Level   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 37.93 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 22
loc 58
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A asList() 0 14 2
A toString() 11 11 1
A fromString() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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