-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsalm-schema
executable file
·69 lines (56 loc) · 2.19 KB
/
psalm-schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env php
<?php
declare(strict_types=1);
\error_reporting(-1);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/functions.php';
define('NS_XS', 'http://www.w3.org/2001/XMLSchema');
//******************************************************************************
// Update files
/**
* Firstly, run `make psalm` to fetch the latest Psalm schema.
*
* Next, this script will parse through the schema file to get a list of the
* "Issue Types" currently supported by Psalm. It will generate a new "template"
* file that is used for the `@@VENDOR@@` token in `psalm.xml`.
*
* This is to work around a bug where `vendor` is not ignored correctly despite
* a correct top-level definition.
*
* This hack is hopefully temporary.
*/
// Parse schema
$domDocument = new DOMDocument('1.0');
$domDocument->recover = true;
$domDocument->formatOutput = true;
$domDocument->preserveWhiteSpace = false;
$domDocument->resolveExternals = false;
$domDocument->substituteEntities = false;
$domDocument->strictErrorChecking = false;
$domDocument->validateOnParse = false;
$domDocument->load(__DIR__ . '/psalm-schema.xml');
$complexTypes = $domDocument->getElementsByTagNameNS(NS_XS, 'complexType');
$issueTypes = [];
foreach ($complexTypes as $complexType) {
if (count($complexType->attributes) > 0) {
if ('IssueHandlersType' === (string) $complexType->attributes->getNamedItem('name')->value) {
$elements = $complexType->getElementsByTagNameNS(NS_XS, 'element');
foreach ($elements as $element) {
if (count($element->attributes) > 0) {
$issueTypes[] = (string) $element->attributes->getNamedItem('name')->value;
}
}
}
}
}
$issueTypes = array_unique($issueTypes);
sort($issueTypes);
$template = [
' <!-- Psalm is broken and doesn\'t obey ignoring directories at the top level -->',
];
foreach ($issueTypes as $issueType) {
$template[] = <<<EOF
<{$issueType}><errorLevel type="suppress"><directory name="vendor" /></errorLevel></{$issueType}>
EOF;
}
file_put_contents(__DIR__ . '/templates/PSALM-VENDOR.tmpl', implode("\n", $template) . "\n");