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