Passed
Push — master ( 2ab0f7...e831fb )
by Bruno
09:21
created

validators()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 20
rs 10
1
<?php declare(strict_types=1);
2
3
require('vendor/autoload.php');
4
5
use Formularium\Element;
6
use Formularium\Formularium;
7
use HaydenPierce\ClassFinder\ClassFinder;
8
9
use function Safe\file_put_contents;
10
11
function validators()
12
{
13
    $validators = Formularium::getValidatorNames();
14
15
    $markdown = [];
16
17
    foreach ($validators as $className => $name) {
18
        $markdown[$name] = $className::getMetadata()->toMarkdown();
19
    }
20
21
    ksort($markdown);
22
23
    $validatorAPI = '
24
# Validators
25
26
List of validators and its parameters generated automatically.
27
28
' . join("\n", $markdown);
29
30
    file_put_contents(__DIR__ . '/../docs/api-validators.md', $validatorAPI);
31
}
32
33
function datatypes()
34
{
35
    $datatypes = Formularium::getDatatypeNames();
0 ignored issues
show
Unused Code introduced by
The assignment to $datatypes is dead and can be removed.
Loading history...
36
37
    $markdown = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $markdown is dead and can be removed.
Loading history...
38
}
39
40
function elements()
41
{
42
    $frameworks = [
43
        'Bootstrap',
44
        'Buefy',
45
        'Bulma',
46
        'HTML',
47
        'Materialize'
48
    ];
49
50
    foreach ($frameworks as $framework) {
51
        $markdown = [];
52
        $ns = "Formularium\\Frontend\\$framework\\Element";
53
54
        /** @var array<class-string> $classesInNamespace */
55
        $classesInNamespace = ClassFinder::getClassesInNamespace($ns);
56
57
        foreach ($classesInNamespace as $className) {
58
            $reflection = new \ReflectionClass($className);
59
            if (!$reflection->isInstantiable()) {
60
                continue;
61
            }
62
63
            if (!is_a($className, Element::class, true)) {
64
                continue;
65
            }
66
67
            $metadata = $className::getMetadata();
68
            
69
            $markdown[$metadata->name] = $metadata->toMarkdown();
70
        }
71
        ksort($markdown);
72
73
        $elementAPI = "
74
# Elements for $framework
75
76
List of elements for $framework and its parameters.
77
78
" . join("\n", $markdown);
79
        
80
        file_put_contents(__DIR__ . "'/../docs/api-$framework-elements.md", $elementAPI);
81
    }
82
}
83
84
validators();
85
elements();
86