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

WriteEntityFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 66
loc 66
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A handle() 20 20 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 WriteEntityFactory
9
 *
10
 * @link   http://pyrocms.com/
11
 * @author PyroCMS, Inc. <[email protected]>
12
 * @author Ryan Thompson <[email protected]>
13
 */
14 View Code Duplication
class WriteEntityFactory
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...
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 WriteEntityFactory 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}Model";
65
        $namespace = $this->addon->getTransformedClass("{$entity}");
66
67
        $model = $namespace . '\\' . $class;
68
69
        $path = $this->addon->getPath("factories/{$entity}Factory.php");
70
71
        $template = $filesystem->get(
72
            base_path("vendor/anomaly/streams-platform/resources/stubs/entity/factory.stub")
73
        );
74
75
        $filesystem->makeDirectory(dirname($path), 0755, true, true);
76
77
        $filesystem->put($path, $parser->parse($template, compact('model')));
78
    }
79
}
80