Completed
Pull Request — master (#340)
by
unknown
05:30
created

WriteEntitySeeder::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 2
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Stream\Console\Command;
2
3
use Illuminate\Filesystem\Filesystem;
4
use Anomaly\Streams\Platform\Addon\Addon;
5
use Anomaly\Streams\Platform\Support\Parser;
6
7
/**
8
 * Class WriteEntitySeeder
9
 *
10
 * @author PyroCMS, Inc. <[email protected]>
11
 * @author Ryan Thompson <[email protected]>
12
 *
13
 * @link   http://pyrocms.com/
14
 */
15 View Code Duplication
class WriteEntitySeeder
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
18
    /**
19
     * The entity slug.
20
     *
21
     * @var string
22
     */
23
    private $slug;
24
25
    /**
26
     * The addon instance.
27
     *
28
     * @var Addon
29
     */
30
    private $addon;
31
32
    /**
33
     * The entity stream namespace.
34
     *
35
     * @var string
36
     */
37
    private $namespace;
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
        $entities = camel_case($this->slug);
62
        $suffix   = ucfirst($entities);
63
        $entity   = str_singular($suffix);
64
65
        $class     = "{$entity}Seeder";
66
        $namespace = $this->addon->getTransformedClass("{$entity}");
67
68
        $path = $this->addon->getPath("src/{$entity}/{$entity}Seeder.php");
69
70
        $template = $filesystem->get(
71
            base_path('vendor/anomaly/streams-platform/resources/stubs/entity/seeder.stub')
72
        );
73
74
        $filesystem->makeDirectory(dirname($path), 0755, true, true);
75
76
        $filesystem->put($path, $parser->parse(
77
            $template,
78
            compact('class', 'namespace', 'entity', 'entities')));
79
    }
80
}
81