-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat-xml
executable file
·60 lines (47 loc) · 1.46 KB
/
format-xml
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
#! /usr/bin/env php
<?php
declare(strict_types=1);
\error_reporting(-1);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use Symfony\Component\Finder\Finder;
//******************************************************************************
// Update files
/**
* This will reformat the XML files and save the changes to disk.
*/
$__files__ = [
'pdepend.xml.dist',
'phpcs.xml',
'phpmd.xml.dist',
'phpunit.xml.dist',
];
foreach ($__files__ as $__f__) {
$finder = Finder::create()
->files()
->name($__f__)
->depth('< 2')
->in(dirname(__DIR__))
->notPath('vendor')
;
foreach ($finder as $file) {
$path = $file->getRealPath();
// First pass
$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($path);
$domDocument->save($path);
// Second pass
$content = file_get_contents($path);
$content = preg_replace('/>/i', '>', $content);
file_put_contents($path, $content);
echo sprintf('Completed %s', $path) . PHP_EOL;
}
unset($finder);
}