Completed
Pull Request — master (#67)
by Vladimir
02:34
created

FileMapper::getObjectType()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 7
nop 1
1
<?php
2
3
namespace allejo\stakx;
4
5
use allejo\stakx\Document\ContentItem;
6
use allejo\stakx\Document\DataItem;
7
use allejo\stakx\Document\DynamicPageView;
8
use allejo\stakx\Document\ReadableDocument;
9
use allejo\stakx\Document\RepeaterPageView;
10
use allejo\stakx\Document\StaticPageView;
11
12
class FileMapper
13
{
14
    const UNKNOWN = -1;
15
16
    const CONTENT_ITEM = 0;
17
    const DATA_ITEM = 1;
18
19
    const BASE_PAGEVIEW = 2;
20
    const STATIC_PAGEVIEW = 3;
21
    const DYNAMIC_PAGEVIEW = 4;
22
    const REPEATER_PAGEVIEW = 5;
23
24
    const TWIG_INCLUDE = 6;
25
26
    private $templateIncludes = [];
27
    private $templateExtends = [];
28
    private $metadataMap = [];
29
    private $folderMap = [];
30
    private $fileMap = [];
31
32
    public function __construct()
33
    {
34
    }
35
36
    public function registerFile(ReadableDocument $file)
37
    {
38
        $relativePath = $file->getRelativeFilePath();
39
40
        $this->fileMap[$relativePath] = $this->getObjectType($file);
41
    }
42
43
    public function registerFolder($folder, $folderType)
44
    {
45
        $this->folderMap[$folder] = $folderType;
46
    }
47
48
    public function registerMetadata($key, $value)
49
    {
50
        $this->metadataMap[$key] = $value;
51
    }
52
53
    public function registerTemplateInclude($include, $file)
54
    {
55
        $this->templateIncludes[$include][] = $file;
56
    }
57
58
    public function registerTemplateExtend($extend, $file)
59
    {
60
        $this->templateExtends[$extend][] = $file;
61
    }
62
63
    private function getObjectType(ReadableDocument $file)
64
    {
65
        $objectType = get_class($file);
66
67
        switch ($objectType)
68
        {
69
            case ContentItem::class:
70
                return self::CONTENT_ITEM;
71
72
            case DataItem::class:
73
                return self::DATA_ITEM;
74
75
            case StaticPageView::class:
76
                return self::STATIC_PAGEVIEW;
77
78
            case DynamicPageView::class:
79
                return self::DYNAMIC_PAGEVIEW;
80
81
            case RepeaterPageView::class:
82
                return self::REPEATER_PAGEVIEW;
83
        }
84
85
        if ($file->getExtension() === "twig")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal twig does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
86
        {
87
            return self::TWIG_INCLUDE;
88
        }
89
90
        return self::UNKNOWN;
91
    }
92
}
93