Skip to content

Commit 8e72191

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 51868a0 + 18f8ae0 commit 8e72191

8 files changed

Lines changed: 530 additions & 88 deletions

File tree

‎phpcs.xml.dist‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
<file>./tests</file>
1616
<file>./config.sample.inc.php</file>
1717

18+
<!-- Make sniff report relative -->
19+
<arg name="basepath" value="."/>
20+
1821
<exclude-pattern>*/app/cache/*</exclude-pattern>
1922
<exclude-pattern>*/app/language_stats.inc.php</exclude-pattern>
2023
<exclude-pattern>*/build/*</exclude-pattern>
2124
<exclude-pattern>*/config.inc.php</exclude-pattern>
2225
<exclude-pattern>*/node_modules/*</exclude-pattern>
2326
<exclude-pattern>*/tests/doctum-config.php</exclude-pattern>
27+
<exclude-pattern>*/revision-info.php</exclude-pattern>
2428
<exclude-pattern>*/tmp/*</exclude-pattern>
2529
<exclude-pattern>*/twig-templates/*</exclude-pattern>
2630
<exclude-pattern>*/vendor/*</exclude-pattern>

‎phpstan-baseline.neon‎

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8535,12 +8535,6 @@ parameters:
85358535
count: 2
85368536
path: src/Footer.php
85378537

8538-
-
8539-
message: '#^Method PhpMyAdmin\\Footer\:\:getGitRevisionInfo\(\) should return array\<string, string\> but returns array\<mixed\>\.$#'
8540-
identifier: return.type
8541-
count: 1
8542-
path: src/Footer.php
8543-
85448538
-
85458539
message: '#^Only booleans are allowed in &&, array\<mixed, mixed\>\|object given on the right side\.$#'
85468540
identifier: booleanAnd.rightNotBoolean
@@ -9172,7 +9166,7 @@ parameters:
91729166
path: src/Git.php
91739167

91749168
-
9175-
message: '#^Parameter \#1 \$commit of method PhpMyAdmin\\Git\:\:extractDataFormTextBody\(\) expects array\<mixed\>, mixed given\.$#'
9169+
message: '#^Parameter \#1 \$commit of static method PhpMyAdmin\\Git\:\:extractDataFormTextBody\(\) expects array\<string\>, mixed given\.$#'
91769170
identifier: argument.type
91779171
count: 1
91789172
path: src/Git.php
@@ -9214,7 +9208,7 @@ parameters:
92149208
path: src/Git.php
92159209

92169210
-
9217-
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
9211+
message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#'
92189212
identifier: argument.type
92199213
count: 1
92209214
path: src/Git.php
@@ -21000,6 +20994,78 @@ parameters:
2100020994
count: 1
2100120995
path: tests/unit/Gis/GisPolygonTest.php
2100220996

20997+
-
20998+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''author'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: ''QA_5_2'', message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
20999+
identifier: staticMethod.alreadyNarrowedType
21000+
count: 1
21001+
path: tests/unit/GitTest.php
21002+
21003+
-
21004+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''branch'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: string\|false, message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21005+
identifier: staticMethod.alreadyNarrowedType
21006+
count: 1
21007+
path: tests/unit/GitTest.php
21008+
21009+
-
21010+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''committer'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: ''QA_5_2'', message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21011+
identifier: staticMethod.alreadyNarrowedType
21012+
count: 1
21013+
path: tests/unit/GitTest.php
21014+
21015+
-
21016+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''hash'' and array\{hash\: string, branch\: string\|false, message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21017+
identifier: staticMethod.alreadyNarrowedType
21018+
count: 1
21019+
path: tests/unit/GitTest.php
21020+
21021+
-
21022+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''is_remote_branch'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: ''QA_5_2'', message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21023+
identifier: staticMethod.alreadyNarrowedType
21024+
count: 1
21025+
path: tests/unit/GitTest.php
21026+
21027+
-
21028+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''is_remote_commit'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: ''QA_5_2'', message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21029+
identifier: staticMethod.alreadyNarrowedType
21030+
count: 1
21031+
path: tests/unit/GitTest.php
21032+
21033+
-
21034+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) with ''message'' and array\{hash\: ''97b9895908f281b62c9…'', branch\: ''QA_5_2'', message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21035+
identifier: staticMethod.alreadyNarrowedType
21036+
count: 1
21037+
path: tests/unit/GitTest.php
21038+
21039+
-
21040+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{hash\: string, branch\: string\|false, message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21041+
identifier: staticMethod.alreadyNarrowedType
21042+
count: 1
21043+
path: tests/unit/GitTest.php
21044+
21045+
-
21046+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{name\: string, email\: string, date\: string\} will always evaluate to true\.$#'
21047+
identifier: staticMethod.alreadyNarrowedType
21048+
count: 2
21049+
path: tests/unit/GitTest.php
21050+
21051+
-
21052+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsBool\(\) with bool will always evaluate to true\.$#'
21053+
identifier: staticMethod.alreadyNarrowedType
21054+
count: 2
21055+
path: tests/unit/GitTest.php
21056+
21057+
-
21058+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsString\(\) with string will always evaluate to true\.$#'
21059+
identifier: staticMethod.alreadyNarrowedType
21060+
count: 7
21061+
path: tests/unit/GitTest.php
21062+
21063+
-
21064+
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertNotNull\(\) with array\{hash\: string, branch\: string\|false, message\: string, author\: array\{name\: string, email\: string, date\: string\}, committer\: array\{name\: string, email\: string, date\: string\}, is_remote_commit\: bool, is_remote_branch\: bool\} will always evaluate to true\.$#'
21065+
identifier: staticMethod.alreadyNarrowedType
21066+
count: 1
21067+
path: tests/unit/GitTest.php
21068+
2100321069
-
2100421070
message: '''
2100521071
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:

‎psalm-baseline.xml‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,13 +5156,8 @@
51565156
<code><![CDATA[$params]]></code>
51575157
</InvalidArgument>
51585158
<MixedAssignment>
5159-
<code><![CDATA[$info]]></code>
51605159
<code><![CDATA[$subObject]]></code>
51615160
</MixedAssignment>
5162-
<MixedReturnTypeCoercion>
5163-
<code><![CDATA[array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]]]></code>
5164-
<code><![CDATA[is_array($info) ? $info : []]]></code>
5165-
</MixedReturnTypeCoercion>
51665161
<RiskyTruthyFalsyComparison>
51675162
<code><![CDATA[$object]]></code>
51685163
<code><![CDATA[empty($_REQUEST['no_debug'])]]></code>
@@ -5474,16 +5469,11 @@
54745469
<MixedArgument>
54755470
<code><![CDATA[$commit]]></code>
54765471
<code><![CDATA[$commitJson->message]]></code>
5477-
<code><![CDATA[$dataline]]></code>
54785472
<code><![CDATA[$offset + ($position * 20)]]></code>
54795473
<code><![CDATA[$offset + ($position * 4)]]></code>
54805474
</MixedArgument>
5481-
<MixedArgumentTypeCoercion>
5482-
<code><![CDATA[$commit]]></code>
5483-
</MixedArgumentTypeCoercion>
54845475
<MixedAssignment>
54855476
<code><![CDATA[$commit]]></code>
5486-
<code><![CDATA[$dataline]]></code>
54875477
<code><![CDATA[$end]]></code>
54885478
<code><![CDATA[$gitLocation]]></code>
54895479
<code><![CDATA[$offset]]></code>
@@ -5516,6 +5506,27 @@
55165506
<code><![CDATA[$packOffsets[1]]]></code>
55175507
<code><![CDATA[json_decode((string) $isFound)]]></code>
55185508
</MixedReturnStatement>
5509+
<MixedReturnTypeCoercion>
5510+
<code><![CDATA[$info]]></code>
5511+
<code><![CDATA[array{
5512+
* revision: string,
5513+
* revisionHash: string,
5514+
* revisionUrl: string,
5515+
* branch: string,
5516+
* branchUrl: string,
5517+
* message: string,
5518+
* author: array{
5519+
* name: string,
5520+
* email: string,
5521+
* date: string
5522+
* },
5523+
* committer: array{
5524+
* name: string,
5525+
* email: string,
5526+
* date: string
5527+
* }
5528+
* }|null]]></code>
5529+
</MixedReturnTypeCoercion>
55195530
<PossiblyNullArgument>
55205531
<code><![CDATA[$commit[1]]]></code>
55215532
<code><![CDATA[$gitFolder]]></code>
@@ -12484,6 +12495,22 @@
1248412495
<code><![CDATA[$queryString]]></code>
1248512496
</MixedAssignment>
1248612497
</file>
12498+
<file src="tests/unit/GitTest.php">
12499+
<RedundantConditionGivenDocblockType>
12500+
<code><![CDATA[assertIsArray]]></code>
12501+
<code><![CDATA[assertIsArray]]></code>
12502+
<code><![CDATA[assertIsArray]]></code>
12503+
<code><![CDATA[assertIsBool]]></code>
12504+
<code><![CDATA[assertIsBool]]></code>
12505+
<code><![CDATA[assertIsString]]></code>
12506+
<code><![CDATA[assertIsString]]></code>
12507+
<code><![CDATA[assertIsString]]></code>
12508+
<code><![CDATA[assertIsString]]></code>
12509+
<code><![CDATA[assertIsString]]></code>
12510+
<code><![CDATA[assertIsString]]></code>
12511+
<code><![CDATA[assertIsString]]></code>
12512+
</RedundantConditionGivenDocblockType>
12513+
</file>
1248712514
<file src="tests/unit/HeaderTest.php">
1248812515
<DeprecatedMethod>
1248912516
<code><![CDATA[Config::getInstance()]]></code>

‎src/Command/WriteGitRevisionCommand.php‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
namespace PhpMyAdmin\Command;
66

7+
use PhpMyAdmin\Git;
78
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213

14+
use function addcslashes;
15+
use function explode;
1316
use function file_put_contents;
1417
use function is_string;
1518
use function shell_exec;
@@ -32,9 +35,21 @@ class WriteGitRevisionCommand extends Command
3235
*/
3336
return [
3437
'revision' => '%s',
38+
'revisionHash' => '%s',
3539
'revisionUrl' => '%s',
3640
'branch' => '%s',
3741
'branchUrl' => '%s',
42+
'message' => '%s',
43+
'author' => [
44+
'name' => '%s',
45+
'email' => '%s',
46+
'date' => '%s',
47+
],
48+
'committer' => [
49+
'name' => '%s',
50+
'email' => '%s',
51+
'date' => '%s',
52+
],
3853
];
3954

