33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Deploy \Console ;
78
8- use Magento \ Setup \ Console \ Command \ DeployStaticContentCommand ;
9+ use InvalidArgumentException ;
910use Magento \Deploy \Console \DeployStaticOptions as Options ;
10- use Magento \Framework \Validator \Locale ;
11- use Symfony \Component \Console \Input \InputInterface ;
1211use Magento \Framework \App \ObjectManager ;
12+ use Magento \Framework \Validator \Locale ;
1313use Magento \Framework \Validator \RegexFactory ;
14+ use Symfony \Component \Console \Input \InputInterface ;
15+ use function array_key_exists ;
1416
1517/**
1618 * Command input arguments validator class
@@ -66,7 +68,7 @@ class InputValidator
6668 * InputValidator constructor
6769 *
6870 * @param Locale $localeValidator
69- * @param RegexFactory $versionValidatorFactory
71+ * @param RegexFactory|null $versionValidatorFactory
7072 */
7173 public function __construct (
7274 Locale $ localeValidator ,
@@ -100,6 +102,10 @@ public function validate(InputInterface $input)
100102 $ this ->checkVersionInput (
101103 $ input ->getOption (Options::CONTENT_VERSION ) ?: ''
102104 );
105+ $ this ->checkNoParentInput (
106+ (bool )$ input ->getOption (Options::NO_PARENT ),
107+ (string )$ input ->getOption (Options::STRATEGY )
108+ );
103109 }
104110
105111 /**
@@ -108,12 +114,12 @@ public function validate(InputInterface $input)
108114 * @param array $areasInclude
109115 * @param array $areasExclude
110116 * @return void
111- * @throws \ InvalidArgumentException
117+ * @throws InvalidArgumentException
112118 */
113119 private function checkAreasInput (array $ areasInclude , array $ areasExclude )
114120 {
115- if ($ areasInclude [0 ] != 'all ' && $ areasExclude [0 ] != 'none ' ) {
116- throw new \ InvalidArgumentException (
121+ if ($ areasInclude [0 ] !== 'all ' && $ areasExclude [0 ] != = 'none ' ) {
122+ throw new InvalidArgumentException (
117123 '--area (-a) and --exclude-area cannot be used at the same time '
118124 );
119125 }
@@ -125,12 +131,12 @@ private function checkAreasInput(array $areasInclude, array $areasExclude)
125131 * @param array $themesInclude
126132 * @param array $themesExclude
127133 * @return void
128- * @throws \ InvalidArgumentException
134+ * @throws InvalidArgumentException
129135 */
130136 private function checkThemesInput (array $ themesInclude , array $ themesExclude )
131137 {
132- if ($ themesInclude [0 ] != 'all ' && $ themesExclude [0 ] != 'none ' ) {
133- throw new \ InvalidArgumentException (
138+ if ($ themesInclude [0 ] !== 'all ' && $ themesExclude [0 ] != = 'none ' ) {
139+ throw new InvalidArgumentException (
134140 '--theme (-t) and --exclude-theme cannot be used at the same time '
135141 );
136142 }
@@ -142,21 +148,21 @@ private function checkThemesInput(array $themesInclude, array $themesExclude)
142148 * @param array $languagesInclude
143149 * @param array $languagesExclude
144150 * @return void
145- * @throws \ InvalidArgumentException
151+ * @throws InvalidArgumentException
146152 */
147153 private function checkLanguagesInput (array $ languagesInclude , array $ languagesExclude )
148154 {
149- if ($ languagesInclude [0 ] != 'all ' ) {
155+ if ($ languagesInclude [0 ] !== 'all ' ) {
150156 foreach ($ languagesInclude as $ lang ) {
151157 if (!$ this ->localeValidator ->isValid ($ lang )) {
152- throw new \ InvalidArgumentException (
158+ throw new InvalidArgumentException (
153159 $ lang .
154160 ' argument has invalid value, please run info:language:list for list of available locales '
155161 );
156162 }
157163 }
158- if ($ languagesExclude [0 ] != 'none ' ) {
159- throw new \ InvalidArgumentException (
164+ if ($ languagesExclude [0 ] !== 'none ' ) {
165+ throw new InvalidArgumentException (
160166 '--language (-l) and --exclude-language cannot be used at the same time '
161167 );
162168 }
@@ -167,7 +173,7 @@ private function checkLanguagesInput(array $languagesInclude, array $languagesEx
167173 * Version input checks
168174 *
169175 * @param string $contentVersion
170- * @throws \ InvalidArgumentException
176+ * @throws InvalidArgumentException
171177 */
172178 private function checkVersionInput (string $ contentVersion ): void
173179 {
@@ -179,12 +185,33 @@ private function checkVersionInput(string $contentVersion): void
179185 );
180186
181187 if (!$ versionValidator ->isValid ($ contentVersion )) {
182- throw new \ InvalidArgumentException (
188+ throw new InvalidArgumentException (
183189 'Argument " ' .
184190 Options::CONTENT_VERSION
185191 . '" has invalid value, content version should contain only characters, digits and dots '
186192 );
187193 }
188194 }
189195 }
196+
197+ /**
198+ * Validate if --no-parent flag could be used with selected strategy
199+ *
200+ * @param bool $noParent
201+ * @param string $strategy
202+ * @throws InvalidArgumentException
203+ */
204+ private function checkNoParentInput (bool $ noParent , string $ strategy ): void
205+ {
206+ $ supportedStrategies = [
207+ 'quick ' => true ,
208+ 'standard ' => true ,
209+ ];
210+
211+ if ($ noParent && !array_key_exists ($ strategy , $ supportedStrategies )) {
212+ throw new InvalidArgumentException (
213+ sprintf ('Argument "%s" is not supported with "%s" strategy ' , Options::NO_PARENT , $ strategy )
214+ );
215+ }
216+ }
190217}
0 commit comments