Completed
Push — 4.x ( 1463bf...41d78e )
by
unknown
13s
created

TwigTemplateTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 37
ccs 11
cts 15
cp 0.7332
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A bake() 0 20 4
1
<?php
2
3
/**
4
 * This file is part of TwigView.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Shell\Task;
12
13
use Bake\Shell\Task\TemplateTask;
14
use Cake\Console\Shell;
15
use Cake\Core\Configure;
16
use Cake\Utility\Inflector;
17
18
/**
19
 * Task class for creating and updating twig view template files.
20
 *
21
 */
22
class TwigTemplateTask extends TemplateTask
23
{
24
25
    public function name()
26
    {
27
        return 'twig_template';
28
    }
29
30
    /**
31
     * Assembles and writes bakes the twig view file.
32
     *
33
     * @param string $template Template to generate content with.
34
     * @param string $content Content to write.
35
     * @param string $outputFile The destination action name. If null, will fallback to $template.
36
     * @return string Generated file content.
37
     */
38 5
    public function bake($template, $content = '', $outputFile = null)
39
    {
40 5
        if ($outputFile === null) {
41 4
            $outputFile = $template;
42
        }
43 5
        if ($content === true) {
44 5
            $content = $this->getContent($template);
45
        }
46 5
        if (empty($content)) {
47
            $this->err("<warning>No generated content for '{$template}.ctp', not generating template.</warning>");
48
49
            return false;
50
        }
51 5
        $this->out("\n" . sprintf('Baking `%s` view twig template file...', $outputFile), 1, Shell::QUIET);
52 5
        $path = $this->getPath();
53 5
        $filename = $path . Inflector::underscore($outputFile) . '.twig';
54 5
        $this->createFile($filename, $content);
55
56 5
        return $content;
57
    }
58
}
59