GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( eb5c8e...f4ded9 )
by Joni
06:39
created

CRLDistributionPointsExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 30.26 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 4
dl 23
loc 76
ccs 26
cts 27
cp 0.963
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A _fromDER() 13 13 2
A _valueASN1() 10 10 2
A distributionPoints() 0 3 1
A count() 0 3 1
A getIterator() 0 3 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 X509\Certificate\Extension;
4
5
use ASN1\Type\Constructed\Sequence;
6
use ASN1\Type\UnspecifiedType;
7
use X509\Certificate\Extension\DistributionPoint\DistributionPoint;
8
9
10
/**
11
 * Implements 'CRL Distribution Points' certificate extension.
12
 *
13
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.13
14
 */
15
class CRLDistributionPointsExtension extends Extension implements \Countable, 
0 ignored issues
show
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
16
	\IteratorAggregate
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
17
{
18
	/**
19
	 * Distribution points.
20
	 *
21
	 * @var DistributionPoint[] $_distributionPoints
22
	 */
23
	protected $_distributionPoints;
24
	
25
	/**
26
	 * Constructor
27
	 *
28
	 * @param bool $critical
29
	 * @param DistributionPoint ...$distribution_points
30
	 */
31 7
	public function __construct($critical, 
32
			DistributionPoint ...$distribution_points) {
33 7
		parent::__construct(self::OID_CRL_DISTRIBUTION_POINTS, $critical);
34 7
		$this->_distributionPoints = $distribution_points;
35 7
	}
36
	
37 7 View Code Duplication
	protected static function _fromDER($data, $critical) {
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...
38 7
		$dps = array_map(
39
			function (UnspecifiedType $el) {
40 6
				return DistributionPoint::fromASN1($el->asSequence());
41 7
			}, Sequence::fromDER($data)->elements());
42 7
		if (!count($dps)) {
43 1
			throw new \UnexpectedValueException(
44
				"CRLDistributionPoints must have" .
45 1
					 " at least one DistributionPoint.");
46
		}
47
		// late static bound, extended by Freshest CRL extension
48 6
		return new static($critical, ...$dps);
49
	}
50
	
51 4 View Code Duplication
	protected function _valueASN1() {
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...
52 4
		if (!count($this->_distributionPoints)) {
53 1
			throw new \LogicException("No distribution points.");
54
		}
55 3
		$elements = array_map(
56 3
			function (DistributionPoint $dp) {
57 3
				return $dp->toASN1();
58 3
			}, $this->_distributionPoints);
59 3
		return new Sequence(...$elements);
60
	}
61
	
62
	/**
63
	 * Get distribution points.
64
	 *
65
	 * @return DistributionPoint[]
66
	 */
67 1
	public function distributionPoints() {
68 1
		return $this->_distributionPoints;
69
	}
70
	
71
	/**
72
	 * Get the number of distribution points.
73
	 *
74
	 * @see Countable::count()
75
	 * @return int
76
	 */
77 1
	public function count() {
78 1
		return count($this->_distributionPoints);
79
	}
80
	
81
	/**
82
	 * Get iterator for distribution points.
83
	 *
84
	 * @see IteratorAggregate::getIterator()
85
	 * @return \ArrayIterator
86
	 */
87 3
	public function getIterator() {
88 3
		return new \ArrayIterator($this->_distributionPoints);
89
	}
90
}
91