These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Acacha\AdminLTETemplateLaravel\Console; |
||
4 | |||
5 | use League\Flysystem\Adapter\Local as LocalAdapter; |
||
6 | use League\Flysystem\Filesystem as Flysystem; |
||
7 | use League\Flysystem\MountManager; |
||
8 | |||
9 | /** |
||
10 | * Class Installable. |
||
11 | */ |
||
12 | trait Installable |
||
13 | { |
||
14 | /** |
||
15 | * Install files from array. |
||
16 | * |
||
17 | * @param $files |
||
18 | */ |
||
19 | private function install($files) |
||
20 | { |
||
21 | foreach ($files as $fileSrc => $fileDst) { |
||
22 | if (file_exists($fileDst) && !$this->force && !$this->confirmOverwrite(basename($fileDst))) { |
||
23 | return; |
||
24 | } |
||
25 | if ($this->files->isFile($fileSrc)) { |
||
26 | $this->publishFile($fileSrc, $fileDst); |
||
27 | } elseif ($this->files->isDirectory($fileSrc)) { |
||
28 | $this->publishDirectory($fileSrc, $fileDst); |
||
29 | } else { |
||
30 | $this->error("Can't locate path: <{$fileSrc}>"); |
||
0 ignored issues
–
show
|
|||
31 | } |
||
32 | } |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param $fileName |
||
37 | * @param string $prompt |
||
38 | * |
||
39 | * @return bool |
||
40 | */ |
||
41 | protected function confirmOverwrite($fileName, $prompt = '') |
||
42 | { |
||
43 | $prompt = (empty($prompt)) |
||
44 | ? $fileName.' already exists. Do you want to overwrite it? [y|N]' |
||
45 | : $prompt; |
||
46 | |||
47 | return $this->confirm($prompt, false); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Create the directory to house the published files if needed. |
||
52 | * |
||
53 | * @param string $directory |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | protected function createParentDirectory($directory) |
||
58 | { |
||
59 | if (!$this->files->isDirectory($directory)) { |
||
60 | $this->files->makeDirectory($directory, 0755, true); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Publish the file to the given path. |
||
66 | * |
||
67 | * @param string $from |
||
68 | * @param string $to |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | protected function publishFile($from, $to) |
||
73 | { |
||
74 | $this->createParentDirectory(dirname($to)); |
||
75 | $this->files->copy($from, $to); |
||
76 | $this->status($from, $to, 'File'); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Publish the directory to the given directory. |
||
81 | * |
||
82 | * @param string $from |
||
83 | * @param string $to |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | protected function publishDirectory($from, $to) |
||
88 | { |
||
89 | $manager = new MountManager([ |
||
90 | 'from' => new Flysystem(new LocalAdapter($from)), |
||
91 | 'to' => new Flysystem(new LocalAdapter($to)), |
||
92 | ]); |
||
93 | foreach ($manager->listContents('from://', true) as $file) { |
||
94 | if ($file['type'] === 'file' && (!$manager->has('to://'.$file['path']) || $this->force)) { |
||
95 | $manager->put('to://'.$file['path'], $manager->read('from://'.$file['path'])); |
||
96 | } |
||
97 | } |
||
98 | $this->status($from, $to, 'Directory'); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Write a status message to the console. |
||
103 | * |
||
104 | * @param string $from |
||
105 | * @param string $to |
||
106 | * @param string $type |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | protected function status($from, $to, $type) |
||
111 | { |
||
112 | $from = str_replace(base_path(), '', realpath($from)); |
||
113 | $to = str_replace(base_path(), '', realpath($to)); |
||
114 | $this->line('<info>Copied '. $type. '</info> <comment>['. $from. |
||
0 ignored issues
–
show
It seems like
line() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
115 | ']</comment> <info>To</info> <comment>['.$to.']</comment>'); |
||
116 | } |
||
117 | } |
||
118 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.