Completed
Push — master ( 6054a8...c11aa8 )
by Kacper
04:06
created

Language::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
namespace Kadet\Highlighter\Language;
16
17
use Kadet\Highlighter\KeyLighter;
18
use Kadet\Highlighter\Parser\Rule;
19
use Kadet\Highlighter\Parser\Tokens;
20
21
22
/**
23
 * Class Language
24
 *
25
 * @package Kadet\Highlighter\Language
26
 */
27
abstract class Language
28
{
29
    const EMBEDDED_BY_PARENT = 2;
30
    const EMBEDDED           = true;
31
    const NOT_EMBEDDED       = false;
32
33
    /**
34
     * Parses source and removes wrong tokens.
35
     *
36
     * @param Tokens|string $tokens
37
     *
38
     * @param array                $additional
39
     * @param bool                 $embedded
40
     *
41
     * @return Tokens
42
     */
43
    public abstract function parse($tokens = null, $additional = [], $embedded = false);
44
45
    public abstract function tokenize($source, $additional = [], $offset = 0, $embedded = false);
46
47
    /**
48
     * Unique language identifier, for example 'php'
49
     *
50
     * @return string
51
     */
52
    public abstract function getIdentifier();
53
54
    /**
55
     * Language range Rule(s)
56
     *
57
     * @param $embedded
58
     *
59
     * @return Rule|\Kadet\Highlighter\Parser\Rule[]
60
     */
61
    public abstract function getEnds($embedded = false);
62
63
    /**
64
     * @return Language[]
65
     */
66
    public abstract function getEmbedded();
67
68
    /**
69
     * @param Language $lang
70
     */
71
    public abstract function embed(Language $lang);
72
73 1
    public static function byName($name, $params = [])
74
    {
75 1
        return KeyLighter::get()->languageByName($name, $params);
76
    }
77
78 1
    public static function byMime($mime, $params = [])
79
    {
80 1
        return KeyLighter::get()->languageByMime($mime, $params);
81
    }
82
83 1
    public static function byFilename($filename, $params = [])
84
    {
85 1
        return KeyLighter::get()->languageByExt($filename, $params);
86
    }
87
88 5
    public final function getFQN($class = false)
89
    {
90 5
        $embedded =$this->getEmbedded();
91 5
        return  ($class ? get_class($this) : $this->getIdentifier()).(
92
            !empty($embedded)
93
                ? ' + '.implode(', ', array_map($class ? 'get_class' : function(Language $e) { return $e->getIdentifier(); }, $embedded))
94 1
                : ''
95 5
        );
96
    }
97
98
    /**
99
     * Aliases of given language, used for aliases.php file generation.
100
     *
101
     * @return array
102
     *
103
     * @codeCoverageIgnore
104
     */
105
    public static function getMetadata()
106
    {
107
        return [
108
            'name'      => [],
109
            'mime'      => [],
110
            'extension' => [],
111
            'standalone' => true,
112
            'injectable' => false
113
        ];
114
    }
115
}
116