Skip to content

Commit e31c82d

Browse files
committed
Added a tool to find missing tags.
1 parent 7e7507e commit e31c82d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tools/detect-missing-tags.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CPMDB\Tools;
6+
7+
use AppUtils\FileHelper\FolderInfo;
8+
use CPMDB\Mods\Collection\ModCollection;
9+
use CPMDB\Mods\Tags\TagCollection;
10+
11+
require_once __DIR__.'/../vendor/autoload.php';
12+
13+
$collection = ModCollection::create(
14+
FolderInfo::factory(__DIR__.'/../vendor'),
15+
FolderInfo::factory(__DIR__.'/../tests/cache'),
16+
''
17+
);
18+
19+
$allTagNames = array();
20+
foreach($collection->getAll() as $mod) {
21+
array_push($allTagNames, ...$mod->getTags());
22+
}
23+
24+
$allTagNames = array_unique($allTagNames);
25+
$collection = TagCollection::getInstance();
26+
$missing = array();
27+
28+
foreach($allTagNames as $tagName) {
29+
if(!$collection->idExists($tagName)) {
30+
$missing[] = $tagName;
31+
echo 'Missing tag: '.$tagName.PHP_EOL;
32+
}
33+
}
34+
35+
$template = <<<'PHP'
36+
<?php
37+
38+
declare(strict_types=1);
39+
40+
namespace CPMDB\Mods\Tags\Types;
41+
42+
use CPMDB\Mods\Tags\Categories\GeneralTagInfo;
43+
44+
class %2$s extends GeneralTagInfo
45+
{
46+
public const TAG_NAME = '%1$s';
47+
48+
protected function _getName(): string
49+
{
50+
return self::TAG_NAME;
51+
}
52+
53+
public function getLabel(): string
54+
{
55+
return '%1$s';
56+
}
57+
}
58+
59+
PHP;
60+
61+
foreach($missing as $tagID) {
62+
$className = str_replace('-', '', $tagID);
63+
64+
$content = sprintf(
65+
$template,
66+
$tagID,
67+
$className
68+
);
69+
70+
file_put_contents(__DIR__.'/../src/Mods/Tags/Types/'.$className.'.php', $content);
71+
}

0 commit comments

Comments
 (0)