1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack\Analyzer; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This simply lists dependencies of invocations in Codebase A to declarations in codebase B |
7
|
|
|
*/ |
8
|
|
|
class Dependencies extends PersistentList { |
9
|
|
|
function generate( $invocations, $declarations, $invocation_root = null ) { |
10
|
|
|
if ( $invocation_root ) { |
11
|
|
|
$invocation_root = $this->slashit( $invocation_root ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Scan every invocation to see if it depends on a Difference |
16
|
|
|
*/ |
17
|
|
|
foreach( $invocations->get() as $invocation ) { |
18
|
|
|
foreach( $declarations->get() as $declaration ) { |
19
|
|
|
// $warning = $ |
20
|
|
|
if ( $invocation->depends_on( $declaration ) ) { |
21
|
|
|
$this->add( new Dependencies\Dependency( $invocation, $declaration, $invocation_root ) ); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
private function slashit( $path ) { |
28
|
|
|
$path .= ( substr( $path, -1 ) == '/' ? '' : '/' ); |
29
|
|
|
return $path; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function declaration_summary() { |
33
|
|
|
if ( $this->count() === 0 ) { |
34
|
|
|
return ''; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// assoc array of issues and counts |
38
|
|
|
$summary = array(); |
39
|
|
|
foreach( $this->get() as $dependency ) { |
40
|
|
|
$unique_issue_key = $dependency->declaration->display_name(); |
41
|
|
|
|
42
|
|
|
if ( ! isset( $summary[$unique_issue_key] ) ) { |
43
|
|
|
$summary[$unique_issue_key] = 0; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$summary[$unique_issue_key] += 1; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
arsort( $summary ); |
50
|
|
|
|
51
|
|
|
$summary_string = ''; |
52
|
|
|
foreach( $summary as $issue => $count ) { |
53
|
|
|
$summary_string .= "$issue,$count\n"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $summary_string; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function external_file_summary() { |
60
|
|
|
if ( $this->count() === 0 ) { |
61
|
|
|
return ''; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// assoc array of issues and counts |
65
|
|
|
$summary = array(); |
66
|
|
|
foreach( $this->get() as $dependency ) { |
67
|
|
|
$unique_issue_key = $dependency->full_path(); |
68
|
|
|
|
69
|
|
|
if ( ! isset( $summary[$unique_issue_key] ) ) { |
70
|
|
|
$summary[$unique_issue_key] = 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$summary[$unique_issue_key] += 1; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
arsort( $summary ); |
77
|
|
|
|
78
|
|
|
$summary_string = ''; |
79
|
|
|
foreach( $summary as $issue => $count ) { |
80
|
|
|
$summary_string .= "$issue,$count\n"; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $summary_string; |
84
|
|
|
} |
85
|
|
|
} |