Skip to content

Commit

Permalink
Merge pull request #3957 from magento-eqp/REPO-66-coding-standard
Browse files Browse the repository at this point in the history
- added "magento/magento-coding-standard": "~1.0.0" dev dependency;
- removed duplicated static checks: PHPMD.ExitExpression, PHPMD.FinalImplementation, unsecure_php_functions, Xss Unsafe Output Test suite;
- removed SuppressWarnings for deleted PHPMD rules;
- fixed issues in changed files.
  • Loading branch information
irenelagno authored Mar 29, 2019
2 parents 70bf7c6 + 9898fac commit a9a72b6
Show file tree
Hide file tree
Showing 67 changed files with 259 additions and 2,375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Config\Observer\Config\Backend\Admin;

use Magento\Framework\Event\ObserverInterface;

/**
* Class AfterCustomUrlChangedObserver redirects to new custom admin URL.
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class AfterCustomUrlChangedObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -56,7 +63,6 @@ public function __construct(
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.ExitExpression)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
Expand All @@ -68,6 +74,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$this->_authSession->destroy();
$adminUrl = $this->_backendData->getHomePageUrl();
$this->_response->setRedirect($adminUrl)->sendResponse();
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Controller\Adminhtml\Index;

use Magento\Customer\Api\AccountManagementInterface;
Expand All @@ -17,7 +19,10 @@
use Magento\Framework\DataObjectFactory;

/**
* Class Viewfile serves to show file or image by file/image name provided in request parameters.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index
{
Expand Down Expand Up @@ -127,8 +132,6 @@ public function __construct(
*
* @return \Magento\Framework\Controller\ResultInterface|void
* @throws NotFoundException
*
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute()
{
Expand All @@ -146,6 +149,7 @@ public function execute()
}

if ($plain) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$extension = pathinfo($path, PATHINFO_EXTENSION);
switch (strtolower($extension)) {
case 'gif':
Expand Down Expand Up @@ -175,6 +179,7 @@ public function execute()
$resultRaw->setContents($directory->readFile($fileName));
return $resultRaw;
} else {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$name = pathinfo($path, PATHINFO_BASENAME);
$this->_fileFactory->create(
$name,
Expand Down
32 changes: 28 additions & 4 deletions app/code/Magento/Deploy/Process/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Deploy\Process;

use Magento\Deploy\Package\Package;
Expand Down Expand Up @@ -125,6 +127,8 @@ public function __construct(
}

/**
* Adds deployment package.
*
* @param Package $package
* @param Package[] $dependencies
* @return bool true on success
Expand All @@ -140,6 +144,8 @@ public function add(Package $package, array $dependencies = [])
}

/**
* Returns packages array.
*
* @return Package[]
*/
public function getPackages()
Expand All @@ -162,6 +168,7 @@ public function process()
$this->assertAndExecute($name, $packages, $packageJob);
}
$this->logger->info('.');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
sleep(3);
foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
Expand Down Expand Up @@ -209,6 +216,8 @@ private function assertAndExecute($name, array & $packages, array $packageJob)
}

/**
* Executes deployment package.
*
* @param Package $package
* @param string $name
* @param array $packages
Expand Down Expand Up @@ -244,6 +253,7 @@ private function awaitForAllProcesses()
}
}
$this->logger->info('.');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
sleep(5);
}
if ($this->isCanBeParalleled()) {
Expand All @@ -253,6 +263,8 @@ private function awaitForAllProcesses()
}

/**
* Checks if can be parallel.
*
* @return bool
*/
private function isCanBeParalleled()
Expand All @@ -261,9 +273,11 @@ private function isCanBeParalleled()
}