4055
PHP;
@@ -98,14 +113,31 @@ private function getRevisionInfo(string $commitUrlFormat, string $branchUrlForma
98113
return null;
99114
}
100115

101-
$branchName = trim(str_replace('refs/heads/', '', $branchName));
116+
$commitDetails = $this->gitCli(
117+
'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\'',
118+
);
119+
if ($commitDetails === null) {
120+
return null;
121+
}
122+
123+
$branchName = addcslashes(trim(str_replace('refs/heads/', '', $branchName)), "'");
124+
125+
[$author, $committer, $message] = Git::extractDataFormTextBody(explode("\n", $commitDetails));
102126

103127
return sprintf(
104128
self::$generatedClassTemplate,
105129
trim($revisionText),
130+
trim($commitHash),
106131
sprintf($commitUrlFormat, trim($commitHash)),
107-
trim($branchName),
132+
$branchName,
108133
sprintf($branchUrlFormat, $branchName),
134+
addcslashes(trim($message), "'"), // Commit message
135+
addcslashes($author['name'], "'"), // Author name
136+
addcslashes($author['email'], "'"), // Author email
137+
$author['date'], // Author date
138+
addcslashes($committer['name'], "'"), // Committer name
139+
addcslashes($committer['email'], "'"), // Committer email
140+
$committer['date'], // Committer date
109141
);
110142
}
111143

