1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fixed duplicate shortcodes (#3996)

Also added an utility to help assign new shortcodes and a test to
prevent duplicate shortcodes.
This commit is contained in:
Bruce Weirdan 2020-08-16 23:26:54 +03:00 committed by GitHub
parent cb243778d2
commit 22d8f5a0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,16 @@
<?php
require_once(dirname(__DIR__) . '/vendor/autoload.php');
$issue_types = \Psalm\Config\IssueHandler::getAllIssueTypes();
$shortcodes = array_map(
function ($issue_type): int {
$issue_class = '\\Psalm\\Issue\\' . $issue_type;
/** @var int */
return $issue_class::SHORTCODE;
},
$issue_types
);
echo 'Max used shortcode: ' . max($shortcodes) . PHP_EOL;

View File

@ -4,5 +4,5 @@ namespace Psalm\Issue;
class InvalidExtendClass extends ClassIssue
{
const ERROR_LEVEL = -1;
const SHORTCODE = 7; // to be updated
const SHORTCODE = 232;
}

View File

@ -25,6 +25,8 @@ use function array_shift;
use DOMDocument;
use DOMXPath;
use DOMAttr;
use function array_filter;
use function var_export;
class DocumentationTest extends TestCase
{
@ -265,4 +267,30 @@ class DocumentationTest extends TestCase
return $invalid_code_data;
}
public function testShortcodesAreUnique(): void
{
$all_issues = \Psalm\Config\IssueHandler::getAllIssueTypes();
$all_shortcodes = [];
foreach ($all_issues as $issue_type) {
$issue_class = '\\Psalm\\Issue\\' . $issue_type;
/** @var int $shortcode */
$shortcode = $issue_class::SHORTCODE;
$all_shortcodes[$shortcode][] = $issue_type;
}
$duplicate_shortcodes = array_filter(
$all_shortcodes,
function ($issues) {
return count($issues) > 1;
}
);
$this->assertEquals(
[],
$duplicate_shortcodes,
"Duplicate shortcodes found: \n" . var_export($duplicate_shortcodes, true)
);
}
}