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:
parent
cb243778d2
commit
22d8f5a0bc
16
bin/max_used_shortcode.php
Normal file
16
bin/max_used_shortcode.php
Normal 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;
|
@ -4,5 +4,5 @@ namespace Psalm\Issue;
|
||||
class InvalidExtendClass extends ClassIssue
|
||||
{
|
||||
const ERROR_LEVEL = -1;
|
||||
const SHORTCODE = 7; // to be updated
|
||||
const SHORTCODE = 232;
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user