Publisher::hideMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Consigliere\Components\Publishing;
4
5
use Illuminate\Console\Command;
6
use Consigliere\Components\Contracts\PublisherInterface;
7
use Consigliere\Components\Component;
8
use Consigliere\Components\Repository;
9
10
abstract class Publisher implements PublisherInterface
11
{
12
    /**
13
     * The name of component will used.
14
     *
15
     * @var string
16
     */
17
    protected $component;
18
19
    /**
20
     * The components repository instance.
21
     *
22
     * @var \Consigliere\Components\Repository
23
     */
24
    protected $repository;
25
26
    /**
27
     * The laravel console instance.
28
     *
29
     * @var \Illuminate\Console\Command
30
     */
31
    protected $console;
32
33
    /**
34
     * The success message will displayed at console.
35
     *
36
     * @var string
37
     */
38
    protected $success;
39
40
    /**
41
     * The error message will displayed at console.
42
     *
43
     * @var string
44
     */
45
    protected $error = '';
46
47
    /**
48
     * Determine whether the result message will shown in the console.
49
     *
50
     * @var bool
51
     */
52
    protected $showMessage = true;
53
54
    /**
55
     * The constructor.
56
     *
57
     * @param Component $component
58
     */
59
    public function __construct(Component $component)
60
    {
61
        $this->component = $component;
0 ignored issues
show
Documentation Bug introduced by
It seems like $component of type object<Consigliere\Components\Component> is incompatible with the declared type string of property $component.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
    }
63
64
    /**
65
     * Show the result message.
66
     *
67
     * @return self
68
     */
69
    public function showMessage()
70
    {
71
        $this->showMessage = true;
72
73
        return $this;
74
    }
75
76
    /**
77
     * Hide the result message.
78
     *
79
     * @return self
80
     */
81
    public function hideMessage()
82
    {
83
        $this->showMessage = false;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Get component instance.
90
     *
91
     * @return \Consigliere\Components\Component
92
     */
93
    public function getComponent()
94
    {
95
        return $this->component;
96
    }
97
98
    /**
99
     * Set components repository instance.
100
     *
101
     * @param \Consigliere\Components\Repository $repository
102
     *
103
     * @return $this
104
     */
105
    public function setRepository(Repository $repository)
106
    {
107
        $this->repository = $repository;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Get components repository instance.
114
     *
115
     * @return \Consigliere\Components\Repository
116
     */
117
    public function getRepository()
118
    {
119
        return $this->repository;
120
    }
121
122
    /**
123
     * Set console instance.
124
     *
125
     * @param \Illuminate\Console\Command $console
126
     *
127
     * @return $this
128
     */
129
    public function setConsole(Command $console)
130
    {
131
        $this->console = $console;
132
133
        return $this;
134
    }
135
136
    /**
137
     * Get console instance.
138
     *
139
     * @return \Illuminate\Console\Command
140
     */
141
    public function getConsole()
142
    {
143
        return $this->console;
144
    }
145
146
    /**
147
     * Get laravel filesystem instance.
148
     *
149
     * @return \Illuminate\Filesystem\Filesystem
150
     */
151
    public function getFilesystem()
152
    {
153
        return $this->repository->getFiles();
154
    }
155
156
    /**
157
     * Get destination path.
158
     *
159
     * @return string
160
     */
161
    abstract public function getDestinationPath();
162
163
    /**
164
     * Get source path.
165
     *
166
     * @return string
167
     */
168
    abstract public function getSourcePath();
169
170
    /**
171
     * Publish something.
172
     */
173
    public function publish()
174
    {
175
        if (!$this->console instanceof Command) {
176
            $message = "The 'console' property must instance of \\Illuminate\\Console\\Command.";
177
178
            throw new \RuntimeException($message);
179
        }
180
181
        if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) {
182
            return;
183
        }
184
185
        if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) {
186
            $this->getFilesystem()->makeDirectory($destinationPath, 0775, true);
187
        }
188
189
        if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) {
190
            if ($this->showMessage === true) {
191
                $this->console->line("<info>Published</info>: {$this->component->getStudlyName()}");
0 ignored issues
show
Bug introduced by
The method getStudlyName cannot be called on $this->component (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
192
            }
193
        } else {
194
            $this->console->error($this->error);
195
        }
196
    }
197
}
198