Completed
Push — renovate/glob-7.x ( 697d78...f7fc07 )
by
unknown
18:21 queued 12:01
created

Warnings   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 65 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 26
loc 40
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 11 3
A summary() 26 26 5

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 Automattic\Jetpack\Analyzer;
4
5
class Warnings extends PersistentList {
6
	public function generate( $invocations, $differences ) {
7
		/**
8
		 * Scan every invocation to see if it depends on a Difference
9
		 */
10
		foreach( $invocations->get() as $invocation ) {
11
			foreach( $differences->get() as $difference ) {
12
				// $warning = $
13
				$difference->find_invocation_warnings( $invocation, $this );
14
			}
15
		}
16
	}
17
18 View Code Duplication
	public function summary() {
19
		if ( $this->count() === 0 ) {
20
			return '';
21
		}
22
23
		// assoc array of issues and counts
24
		$summary = array();
25
		foreach( $this->get() as $warning ) {
26
			$unique_issue_key = $warning->unique_issue_key();
27
28
			if ( ! isset( $summary[$unique_issue_key] ) ) {
29
				$summary[$unique_issue_key] = 0;
30
			}
31
32
			$summary[$unique_issue_key] += 1;
33
		}
34
35
		arsort( $summary );
36
37
		$summary_string = '';
38
		foreach( $summary as $issue => $count ) {
39
			$summary_string .= "$issue,$count\n";
40
		}
41
42
		return $summary_string;
43
	}
44
}