Skip to content

Commit

Permalink
Merge branch 'QA_5_2'
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <[email protected]>
  • Loading branch information
williamdes committed Dec 19, 2024
2 parents 51868a0 + 18f8ae0 commit 8e72191
Show file tree
Hide file tree
Showing 8 changed files with 530 additions and 88 deletions.
4 changes: 4 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
<file>./tests</file>
<file>./config.sample.inc.php</file>

<!-- Make sniff report relative -->
<arg name="basepath" value="."/>

<exclude-pattern>*/app/cache/*</exclude-pattern>
<exclude-pattern>*/app/language_stats.inc.php</exclude-pattern>
<exclude-pattern>*/build/*</exclude-pattern>
<exclude-pattern>*/config.inc.php</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/tests/doctum-config.php</exclude-pattern>
<exclude-pattern>*/revision-info.php</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
<exclude-pattern>*/twig-templates/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
Expand Down
82 changes: 74 additions & 8 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8535,12 +8535,6 @@ parameters:
count: 2
path: src/Footer.php

-
message: '#^Method PhpMyAdmin\\Footer\:\:getGitRevisionInfo\(\) should return array\<string, string\> but returns array\<mixed\>\.$#'
identifier: return.type
count: 1
path: src/Footer.php

-
message: '#^Only booleans are allowed in &&, array\<mixed, mixed\>\|object given on the right side\.$#'
identifier: booleanAnd.rightNotBoolean
Expand Down Expand Up @@ -9172,7 +9166,7 @@ parameters:
path: src/Git.php

-
message: '#^Parameter \#1 \$commit of method PhpMyAdmin\\Git\:\:extractDataFormTextBody\(\) expects array\<mixed\>, mixed given\.$#'
message: '#^Parameter \#1 \$commit of static method PhpMyAdmin\\Git\:\:extractDataFormTextBody\(\) expects array\<string\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Git.php
Expand Down Expand Up @@ -9214,7 +9208,7 @@ parameters:
path: src/Git.php

-
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Git.php
Expand Down Expand Up @@ -21000,6 +20994,78 @@ parameters:
count: 1
path: tests/unit/Gis/GisPolygonTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\) with array\{name\: string, email\: string, date\: string\} will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/unit/GitTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsBool\(\) with bool will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 2
path: tests/unit/GitTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsString\(\) with string will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 7
path: tests/unit/GitTest.php

-
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\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: tests/unit/GitTest.php

