-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdepend.php
More file actions
138 lines (117 loc) · 3.96 KB
/
Copy pathPdepend.php
File metadata and controls
138 lines (117 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
declare(strict_types=1);
namespace PHPCensor\Plugins\CodeQuality;
use PHPCensor\Common\Build\BuildInterface;
use PHPCensor\Common\Exception\Exception;
use PHPCensor\Common\Plugin\Plugin;
use Symfony\Component\Filesystem\Filesystem;
/**
* Pdepend Plugin - Allows Pdepend report
*
* @package PHP Censor
* @subpackage Plugins
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
* @author Johan van der Heide <info@japaveh.nl>
*/
class Pdepend extends Plugin
{
/**
* @var string File where the summary.xml is stored
*/
private string $summary = 'summary.xml';
/**
* @var string File where the chart.svg is stored
*/
private string $chart = 'chart.svg';
/**
* @var string File where the pyramid.svg is stored
*/
private string $pyramid = 'pyramid.svg';
/**
* {@inheritDoc}
*/
public static function getName(): string
{
return 'pdepend';
}
/**
* {@inheritDoc}
*/
public function execute(): bool
{
$executable = $this->commandExecutor->findBinary($this->binaryNames, $this->binaryPath);
$allowPublicArtifacts = $this->application->isPublicArtifactsAllowed();
$fileSystem = new Filesystem();
if (!$fileSystem->exists($this->getArtifactPath())) {
$fileSystem->mkdir($this->getArtifactPath(), (0777 & ~\umask()));
}
if (!\is_writable($this->getArtifactPath())) {
throw new Exception(\sprintf(
'The location %s is not writable or does not exist.',
$this->getArtifactPath()
));
}
$cmd = 'cd "%s" && ' . $executable . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
$ignores = '';
if (\count($this->ignores)) {
$ignores = \sprintf(' --ignore="%s"', \implode(',', $this->ignores));
}
$success = $this->commandExecutor->executeCommand(
$cmd,
$this->build->getBuildPath(),
$this->getArtifactPath($this->summary),
$this->getArtifactPath($this->chart),
$this->getArtifactPath($this->pyramid),
$ignores,
$this->directory
);
if (!$allowPublicArtifacts) {
$fileSystem->remove($this->getArtifactPath());
}
if ($allowPublicArtifacts && \file_exists($this->getArtifactPath())) {
$fileSystem->remove($this->getArtifactPathForBranch());
$fileSystem->mirror($this->getArtifactPath(), $this->getArtifactPathForBranch());
}
if ($allowPublicArtifacts && $success) {
$this->buildLogger->logSuccess(
\sprintf(
"\nPdepend successful build report.\nYou can use report for this build for inclusion in the readme.md file:\n%s,\n and\n\n\nOr report for last build in the branch:\n%s,\n and\n\n",
$this->getArtifactLink($this->summary),
$this->getArtifactLink($this->chart),
$this->getArtifactLink($this->pyramid),
$this->getArtifactLinkForBranch($this->summary),
$this->getArtifactLinkForBranch($this->chart),
$this->getArtifactLinkForBranch($this->pyramid)
)
);
}
return $success;
}
/**
* {@inheritDoc}
*/
public static function canExecute(string $stage, BuildInterface $build): bool
{
if (BuildInterface::STAGE_TEST === $stage) {
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
protected function initPluginSettings(): void
{
}
/**
* {@inheritDoc}
*/
protected function getPluginDefaultBinaryNames(): array
{
return [
'pdepend',
'pdepend.phar',
];
}
}