Completed
Push — master ( b68ec1...9e5bf9 )
by Cees-Jan
03:04
created

TwigTemplateTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 35
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A bake() 0 17 3
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
     * @return string Task name.
26
     */
27
    public function name(): string
28
    {
29
        return 'twig_template';
30
    }
31
32
    /**
33
     * Assembles and writes bakes the twig view file.
34
     *
35
     * @param  string $action  Action to bake.
36
     * @param  string $content Content to write.
37
     * @return string Generated file content.
38
     */
39 4
    public function bake($action, $content = ''): string
40
    {
41 4
        if ($content === true) {
42 4
            $content = $this->getContent($action);
43
        }
44 4
        if (empty($content)) {
45
            $this->err("<warning>No generated content for '{$action}.ctp', not generating template.</warning>");
46
47
            return false;
48
        }
49 4
        $this->out("\n" . sprintf('Baking `%s` view twig template file...', $action), 1, Shell::QUIET);
50 4
        $path = $this->getPath();
51 4
        $filename = $path . Inflector::underscore($action) . '.twig';
52 4
        $this->createFile($filename, $content);
53
54 4
        return $content;
55
    }
56
}
57