Completed
Pull Request — master (#58)
by
unknown
02:15
created

TwigTemplateTask::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php declare(strict_types=1);
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
12
namespace WyriHaximus\TwigView\Shell\Task;
13
14
use Bake\Shell\Task\TemplateTask;
15
use Cake\Console\Shell;
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
     * FIXME missing docblock.
26
     *
27
     * @return string Task name.
28
     */
29
    public function name(): string
30
    {
31
        return 'twig_template';
32
    }
33
34
    /**
35
     * Assembles and writes bakes the twig view file.
36
     *
37
     * @param  string $action  Action to bake.
38
     * @param  string $content Content to write.
39
     * @return string Generated file content.
40
     */
41 4
    public function bake($action, $content = ''): string
42
    {
43 4
        if ($content === true) {
44 4
            $content = $this->getContent($action);
45
        }
46 4
        if (empty($content)) {
47
            $this->err("<warning>No generated content for '{$action}.ctp', not generating template.</warning>");
48
49
            return false;
50
        }
51 4
        $this->out("\n" . sprintf('Baking `%s` view twig template file...', $action), 1, Shell::QUIET);
52 4
        $path = $this->getPath();
53 4
        $filename = $path . Inflector::underscore($action) . '.twig';
54 4
        $this->createFile($filename, $content);
55
56 4
        return $content;
57
    }
58
}
59