Completed
Push — master ( 76c23d...9a1475 )
by Andrii
02:13
created

Markdown::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Pluggable themes for Yii2.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-thememanager
6
 * @package   yii2-thememanager
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\thememanager\widgets;
12
13
use cebe\markdown\GithubMarkdown;
14
use Yii;
15
use yii\base\Widget;
16
17
/**
18
 * Markdown widget - renders markdown.
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class Markdown extends Widget
22
{
23
    /**
24
     * @var array options XXX ?
25
     */
26
    public $options = [];
27
28
    /**
29
     * @var string markdown source to render
30
     */
31
    public $source;
32
33
    /**
34
     * @var string markdown file to render
35
     */
36
    public $file;
37
38
    public function run()
39
    {
40
        $parser = new GithubMarkdown();
41
42
        return $parser->parse($this->prepareSource());
43
    }
44
45
    protected function prepareSource()
46
    {
47
        return $this->source ?: $this->readFile($this->file);
48
    }
49
50
    protected function readFile($file)
51
    {
52
        return file_get_contents(Yii::getAlias($file));
53
    }
54
}
55