1616use Symfony \Component \Console \Attribute \AsCommand ;
1717use Symfony \Component \Console \Command \Command ;
1818use Symfony \Component \Console \Exception \RuntimeException ;
19+ use Symfony \Component \Console \Helper \QuestionHelper ;
1920use Symfony \Component \Console \Input \InputArgument ;
2021use Symfony \Component \Console \Input \InputInterface ;
2122use Symfony \Component \Console \Input \InputOption ;
@@ -30,33 +31,14 @@ final class DeployRsyncCommand extends Command
3031 public const TARGET_SSH_REGEX = '/^ssh:\/\/(?<username>.+)@(?<hostname>[^:]+)(:(?<port>\d+)){0,1}:(?<path>.+)$/ ' ;
3132
3233 /**
33- * @var array
34+ * @param array<string, array{target: string, rsync_options?: string[], ignore_file?: string}> $environments
35+ * @param array{rsync_path: string, rsync_options: string[], ignore_file: ?string} $rsyncConfig
3436 */
35- protected $ environments ;
36-
37- /**
38- * @var array
39- */
40- protected $ rsyncConfig ;
41-
42- /**
43- * @var string
44- */
45- protected $ projetDir ;
46-
47- public function __construct (array $ environments , array $ rsyncConfig , string $ projetDir )
37+ public function __construct (protected array $ environments , protected array $ rsyncConfig , protected string $ projetDir )
4838 {
49- $ this ->environments = $ environments ;
50- $ this ->rsyncConfig = $ rsyncConfig ;
51- $ this ->projetDir = $ projetDir ;
52-
5339 parent ::__construct ();
5440 }
5541
56- protected static $ defaultName = 'ecommit:deploy-rsync ' ; // PHP < 8
57-
58- protected static $ defaultDescription = 'Deploy the application with RSYNC and SSH ' ; // PHP < 8
59-
6042 protected function configure (): void
6143 {
6244 $ this
@@ -67,13 +49,16 @@ protected function configure(): void
6749
6850 protected function execute (InputInterface $ input , OutputInterface $ output ): int
6951 {
70- if (!\array_key_exists ($ input ->getArgument ('environment ' ), $ this ->environments )) {
71- throw new RuntimeException ('Environment not found: ' .$ input ->getArgument ('environment ' ));
52+ /** @var string $environmentName */
53+ $ environmentName = $ input ->getArgument ('environment ' );
54+ if (!\array_key_exists ($ environmentName , $ this ->environments )) {
55+ throw new RuntimeException ('Environment not found: ' .$ environmentName );
7256 }
73- $ environment = $ this ->environments [$ input -> getArgument ( ' environment ' ) ];
57+ $ environment = $ this ->environments [$ environmentName ];
7458
7559 $ ignoreFile = $ environment ['ignore_file ' ] ?? $ this ->rsyncConfig ['ignore_file ' ];
7660 if (!$ ignoreFile ) {
61+ /** @var QuestionHelper $helper */
7762 $ helper = $ this ->getHelper ('question ' );
7863 $ question = new ConfirmationQuestion ('Continue without ignore file? [y/N] ' , false );
7964
@@ -123,12 +108,18 @@ protected function getDirPath(string $dir): string
123108 return $ dir ;
124109 }
125110
126- protected function executeProcess (array $ command ): \Iterator
111+ /**
112+ * @param string[] $command
113+ *
114+ * @return \Generator<array-key, string>
115+ */
116+ protected function executeProcess (array $ command ): \Generator
127117 {
128118 $ process = $ this ->createProcess ($ command );
129119 $ process ->start ();
130120
131- foreach ($ process as $ type => $ data ) {
121+ /** @var string $data */
122+ foreach ($ process as $ data ) {
132123 yield $ data ;
133124 }
134125
@@ -137,6 +128,9 @@ protected function executeProcess(array $command): \Iterator
137128 }
138129 }
139130
131+ /**
132+ * @param string[] $command
133+ */
140134 protected function createProcess (array $ command ): Process
141135 {
142136 return new Process ($ command );
0 commit comments