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

Level   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 38.6 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 0
dl 22
loc 57
ccs 23
cts 23
cp 1
rs 10

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
	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