-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6396b56
commit 9ee22f9
Showing
7 changed files
with
228 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SprykerSdk\Integrator\Builder\FileNormalizer; | ||
|
||
use RuntimeException; | ||
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface; | ||
|
||
class CodeSnifferCommandExecutor | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public const EXECUTION_ATTEMPTS = 2; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected const SUCCESS_COMMAND_CODE = 0; | ||
|
||
/** | ||
* @var \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface | ||
*/ | ||
protected ProcessRunnerServiceInterface $processRunner; | ||
|
||
/** | ||
* @param \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface $processRunner | ||
*/ | ||
public function __construct(ProcessRunnerServiceInterface $processRunner) | ||
{ | ||
$this->processRunner = $processRunner; | ||
} | ||
|
||
/** | ||
* @param array<string> $command | ||
* | ||
* @throws \RuntimeException | ||
* | ||
* @return void | ||
*/ | ||
public function executeCodeSnifferCommand(array $command): void | ||
{ | ||
$leftAttempts = static::EXECUTION_ATTEMPTS; | ||
|
||
while ($leftAttempts > 0) { | ||
$process = $this->processRunner->run($command); | ||
|
||
if ($process->getExitCode() === static::SUCCESS_COMMAND_CODE) { | ||
break; | ||
} | ||
|
||
--$leftAttempts; | ||
} | ||
|
||
if (isset($process) && $process->getExitCode() !== static::SUCCESS_COMMAND_CODE) { | ||
$errorOutput = $process->getErrorOutput(); | ||
|
||
if ($errorOutput !== '') { | ||
throw new RuntimeException($errorOutput); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.