This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @package: chapi |
||
4 | * |
||
5 | * @author: msiebeneicher |
||
6 | * @since: 2015-07-30 |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | namespace Chapi\Commands; |
||
11 | |||
12 | use Chapi\BusinessCase\Comparison\JobComparisonInterface; |
||
13 | use Chapi\Service\JobRepository\JobRepository; |
||
14 | use Symfony\Component\Console\Input\InputArgument; |
||
15 | use Symfony\Component\Console\Input\InputOption; |
||
16 | |||
17 | class DiffCommand extends AbstractCommand |
||
18 | { |
||
19 | /** |
||
20 | * Configures the current command. |
||
21 | */ |
||
22 | protected function configure() |
||
23 | { |
||
24 | $this->setName('diff') |
||
25 | ->setDescription('Show changes between jobs and working tree, etc') |
||
26 | ->addArgument('jobName', InputArgument::OPTIONAL, 'Show changes for specific job') |
||
27 | ->addOption( |
||
28 | 'strict', |
||
29 | null, |
||
30 | InputOption::VALUE_NONE, |
||
31 | "Return a non-zero exit code when there are changes", |
||
0 ignored issues
–
show
|
|||
32 | null |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return int |
||
38 | */ |
||
39 | protected function process() |
||
40 | { |
||
41 | $this->output->writeln("<info>+++ local</info>"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
<info>+++ local</info> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
42 | $this->output->writeln("<fg=red>--- remote</>"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
<fg=red>--- remote</> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
43 | /** @var JobComparisonInterface $jobComparisonBusinessCase */ |
||
44 | $jobComparisonBusinessCase = $this->getContainer()->get(JobComparisonInterface::DIC_NAME); |
||
45 | $jobName = $this->input->getArgument('jobName'); |
||
46 | |||
47 | $changed = false; |
||
48 | |||
49 | if (!empty($jobName)) { |
||
50 | $changed = $this->printJobDiff($jobName); |
||
51 | } else { |
||
52 | $localJobUpdates = $jobComparisonBusinessCase->getLocalJobUpdates(); |
||
53 | if (!empty($localJobUpdates)) { |
||
54 | foreach ($localJobUpdates as $jobName) { |
||
55 | $changed = $this->printJobDiff($jobName) || $changed; |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
60 | if ($this->input->getOption('strict') && $changed) { |
||
61 | return 1; |
||
62 | } |
||
63 | |||
64 | return 0; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param string $jobName |
||
69 | */ |
||
70 | private function printJobDiff($jobName) |
||
71 | { |
||
72 | /** @var JobComparisonInterface $jobComparisonBusinessCase */ |
||
73 | $jobComparisonBusinessCase = $this->getContainer()->get(JobComparisonInterface::DIC_NAME); |
||
74 | |||
75 | $jobs = [ $jobName ]; |
||
76 | |||
77 | if (strpos($jobName, '*') !== false) { |
||
78 | $jobs = $this->getJobsMatchingWildcard($jobName); |
||
79 | } |
||
80 | |||
81 | $changed = false; |
||
82 | |||
83 | foreach ($jobs as $jobName) { |
||
84 | $changed = $this->printSingleJobDiff($jobComparisonBusinessCase, $jobName) || $changed; |
||
85 | } |
||
86 | |||
87 | return $changed; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param JobComparisonInterface $jobComparisonBusinessCase |
||
92 | * @param string $jobName |
||
93 | */ |
||
94 | private function printSingleJobDiff(JobComparisonInterface $jobComparisonBusinessCase, $jobName) |
||
95 | { |
||
96 | $this->output->writeln(sprintf("\n<comment>diff %s</comment>", $jobName)); |
||
97 | |||
98 | $jobDiff = $jobComparisonBusinessCase->getJobDiff($jobName); |
||
99 | |||
100 | foreach ($jobDiff as $property => $diff) { |
||
101 | $diffLines = explode(PHP_EOL, $diff); |
||
102 | |||
103 | // the first line might be missing some leading whitespace |
||
104 | if (count($diffLines) > 1) { |
||
105 | $lastLine = $diffLines[count($diffLines) - 1]; |
||
106 | |||
107 | if (strpos($lastLine, ' ') === 0) { |
||
108 | $length = strspn($lastLine, ' '); |
||
109 | |||
110 | $diffLines[0] = substr($lastLine, 0, $length) . $diffLines[0]; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | foreach ($diffLines as $diffLine) { |
||
115 | $diffSign = substr($diffLine, 0, 1); |
||
116 | |||
117 | if ($diffSign == '+') { |
||
118 | $this->output->writeln(sprintf("<info>%s\t%s: %s</info>", $diffSign, $property, ' ' . substr($diffLine, 1))); |
||
119 | } elseif ($diffSign == '-') { |
||
120 | $this->output->writeln(sprintf("<fg=red>%s\t%s: %s</>", $diffSign, $property, ' ' . substr($diffLine, 1))); |
||
121 | } else { |
||
122 | $this->output->writeln(sprintf(" \t%s: %s", $property, $diffLine)); |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | $this->output->writeln("\n"); |
||
128 | |||
129 | return !empty($jobDiff); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param string $jobName |
||
134 | * @return string[] |
||
135 | */ |
||
136 | private function getJobsMatchingWildcard($jobName) |
||
137 | { |
||
138 | /** @var JobRepository[] $jobRepositories */ |
||
139 | $jobRepositories = [ |
||
140 | $this->getContainer()->get(JobRepository::DIC_NAME_CHRONOS), |
||
141 | $this->getContainer()->get(JobRepository::DIC_NAME_FILESYSTEM_CHRONOS), |
||
142 | $this->getContainer()->get(JobRepository::DIC_NAME_FILESYSTEM_MARATHON), |
||
143 | $this->getContainer()->get(JobRepository::DIC_NAME_MARATHON) |
||
144 | ]; |
||
145 | |||
146 | $jobNames = []; |
||
147 | |||
148 | foreach ($jobRepositories as $jobRepository) { |
||
149 | foreach ($jobRepository->getJobs() as $job) { |
||
150 | if (fnmatch($jobName, $job->getKey())) { |
||
151 | $jobNames[$job->getKey()] = true; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | ksort($jobNames); |
||
157 | |||
158 | return array_keys($jobNames); |
||
159 | } |
||
160 | } |
||
161 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.