Completed
Push — master ( 589fec...539028 )
by Milan
07:58
created

InvalidArgument   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 35.9 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 14
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 7 2
A checkRange() 7 7 3
A checkIsInList() 0 7 2
A checkLength() 7 7 2

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 declare(strict_types=1);
2
3
namespace h4kuna\Fio\Exceptions;
4
5
final class InvalidArgument extends \InvalidArgumentException
6
{
7
8
	public static function check(string $text, int $size): string
9
	{
10
		if (mb_strlen($text) > $size) {
11
			throw new static(sprintf('Value "%s" is longer then allowed limit (%s).', $text, $size));
12
		}
13
		return $text;
14
	}
15
16
17 View Code Duplication
	public static function checkRange(int $number, int $limit): int
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...
18
	{
19
		if ($number < 0 || $number > $limit) {
20
			throw new static(sprintf('Value is out of range "%s" must contain 1-%s positive digits.', $number, strlen((string) $limit)));
21
		}
22
		return $number;
23
	}
24
25
26
	public static function checkIsInList($value, array $list)
27
	{
28
		if (!in_array($value, $list, true)) {
29
			throw new InvalidArgument(sprintf('Value "%s" is not contained in list: [%s].', $value, implode(', ', $list)));
30
		}
31
		return $value;
32
	}
33
34
35 View Code Duplication
	public static function checkLength(string $text, int $limit): string
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...
36
	{
37
		if (strlen($text) !== $limit) {
38
			throw new static(sprintf('Value has not exact length "%s" this is "%s" with length "%s".', $limit, $text, strlen((string) $text)));
39
		}
40
		return $text;
41
	}
42
43
}
44