Markdown   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 34
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 6 1
A prepareSource() 0 4 2
A readFile() 0 4 1
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\base\Widget;
15
use Yii;
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