/**
* Executes the process.
*
* @param Package $package
* @return bool true on success for main process and exit for child process
* @SuppressWarnings(PHPMD.ExitExpression)
* @throws \RuntimeException
*/
private function execute(Package $package)
{
Expand Down Expand Up @@ -291,6 +305,7 @@ function () use ($package) {
);

if ($this->isCanBeParalleled()) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$pid = pcntl_fork();
if ($pid === -1) {
throw new \RuntimeException('Unable to fork a new process');
Expand All @@ -305,6 +320,7 @@ function () use ($package) {
// process child process
$this->inProgress = [];
$this->deployPackageService->deploy($package, $this->options, true);
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} else {
$this->deployPackageService->deploy($package, $this->options);
Expand All @@ -313,18 +329,22 @@ function () use ($package) {
}

/**
* Checks if package is deployed.
*
* @param Package $package
* @return bool
*/
private function isDeployed(Package $package)
{
if ($this->isCanBeParalleled()) {
if ($package->getState() === null) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$pid = pcntl_waitpid($this->getPid($package), $status, WNOHANG);
if ($pid === $this->getPid($package)) {
$package->setState(Package::STATE_COMPLETED);

unset($this->inProgress[$package->getPath()]);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return pcntl_wexitstatus($status) === 0;
}
return false;
Expand All @@ -334,17 +354,19 @@ private function isDeployed(Package $package)
}

/**
* Returns process ID or null if not found.
*
* @param Package $package
* @return int|null
*/
private function getPid(Package $package)
{
return isset($this->processIds[$package->getPath()])
? $this->processIds[$package->getPath()]
: null;
return isset($this->processIds[$package->getPath()]) ?? null;
}

/**
* Checks timeout.
*
* @return bool
*/
private function checkTimeout()
Expand All @@ -357,11 +379,13 @@ private function checkTimeout()
*
* Protect against zombie process
*
* @throws \RuntimeException
* @return void
*/
public function __destruct()
{
foreach ($this->inProgress as $package) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
if (pcntl_waitpid($this->getPid($package), $status) === -1) {
throw new \RuntimeException(
'Error while waiting for package deployed: ' . $this->getPid($package) . '; Status: ' . $status
Expand Down
10 changes: 8 additions & 2 deletions app/code/Magento/Downloadable/Controller/Download/Link.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Controller\Download;

use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Downloadable\Model\Link\Purchased\Item as PurchasedLink;
use Magento\Framework\App\ResponseInterface;

/**
* Class Link executes download link action.
*
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
class Link extends \Magento\Downloadable\Controller\Download
{
/**
Expand All @@ -29,7 +35,6 @@ protected function _getCustomerSession()
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute()
{
Expand Down Expand Up @@ -117,6 +122,7 @@ public function execute()
$linkPurchasedItem->setStatus(PurchasedLink::LINK_STATUS_EXPIRED);
}
$linkPurchasedItem->save();
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong while getting the requested content.'));
Expand Down
10 changes: 8 additions & 2 deletions app/code/Magento/Downloadable/Controller/Download/LinkSample.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Controller\Download;

use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Framework\App\ResponseInterface;

/**
* Class LinkSample executes download sample link action.
*
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
class LinkSample extends \Magento\Downloadable\Controller\Download
{
/**
* Download link's sample action
*
* @return ResponseInterface
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute()
{
Expand All @@ -39,6 +44,7 @@ public function execute()
}
try {
$this->_processDownload($resource, $resourceType);
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} catch (\Exception $e) {
$this->messageManager->addError(
Expand Down
10 changes: 8 additions & 2 deletions app/code/Magento/Downloadable/Controller/Download/Sample.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Controller\Download;

use Magento\Downloadable\Helper\Download as DownloadHelper;
use Magento\Framework\App\ResponseInterface;

/**
* Class Sample executes download sample action.
*
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
class Sample extends \Magento\Downloadable\Controller\Download
{
/**
* Download sample action
*
* @return ResponseInterface
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute()
{
Expand All @@ -36,6 +41,7 @@ public function execute()
}
try {
$this->_processDownload($resource, $resourceType);
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
exit(0);
} catch (\Exception $e) {
$this->messageManager->addError(
Expand Down
Loading

0 comments on commit a9a72b6

Please sign in to comment.