Skip to content

Commit 7421dfb

Browse files
committed
REPO-66: [EQP][Sniffs Consolidation] Deliver Magento Coding Standard to magento2ce
1 parent 212a533 commit 7421dfb

File tree

66 files changed

+206
-2375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+206
-2375
lines changed

app/code/Magento/Config/Observer/Config/Backend/Admin/AfterCustomUrlChangedObserver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Framework\Event\ObserverInterface;
99

10+
/**
11+
* Class AfterCustomUrlChangedObserver
12+
*/
1013
class AfterCustomUrlChangedObserver implements ObserverInterface
1114
{
1215
/**
@@ -56,7 +59,6 @@ public function __construct(
5659
*
5760
* @param \Magento\Framework\Event\Observer $observer
5861
* @return void
59-
* @SuppressWarnings(PHPMD.ExitExpression)
6062
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6163
*/
6264
public function execute(\Magento\Framework\Event\Observer $observer)
@@ -68,6 +70,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
6870
$this->_authSession->destroy();
6971
$adminUrl = $this->_backendData->getHomePageUrl();
7072
$this->_response->setRedirect($adminUrl)->sendResponse();
73+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
7174
exit(0);
7275
}
7376
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\DataObjectFactory;
1818

1919
/**
20+
* Class Viewfile
2021
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2122
*/
2223
class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index
@@ -127,8 +128,6 @@ public function __construct(
127128
*
128129
* @return \Magento\Framework\Controller\ResultInterface|void
129130
* @throws NotFoundException
130-
*
131-
* @SuppressWarnings(PHPMD.ExitExpression)
132131
*/
133132
public function execute()
134133
{
@@ -146,6 +145,7 @@ public function execute()
146145
}
147146

148147
if ($plain) {
148+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
149149
$extension = pathinfo($path, PATHINFO_EXTENSION);
150150
switch (strtolower($extension)) {
151151
case 'gif':
@@ -175,6 +175,7 @@ public function execute()
175175
$resultRaw->setContents($directory->readFile($fileName));
176176
return $resultRaw;
177177
} else {
178+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
178179
$name = pathinfo($path, PATHINFO_BASENAME);
179180
$this->_fileFactory->create(
180181
$name,

app/code/Magento/Deploy/Process/Queue.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function __construct(
125125
}
126126

127127
/**
128+
* Adds deployment package.
129+
*
128130
* @param Package $package
129131
* @param Package[] $dependencies
130132
* @return bool true on success
@@ -140,6 +142,8 @@ public function add(Package $package, array $dependencies = [])
140142
}
141143

142144
/**
145+
* Returns packages array.
146+
*
143147
* @return Package[]
144148
*/
145149
public function getPackages()
@@ -162,6 +166,7 @@ public function process()
162166
$this->assertAndExecute($name, $packages, $packageJob);
163167
}
164168
$this->logger->info('.');
169+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
165170
sleep(3);
166171
foreach ($this->inProgress as $name => $package) {
167172
if ($this->isDeployed($package)) {
@@ -209,6 +214,8 @@ private function assertAndExecute($name, array & $packages, array $packageJob)
209214
}
210215

211216
/**
217+
* Executes deployment package.
218+
*
212219
* @param Package $package
213220
* @param string $name
214221
* @param array $packages
@@ -244,6 +251,7 @@ private function awaitForAllProcesses()
244251
}
245252
}
246253
$this->logger->info('.');
254+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
247255
sleep(5);
248256
}
249257
if ($this->isCanBeParalleled()) {
@@ -253,6 +261,8 @@ private function awaitForAllProcesses()
253261
}
254262

255263
/**
264+
* Checks if can be parallel.
265+
*
256266
* @return bool
257267
*/
258268
private function isCanBeParalleled()
@@ -261,9 +271,11 @@ private function isCanBeParalleled()
261271
}
262272

263273
/**
274+
* Executes the process.
275+
*
264276
* @param Package $package
265277
* @return bool true on success for main process and exit for child process
266-
* @SuppressWarnings(PHPMD.ExitExpression)
278+
* @throws \RuntimeException
267279
*/
268280
private function execute(Package $package)
269281
{
@@ -291,6 +303,7 @@ function () use ($package) {
291303
);
292304

293305
if ($this->isCanBeParalleled()) {
306+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
294307
$pid = pcntl_fork();
295308
if ($pid === -1) {
296309
throw new \RuntimeException('Unable to fork a new process');
@@ -305,6 +318,7 @@ function () use ($package) {
305318
// process child process
306319
$this->inProgress = [];
307320
$this->deployPackageService->deploy($package, $this->options, true);
321+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
308322
exit(0);
309323
} else {
310324
$this->deployPackageService->deploy($package, $this->options);
@@ -313,18 +327,22 @@ function () use ($package) {
313327
}
314328

315329
/**
330+
* Checks if package is deployed.
331+
*
316332
* @param Package $package
317333
* @return bool
318334
*/
319335
private function isDeployed(Package $package)
320336
{
321337
if ($this->isCanBeParalleled()) {
322338
if ($package->getState() === null) {
339+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
323340
$pid = pcntl_waitpid($this->getPid($package), $status, WNOHANG);
324341
if ($pid === $this->getPid($package)) {
325342
$package->setState(Package::STATE_COMPLETED);
326343

327344
unset($this->inProgress[$package->getPath()]);
345+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
328346
return pcntl_wexitstatus($status) === 0;
329347
}
330348
return false;
@@ -334,17 +352,19 @@ private function isDeployed(Package $package)
334352
}
335353

336354
/**
355+
* Returns process ID or null if not found.
356+
*
337357
* @param Package $package
338358
* @return int|null
339359
*/
340360
private function getPid(Package $package)
341361
{
342-
return isset($this->processIds[$package->getPath()])
343-
? $this->processIds[$package->getPath()]
344-
: null;
362+
return isset($this->processIds[$package->getPath()]) ?? null;
345363
}
346364

347365
/**
366+
* Checks timeout.
367+
*
348368
* @return bool
349369
*/
350370
private function checkTimeout()
@@ -357,11 +377,13 @@ private function checkTimeout()
357377
*
358378
* Protect against zombie process
359379
*
380+
* @throws \RuntimeException
360381
* @return void
361382
*/
362383
public function __destruct()
363384
{
364385
foreach ($this->inProgress as $package) {
386+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
365387
if (pcntl_waitpid($this->getPid($package), $status) === -1) {
366388
throw new \RuntimeException(
367389
'Error while waiting for package deployed: ' . $this->getPid($package) . '; Status: ' . $status

app/code/Magento/Downloadable/Controller/Download/Link.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -10,6 +9,9 @@
109
use Magento\Downloadable\Model\Link\Purchased\Item as PurchasedLink;
1110
use Magento\Framework\App\ResponseInterface;
1211

12+
/**
13+
* Class Link
14+
*/
1315
class Link extends \Magento\Downloadable\Controller\Download
1416
{
1517
/**
@@ -29,7 +31,6 @@ protected function _getCustomerSession()
2931
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
3032
* @SuppressWarnings(PHPMD.NPathComplexity)
3133
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
32-
* @SuppressWarnings(PHPMD.ExitExpression)
3334
*/
3435
public function execute()
3536
{
@@ -117,6 +118,7 @@ public function execute()
117118
$linkPurchasedItem->setStatus(PurchasedLink::LINK_STATUS_EXPIRED);
118119
}
119120
$linkPurchasedItem->save();
121+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
120122
exit(0);
121123
} catch (\Exception $e) {
122124
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));

app/code/Magento/Downloadable/Controller/Download/LinkSample.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,13 +8,15 @@
98
use Magento\Downloadable\Helper\Download as DownloadHelper;
109
use Magento\Framework\App\ResponseInterface;
1110

11+
/**
12+
* Class LinkSample
13+
*/
1214
class LinkSample extends \Magento\Downloadable\Controller\Download
1315
{
1416
/**
1517
* Download link's sample action
1618
*
1719
* @return ResponseInterface
18-
* @SuppressWarnings(PHPMD.ExitExpression)
1920
*/
2021
public function execute()
2122
{
@@ -39,6 +40,7 @@ public function execute()
3940
}
4041
try {
4142
$this->_processDownload($resource, $resourceType);
43+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
4244
exit(0);
4345
} catch (\Exception $e) {
4446
$this->messageManager->addError(

app/code/Magento/Downloadable/Controller/Download/Sample.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,13 +8,15 @@
98
use Magento\Downloadable\Helper\Download as DownloadHelper;
109
use Magento\Framework\App\ResponseInterface;
1110

11+
/**
12+
* Class Sample
13+
*/
1214
class Sample extends \Magento\Downloadable\Controller\Download
1315
{
1416
/**
1517
* Download sample action
1618
*
1719
* @return ResponseInterface
18-
* @SuppressWarnings(PHPMD.ExitExpression)
1920
*/
2021
public function execute()
2122
{
@@ -36,6 +37,7 @@ public function execute()
3637
}
3738
try {
3839
$this->_processDownload($resource, $resourceType);
40+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
3941
exit(0);
4042
} catch (\Exception $e) {
4143
$this->messageManager->addError(

app/code/Magento/Indexer/Model/ProcessManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function execute($userFunctions)
7171
private function simpleThreadExecute($userFunctions)
7272
{
7373
foreach ($userFunctions as $userFunction) {
74+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
7475
call_user_func($userFunction);
7576
}
7677
}
@@ -79,13 +80,15 @@ private function simpleThreadExecute($userFunctions)
7980
* Execute user functions in multiThreads mode
8081
*
8182
* @param \Traversable $userFunctions
83+
* @throws \RuntimeException
8284
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
8385
*/
8486
private function multiThreadsExecute($userFunctions)
8587
{
8688
$this->resource->closeConnection(null);
8789
$threadNumber = 0;
8890
foreach ($userFunctions as $userFunction) {
91+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
8992
$pid = pcntl_fork();
9093
if ($pid == -1) {
9194
throw new \RuntimeException('Unable to fork a new process');
@@ -95,6 +98,7 @@ private function multiThreadsExecute($userFunctions)
9598
$this->startChildProcess($userFunction);
9699
}
97100
}
101+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock,Magento2.Functions.DiscouragedFunction
98102
while (pcntl_waitpid(0, $status) != -1) {
99103
//Waiting for the completion of child processes
100104
}
@@ -128,12 +132,13 @@ private function isSetupMode(): bool
128132
* Start child process
129133
*
130134
* @param callable $userFunction
131-
* @SuppressWarnings(PHPMD.ExitExpression)
132135
*/
133136
private function startChildProcess(callable $userFunction)
134137
{
138+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
135139
$status = call_user_func($userFunction);
136-
$status = is_integer($status) ? $status : 0;
140+
$status = is_int($status) ? $status : 0;
141+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
137142
exit($status);
138143
}
139144

@@ -146,8 +151,10 @@ private function executeParentProcess(int &$threadNumber)
146151
{
147152
$threadNumber++;
148153
if ($threadNumber >= $this->threadsCount) {
154+
// phpcs:disable Magento2.Functions.DiscouragedFunction
149155
pcntl_wait($status);
150156
if (pcntl_wexitstatus($status) !== 0) {
157+
// phpcs:enable
151158
$this->failInChildProcess = true;
152159
}
153160
$threadNumber--;

app/code/Magento/MessageQueue/Model/CallbackInvoker.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ public function __construct(
4646

4747
/**
4848
* @inheritdoc
49-
* @SuppressWarnings(PHPMD.ExitExpression)
5049
*/
5150
public function invoke(QueueInterface $queue, $maxNumberOfMessages, $callback)
5251
{
5352
$this->poisonPillVersion = $this->poisonPillRead->getLatestVersion();
5453
for ($i = $maxNumberOfMessages; $i > 0; $i--) {
5554
do {
5655
$message = $queue->dequeue();
56+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
5757
} while ($message === null && (sleep(1) === 0));
5858
if (false === $this->poisonPillCompare->isLatestVersion($this->poisonPillVersion)) {
5959
$queue->reject($message);
60+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
6061
exit(0);
6162
}
6263
$callback($message);

app/code/Magento/Paypal/Controller/Ipn/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function validateForCsrf(RequestInterface $request): ?bool
7373
* Instantiate IPN model and pass IPN request to it
7474
*
7575
* @return void
76-
* @SuppressWarnings(PHPMD.ExitExpression)
7776
*/
7877
public function execute()
7978
{
@@ -95,6 +94,7 @@ public function execute()
9594
$this->_logger->critical($e);
9695
$this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();
9796
/** @todo eliminate usage of exit statement */
97+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
9898
exit;
9999
} catch (\Exception $e) {
100100
$this->_logger->critical($e);

0 commit comments

Comments
 (0)