‎src/Footer.php‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Traversable;
1313

1414
use function basename;
15-
use function file_exists;
1615
use function in_array;
1716
use function is_array;
1817
use function is_object;
@@ -40,22 +39,6 @@ public function __construct(Template $template, private readonly Config $config)
4039
$this->scripts = new Scripts($template);
4140
}
4241

43-
/**
44-
* @return array<string, string>
45-
* @psalm-return array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]
46-
*/
47-
private function getGitRevisionInfo(): array
48-
{
49-
$info = [];
50-
51-
if (@file_exists(ROOT_PATH . 'revision-info.php')) {
52-
/** @psalm-suppress MissingFile,UnresolvableInclude */
53-
$info = include ROOT_PATH . 'revision-info.php';
54-
}
55-
56-
return is_array($info) ? $info : [];
57-
}
58-
5942
/**
6043
* Remove recursions and iterator objects from an object
6144
*
@@ -179,7 +162,8 @@ public function getDisplay(): array
179162
$scripts = $this->scripts->getDisplay();
180163

181164
if ($this->config->config->debug->demo) {
182-
$gitRevisionInfo = $this->getGitRevisionInfo();
165+
$git = new Git(true, ROOT_PATH);
166+
$gitRevisionInfo = $git->getGitRevisionInfo();
183167
}
184168

185169
$footer = Config::renderFooter();

0 commit comments

Comments
 (0)