Completed
Pull Request — master (#8)
by Dante
08:46 queued 03:04
created

ResourcesMigrationTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A fileName() 0 7 1
A template() 0 4 1
A bake() 0 12 1
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2020 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace BEdita\DevTools\Shell\Task;
14
15
use Cake\Utility\Inflector;
16
use Migrations\Shell\Task\SimpleMigrationTask;
17
use Phinx\Util\Util;
18
19
/**
20
 * Task class for generating resources migrations files.
21
 *
22
 * {@inheritDoc}
23
 */
24
class ResourcesMigrationTask extends SimpleMigrationTask
25
{
26
    /**
27
     * Main migration file name.
28
     *
29
     * @var string
30
     */
31
    protected $migrationFile = '';
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function name()
37
    {
38
        return 'resources_migration';
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function fileName($name)
45
    {
46
        $name = $this->getMigrationName($name);
47
        $this->migrationFile = Util::getCurrentTimestamp() . '_' . Inflector::camelize($name) . '.php';
48
49
        return $this->migrationFile;
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function template()
56
    {
57
        return 'BEdita/DevTools.resources';
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function bake($name)
64
    {
65
        // create .php file first, then .yml
66
        parent::bake($name);
67
68
        $contents = $this->BakeTemplate->generate('BEdita/DevTools.yaml');
69
70
        $filename = $this->getPath() . str_replace('.php', '.yml', $this->migrationFile);
71
        $this->createFile($filename, $contents);
72
73
        return $contents;
74
    }
75
}
76