Skip to content

Commit 3bacace

Browse files
committed
MC-29402: PHPStan: "Anonymous function has an unused use" errors
1 parent bc8e51d commit 3bacace

File tree

11 files changed

+27
-21
lines changed

11 files changed

+27
-21
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Plugin/ProductRepository/TransactionWrapperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void
6262
$this->closureMock = function () use ($productMock) {
6363
return $productMock;
6464
};
65-
$this->rollbackClosureMock = function () use ($productMock) {
65+
$this->rollbackClosureMock = function () {
6666
throw new \Exception(self::ERROR_MSG);
6767
};
6868

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/TierPrices.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function resolve(
8787
$this->tiers->addProductFilter($productId);
8888

8989
return $this->valueFactory->create(
90-
function () use ($productId, $context) {
90+
function () use ($productId) {
9191
$tierPrices = $this->tiers->getProductTierPrices($productId);
9292

9393
return $tierPrices ?? [];

app/code/Magento/Customer/Controller/Adminhtml/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ protected function _addSessionErrorMessages($messages)
291291
$messages = (array)$messages;
292292
$session = $this->_getSession();
293293

294-
$callback = function ($error) use ($session) {
294+
$callback = function ($error) {
295295
if (!$error instanceof Error) {
296296
$error = new Error($error);
297297
}

app/code/Magento/Customer/Test/Unit/Model/Plugin/CustomerRepository/TransactionWrapperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void
6262
$this->closureMock = function () use ($customerMock) {
6363
return $customerMock;
6464
};
65-
$this->rollbackClosureMock = function () use ($customerMock) {
65+
$this->rollbackClosureMock = function () {
6666
throw new \Exception(self::ERROR_MSG);
6767
};
6868

dev/tests/integration/testsuite/Magento/Swatches/Model/AttributeCreateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function ($values, $index) use ($optionsPerAttribute) {
5252
);
5353
$data['optionvisual']['value'] = array_reduce(
5454
range(1, $optionsPerAttribute),
55-
function ($values, $index) use ($optionsPerAttribute) {
55+
function ($values, $index) {
5656
$values['option_' . $index] = ['option ' . $index];
5757
return $values;
5858
},
@@ -61,7 +61,7 @@ function ($values, $index) use ($optionsPerAttribute) {
6161

6262
$data['options']['option'] = array_reduce(
6363
range(1, $optionsPerAttribute),
64-
function ($values, $index) use ($optionsPerAttribute) {
64+
function ($values, $index) {
6565
$values[] = [
6666
'label' => 'option ' . $index,
6767
'value' => 'option_' . $index

dev/tests/integration/testsuite/Magento/Swatches/Model/SwatchAttributeOptionAddTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testSwatchOptionAdd()
4040

4141
$data['options']['option'] = array_reduce(
4242
range(10, $optionsPerAttribute),
43-
function ($values, $index) use ($optionsPerAttribute) {
43+
function ($values, $index) {
4444
$values[] = [
4545
'label' => 'option ' . $index,
4646
'value' => 'option_' . $index

lib/internal/Magento/Framework/Setup/ExternalFKSetup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ protected function execute()
9292
/**
9393
* Get foreign keys for tables and columns
9494
*
95-
* @param string $refTable
96-
* @param string $refColumn
9795
* @param string $targetTable
9896
* @param string $targetColumn
97+
* @param string $refTable
98+
* @param string $refColumn
9999
* @return array
100100
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
101101
*/
@@ -110,7 +110,7 @@ protected function getForeignKeys(
110110
);
111111
$foreignKeys = array_filter(
112112
$foreignKeys,
113-
function ($key) use ($targetColumn, $refTable, $refColumn) {
113+
function ($key) use ($targetColumn, $refTable) {
114114
return $key['COLUMN_NAME'] == $targetColumn
115115
&& $key['REF_TABLE_NAME'] == $refTable;
116116
}

setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Setup\Console\Command;
88

99
use Magento\Framework\Setup\ConsoleLogger;
10+
use Magento\Framework\Validation\ValidationException;
1011
use Magento\Setup\Model\AdminAccount;
1112
use Magento\Setup\Model\InstallerFactory;
1213
use Magento\User\Model\UserValidationRules;
@@ -81,7 +82,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
8182
$question = new Question('<question>Admin password:</question> ', '');
8283
$question->setHidden(true);
8384

84-
$question->setValidator(function ($value) use ($output) {
85+
$question->setValidator(function ($value) {
8586
$user = new \Magento\Framework\DataObject();
8687
$user->setPassword($value);
8788

@@ -90,7 +91,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
9091

9192
$validator->isValid($user);
9293
foreach ($validator->getMessages() as $message) {
93-
throw new \Exception($message);
94+
throw new ValidationException(__($message));
9495
}
9596

9697
return $value;
@@ -143,7 +144,7 @@ private function addNotEmptyValidator(Question $question)
143144
{
144145
$question->setValidator(function ($value) {
145146
if (trim($value) == '') {
146-
throw new \Exception('The value cannot be empty');
147+
throw new ValidationException(__('The value cannot be empty'));
147148
}
148149

149150
return $value;

setup/src/Magento/Setup/Console/Command/RollbackCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(
8080
}
8181

8282
/**
83-
* {@inheritdoc}
83+
* @inheritDoc
8484
*/
8585
protected function configure()
8686
{
@@ -111,7 +111,7 @@ protected function configure()
111111
}
112112

113113
/**
114-
* {@inheritdoc}
114+
* @inheritDoc
115115
*/
116116
protected function execute(InputInterface $input, OutputInterface $output)
117117
{
@@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
123123
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
124124
}
125125
$returnValue = $this->maintenanceModeEnabler->executeInMaintenanceMode(
126-
function () use ($input, $output, &$returnValue) {
126+
function () use ($input, $output) {
127127
try {
128128
$helper = $this->getHelper('question');
129129
$question = new ConfirmationQuestion(

setup/src/Magento/Setup/Fixtures/AttributeSet/SwatchesGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function ($values, $index) use ($optionCount, $data, $type) {
9191
);
9292
$attribute['optionvisual']['value'] = array_reduce(
9393
range(1, $optionCount),
94-
function ($values, $index) use ($optionCount) {
94+
function ($values, $index) {
9595
$values['option_' . $index] = ['option ' . $index];
9696
return $values;
9797
},
@@ -129,6 +129,7 @@ private function generateSwatchImage($data)
129129
$this->imagesGenerator = $this->imagesGeneratorFactory->create();
130130
}
131131

132+
// phpcs:ignore Magento2.Security.InsecureFunction
132133
$imageName = md5($data) . '.jpg';
133134
$this->imagesGenerator->generate([
134135
'image-width' => self::GENERATED_SWATCH_WIDTH,

0 commit comments

Comments
 (0)