maestriam /
samurai
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Maestriam\Samurai\Console; |
||||||
| 4 | |||||||
| 5 | use Exception; |
||||||
| 6 | use Maestriam\Samurai\Entities\Wizard; |
||||||
| 7 | use Maestriam\Samurai\Support\Samurai; |
||||||
| 8 | |||||||
| 9 | class InitThemeCommand extends BaseCommand |
||||||
| 10 | { |
||||||
| 11 | /** |
||||||
| 12 | * {@inheritDoc} |
||||||
| 13 | */ |
||||||
| 14 | protected $signature = 'samurai:init'; |
||||||
| 15 | |||||||
| 16 | /** |
||||||
| 17 | * {@inheritDoc} |
||||||
| 18 | */ |
||||||
| 19 | protected $description = 'Create a new theme using interactive mode'; |
||||||
| 20 | |||||||
| 21 | /** |
||||||
| 22 | * {@inheritDoc} |
||||||
| 23 | */ |
||||||
| 24 | protected string $successMessage = 'Theme [%s] created successful.'; |
||||||
| 25 | |||||||
| 26 | /** |
||||||
| 27 | * {@inheritDoc} |
||||||
| 28 | */ |
||||||
| 29 | protected string $errorMessage = 'Error to create theme: %s'; |
||||||
| 30 | |||||||
| 31 | /** |
||||||
| 32 | * Executa o comando de criação de componente atráves do Artisan |
||||||
| 33 | * |
||||||
| 34 | * @return void |
||||||
| 35 | */ |
||||||
| 36 | public function handle() |
||||||
| 37 | { |
||||||
| 38 | try { |
||||||
| 39 | |||||||
| 40 | $name = $this->askTheme(); |
||||||
| 41 | $author = $this->askAuthor(); |
||||||
| 42 | $descr = $this->askDescription(); |
||||||
| 43 | |||||||
| 44 | if (! $this->beSure($name, $author, $descr)) { |
||||||
| 45 | return false; |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | $theme = Samurai::theme($name); |
||||||
|
0 ignored issues
–
show
The method
theme() does not exist on Maestriam\Samurai\Support\Samurai. Since you implemented __callStatic, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 49 | |||||||
| 50 | $theme->author($author)->description($descr)->make(); |
||||||
| 51 | |||||||
| 52 | $this->clean(); |
||||||
| 53 | |||||||
| 54 | return $this->success($name); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 55 | |||||||
| 56 | } catch (Exception $e) { |
||||||
| 57 | return $this->failure($e); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 58 | } |
||||||
| 59 | } |
||||||
| 60 | |||||||
| 61 | /** |
||||||
| 62 | * Retorna o nome do vendor/tema escolhido pelo usuário |
||||||
| 63 | * |
||||||
| 64 | * @return string |
||||||
| 65 | */ |
||||||
| 66 | private function askTheme() : string |
||||||
| 67 | { |
||||||
| 68 | $question = $this->wizard()->theme(); |
||||||
| 69 | |||||||
| 70 | return $this->askFor($question); |
||||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | /** |
||||||
| 74 | * Retorna o autor do tema informado pelo usuário |
||||||
| 75 | * |
||||||
| 76 | * @return string |
||||||
| 77 | */ |
||||||
| 78 | private function askAuthor() : string |
||||||
| 79 | { |
||||||
| 80 | $question = $this->wizard()->author(); |
||||||
| 81 | |||||||
| 82 | return $this->askFor($question); |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | /** |
||||||
| 86 | * Retorna a descrição do tema informado pelo usuário |
||||||
| 87 | * |
||||||
| 88 | * @return string |
||||||
| 89 | */ |
||||||
| 90 | private function askDescription() : string |
||||||
| 91 | { |
||||||
| 92 | $question = $this->wizard()->description(); |
||||||
| 93 | |||||||
| 94 | return $this->askFor($question); |
||||||
| 95 | } |
||||||
| 96 | |||||||
| 97 | /** |
||||||
| 98 | * Retorna a resposta de uma pergunta feita para o usuário |
||||||
| 99 | * |
||||||
| 100 | * @param object $question |
||||||
| 101 | * @return string |
||||||
| 102 | */ |
||||||
| 103 | private function askFor(object $question) : string |
||||||
| 104 | { |
||||||
| 105 | $answer = $this->ask($question->ask); |
||||||
| 106 | |||||||
| 107 | return (! $answer || empty($answer)) ? $question->default : $answer; |
||||||
| 108 | } |
||||||
| 109 | |||||||
| 110 | /** |
||||||
| 111 | * Retorna se está de acordo para a criação do tema |
||||||
| 112 | * |
||||||
| 113 | * @param string $theme |
||||||
| 114 | * @param string $author |
||||||
| 115 | * @param string $desc |
||||||
| 116 | * @return boolean |
||||||
| 117 | */ |
||||||
| 118 | private function beSure(string $theme, string $author, string $desc) : bool |
||||||
| 119 | { |
||||||
| 120 | $question = $this->wizard()->confirm($theme, $author, $desc); |
||||||
| 121 | |||||||
| 122 | return $this->confirm($question->ask); |
||||||
| 123 | } |
||||||
| 124 | |||||||
| 125 | /** |
||||||
| 126 | * Retorna a instância do auxiliar com as perguntas do prompt e |
||||||
| 127 | * respostas padrão para a criação do tema. |
||||||
| 128 | * |
||||||
| 129 | * @return Wizard |
||||||
| 130 | */ |
||||||
| 131 | private function wizard() : Wizard |
||||||
| 132 | { |
||||||
| 133 | return Samurai::wizard(); |
||||||
|
0 ignored issues
–
show
The method
wizard() does not exist on Maestriam\Samurai\Support\Samurai. Since you implemented __callStatic, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 134 | } |
||||||
| 135 | } |
||||||
| 136 |