Completed
Push — master ( 98a062...441031 )
by Ryan
10:10
created

WriteEntitySeeder::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Stream\Console\Command;
2
3
use Anomaly\Streams\Platform\Addon\Addon;
4
use Anomaly\Streams\Platform\Support\Parser;
5
use Illuminate\Filesystem\Filesystem;
6
7
/**
8
 * Class WriteEntitySeeder
9
 *
10
 * @link   http://pyrocms.com/
11
 * @author PyroCMS, Inc. <[email protected]>
12
 * @author Ryan Thompson <[email protected]>
13
 */
14
class WriteEntitySeeder
15
{
16
17
    /**
18
     * The entity slug.
19
     *
20
     * @var string
21
     */
22
    private $slug;
23
24
    /**
25
     * The addon instance.
26
     *
27
     * @var Addon
28
     */
29
    private $addon;
30
31
    /**
32
     * The entity stream namespace.
33
     *
34
     * @var string
35
     */
36
    private $namespace;
37
38
39
    /**
40
     * Create a new WriteEntitySeeder instance.
41
     *
42
     * @param Addon $addon
43
     * @param       $slug
44
     * @param       $namespace
45
     */
46
    public function __construct(Addon $addon, $slug, $namespace)
47
    {
48
        $this->slug      = $slug;
49
        $this->addon     = $addon;
50
        $this->namespace = $namespace;
51
    }
52
53
    /**
54
     * Handle the command.
55
     *
56
     * @param Parser     $parser
57
     * @param Filesystem $filesystem
58
     */
59
    public function handle(Parser $parser, Filesystem $filesystem)
60
    {
61
        $suffix = ucfirst(camel_case($this->slug));
62
        $entity = str_singular($suffix);
63
64
        $class     = "{$entity}Seeder";
65
        $namespace = $this->addon->getTransformedClass("{$entity}");
66
67
        $path = $this->addon->getPath("src/{$entity}/{$entity}Seeder.php");
68
69
        $template = $filesystem->get(
70
            base_path("vendor/anomaly/streams-platform/resources/stubs/entity/seeder.stub")
71
        );
72
73
        $filesystem->makeDirectory(dirname($path), 0755, true, true);
74
75
        $filesystem->put($path, $parser->parse($template, compact('class', 'namespace')));
76
    }
77
}
78