Skip to content

Commit d9a95e3

Browse files
committed
MAGE-1113 Add store ID argument validation
1 parent a43700c commit d9a95e3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Console/Command/AbstractStoreCommand.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,27 @@ protected function setAreaCode(): void
7272
/**
7373
* @param InputInterface $input
7474
* @return int[]
75+
* @throws LocalizedException
7576
*/
7677
protected function getStoreIds(InputInterface $input): array
7778
{
78-
return (array) $input->getArgument(self::STORE_ARGUMENT);
79+
return $this->validateStoreIds((array) $input->getArgument(self::STORE_ARGUMENT));
80+
}
81+
82+
/**
83+
* @param array $storeIds
84+
* @return int[]
85+
* @throws LocalizedException
86+
*/
87+
protected function validateStoreIds(array $storeIds): array
88+
{
89+
foreach ($storeIds as $storeId) {
90+
if (!ctype_digit($storeId) || (int) $storeId < 1) {
91+
throw new LocalizedException(__("Store ID argument must be an integer"));
92+
}
93+
}
94+
95+
return array_map('intval', $storeIds);
7996
}
8097

8198
protected function getStoreArgumentDefinition(): InputArgument {

0 commit comments

Comments
 (0)