-
message: '''
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
Expand Down
47 changes: 37 additions & 10 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5156,13 +5156,8 @@
<code><![CDATA[$params]]></code>
</InvalidArgument>
<MixedAssignment>
<code><![CDATA[$info]]></code>
<code><![CDATA[$subObject]]></code>
</MixedAssignment>
<MixedReturnTypeCoercion>
<code><![CDATA[array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]]]></code>
<code><![CDATA[is_array($info) ? $info : []]]></code>
</MixedReturnTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$object]]></code>
<code><![CDATA[empty($_REQUEST['no_debug'])]]></code>
Expand Down Expand Up @@ -5474,16 +5469,11 @@
<MixedArgument>
<code><![CDATA[$commit]]></code>
<code><![CDATA[$commitJson->message]]></code>
<code><![CDATA[$dataline]]></code>
<code><![CDATA[$offset + ($position * 20)]]></code>
<code><![CDATA[$offset + ($position * 4)]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$commit]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$commit]]></code>
<code><![CDATA[$dataline]]></code>
<code><![CDATA[$end]]></code>
<code><![CDATA[$gitLocation]]></code>
<code><![CDATA[$offset]]></code>
Expand Down Expand Up @@ -5516,6 +5506,27 @@
<code><![CDATA[$packOffsets[1]]]></code>
<code><![CDATA[json_decode((string) $isFound)]]></code>
</MixedReturnStatement>
<MixedReturnTypeCoercion>
<code><![CDATA[$info]]></code>
<code><![CDATA[array{
* revision: string,
* revisionHash: string,
* revisionUrl: string,
* branch: string,
* branchUrl: string,
* message: string,
* author: array{
* name: string,
* email: string,
* date: string
* },
* committer: array{
* name: string,
* email: string,
* date: string
* }
* }|null]]></code>
</MixedReturnTypeCoercion>
<PossiblyNullArgument>
<code><![CDATA[$commit[1]]]></code>
<code><![CDATA[$gitFolder]]></code>
Expand Down Expand Up @@ -12484,6 +12495,22 @@
<code><![CDATA[$queryString]]></code>
</MixedAssignment>
</file>
<file src="tests/unit/GitTest.php">
<RedundantConditionGivenDocblockType>
<code><![CDATA[assertIsArray]]></code>
<code><![CDATA[assertIsArray]]></code>
<code><![CDATA[assertIsArray]]></code>
<code><![CDATA[assertIsBool]]></code>
<code><![CDATA[assertIsBool]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
<code><![CDATA[assertIsString]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="tests/unit/HeaderTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down
36 changes: 34 additions & 2 deletions src/Command/WriteGitRevisionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace PhpMyAdmin\Command;

use PhpMyAdmin\Git;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function addcslashes;
use function explode;
use function file_put_contents;
use function is_string;
use function shell_exec;
Expand All @@ -32,9 +35,21 @@ class WriteGitRevisionCommand extends Command
*/
return [
'revision' => '%s',
'revisionHash' => '%s',
'revisionUrl' => '%s',
'branch' => '%s',
'branchUrl' => '%s',
'message' => '%s',
'author' => [
'name' => '%s',
'email' => '%s',
'date' => '%s',
],
'committer' => [
'name' => '%s',
'email' => '%s',
'date' => '%s',
],
];

PHP;
Expand Down Expand Up @@ -98,14 +113,31 @@ private function getRevisionInfo(string $commitUrlFormat, string $branchUrlForma
return null;
}

$branchName = trim(str_replace('refs/heads/', '', $branchName));
$commitDetails = $this->gitCli(
'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\'',
);
if ($commitDetails === null) {
return null;
}

$branchName = addcslashes(trim(str_replace('refs/heads/', '', $branchName)), "'");

Check warning on line 123 in src/Command/WriteGitRevisionCommand.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ if ($commitDetails === null) { return null; } - $branchName = addcslashes(trim(str_replace('refs/heads/', '', $branchName)), "'"); + $branchName = addcslashes(str_replace('refs/heads/', '', $branchName), "'"); [$author, $committer, $message] = Git::extractDataFormTextBody(explode("\n", $commitDetails)); return sprintf( self::$generatedClassTemplate,

[$author, $committer, $message] = Git::extractDataFormTextBody(explode("\n", $commitDetails));

return sprintf(
self::$generatedClassTemplate,
trim($revisionText),
trim($commitHash),

Check warning on line 130 in src/Command/WriteGitRevisionCommand.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ return sprintf( self::$generatedClassTemplate, trim($revisionText), - trim($commitHash), + $commitHash, sprintf($commitUrlFormat, trim($commitHash)), $branchName, sprintf($branchUrlFormat, $branchName),
sprintf($commitUrlFormat, trim($commitHash)),
trim($branchName),
$branchName,
sprintf($branchUrlFormat, $branchName),
addcslashes(trim($message), "'"), // Commit message

Check warning on line 134 in src/Command/WriteGitRevisionCommand.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ sprintf($commitUrlFormat, trim($commitHash)), $branchName, sprintf($branchUrlFormat, $branchName), - addcslashes(trim($message), "'"), + addcslashes($message, "'"), // Commit message addcslashes($author['name'], "'"), // Author name
addcslashes($author['name'], "'"), // Author name
addcslashes($author['email'], "'"), // Author email
$author['date'], // Author date
addcslashes($committer['name'], "'"), // Committer name
addcslashes($committer['email'], "'"), // Committer email
$committer['date'], // Committer date
);
}

Expand Down
20 changes: 2 additions & 18 deletions src/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Traversable;

use function basename;
use function file_exists;
use function in_array;
use function is_array;
use function is_object;
Expand Down Expand Up @@ -40,22 +39,6 @@ public function __construct(Template $template, private readonly Config $config)
$this->scripts = new Scripts($template);
}

/**
* @return array<string, string>
* @psalm-return array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]
*/
private function getGitRevisionInfo(): array
{
$info = [];

if (@file_exists(ROOT_PATH . 'revision-info.php')) {
/** @psalm-suppress MissingFile,UnresolvableInclude */
$info = include ROOT_PATH . 'revision-info.php';
}

return is_array($info) ? $info : [];
}

/**
* Remove recursions and iterator objects from an object
*
Expand Down Expand Up @@ -179,7 +162,8 @@ public function getDisplay(): array
$scripts = $this->scripts->getDisplay();

if ($this->config->config->debug->demo) {
$gitRevisionInfo = $this->getGitRevisionInfo();
$git = new Git(true, ROOT_PATH);
$gitRevisionInfo = $git->getGitRevisionInfo();
}

$footer = Config::renderFooter();
Expand Down
Loading

0 comments on commit 8e72191

Please sign in to comment.