-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateClassifier.php
More file actions
39 lines (30 loc) · 961 Bytes
/
TemplateClassifier.php
File metadata and controls
39 lines (30 loc) · 961 Bytes
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
<?php
declare(strict_types=1);
namespace TwigA11y\Template;
final class TemplateClassifier
{
public static function classify(string $content): TemplateKind
{
$hasExtends = str_contains($content, '{% extends');
$hasBlock = str_contains($content, '{% block');
$hasHtml = false !== stripos($content, '<html');
$hasBody = false !== stripos($content, '<body');
$hasProps = str_contains($content, '{% props');
if ($hasProps) {
return TemplateKind::TwigUxComponent;
}
if ($hasExtends && $hasBlock) {
return TemplateKind::MixedTemplate;
}
if ($hasExtends) {
return TemplateKind::ChildTemplate;
}
if ($hasBlock && !$hasHtml) {
return TemplateKind::ParentTemplate;
}
if ($hasHtml && $hasBody) {
return TemplateKind::FullPage;
}
return TemplateKind::Partial;
}
}