Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-4713: Extract utils #155

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"composer/composer": "^2.1.0",
"czproject/git-php": "^4.1",
"guzzlehttp/guzzle": "^7.4",
"laminas/laminas-filter": "^2.11.0",
"spryker-sdk/utils": "dev-feature/sdk-extract-utils",
"nikic/php-parser": "^4.3.0",
"sebastian/diff": "^4.0.0",
"symfony/console": "^5.3.0 || ^6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/ClassGenerator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use PhpParser\BuilderFactory;
use PhpParser\Node\Name;
use SprykerSdk\Integrator\Builder\ClassLoader\ClassLoaderInterface;
use SprykerSdk\Integrator\Common\UtilText\TextCaseHelper;
use SprykerSdk\Integrator\Helper\ClassHelperInterface;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Integrator\Transfer\ClassInformationTransfer;
use SprykerSdk\Utils\Infrastructure\Helper\StrHelper;

class ClassGenerator implements ClassGeneratorInterface
{
Expand Down Expand Up @@ -163,7 +163,7 @@
{
if (in_array($organisation, $this->config->getCoreNonSplitOrganisations())) {
return $this->config->getVendorDirectory()
. sprintf($this->config->getNonSplitRepositoryPathPattern(), TextCaseHelper::camelCaseToDash($organisation, false))
. sprintf($this->config->getNonSplitRepositoryPathPattern(), StrHelper::camelCaseToDash($organisation, false))

Check warning on line 166 in src/Builder/ClassGenerator/ClassGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/Builder/ClassGenerator/ClassGenerator.php#L166

Added line #L166 was not covered by tests
. $module
. DIRECTORY_SEPARATOR;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Builder/FileNormalizer/CodeSniffStyleFileNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace SprykerSdk\Integrator\Builder\FileNormalizer;

use RuntimeException;
use SprykerSdk\Integrator\Executor\ProcessExecutorInterface;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface;

class CodeSniffStyleFileNormalizer implements FileNormalizerInterface
{
Expand All @@ -31,18 +31,18 @@ class CodeSniffStyleFileNormalizer implements FileNormalizerInterface
protected $config;

/**
* @var \SprykerSdk\Integrator\Executor\ProcessExecutorInterface
* @var \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface
*/
protected ProcessExecutorInterface $processExecutor;
protected ProcessRunnerServiceInterface $processRunner;

/**
* @param \SprykerSdk\Integrator\IntegratorConfig $config
* @param \SprykerSdk\Integrator\Executor\ProcessExecutorInterface $processExecutor
* @param \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface $processRunner
*/
public function __construct(IntegratorConfig $config, ProcessExecutorInterface $processExecutor)
public function __construct(IntegratorConfig $config, ProcessRunnerServiceInterface $processRunner)
{
$this->config = $config;
$this->processExecutor = $processExecutor;
$this->processRunner = $processRunner;
}

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public function normalize(array $filePaths): void
{
$projectConsolePath = $this->getProjectConsolePath();
foreach ($this->getProjectRelativeFilePaths($filePaths) as $filePath) {
$process = $this->processExecutor->execute([$projectConsolePath, static::PHP_CS_FIX_COMMAND, $filePath]);
$process = $this->processRunner->run([$projectConsolePath, static::PHP_CS_FIX_COMMAND, $filePath]);

if ($process->getExitCode() > 0 && $process->getErrorOutput() !== '') {
throw new RuntimeException($process->getErrorOutput());
Expand Down
18 changes: 9 additions & 9 deletions src/Builder/FileNormalizer/PhpCSFixerFileNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace SprykerSdk\Integrator\Builder\FileNormalizer;

use RuntimeException;
use SprykerSdk\Integrator\Executor\ProcessExecutorInterface;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface;

class PhpCSFixerFileNormalizer implements FileNormalizerInterface
{
Expand All @@ -26,18 +26,18 @@ class PhpCSFixerFileNormalizer implements FileNormalizerInterface
protected $config;

/**
* @var \SprykerSdk\Integrator\Executor\ProcessExecutorInterface
* @var \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface
*/
protected ProcessExecutorInterface $processExecutor;
protected ProcessRunnerServiceInterface $processRunner;

/**
* @param \SprykerSdk\Integrator\IntegratorConfig $config
* @param \SprykerSdk\Integrator\Executor\ProcessExecutorInterface $processExecutor
* @param \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface $processRunner
*/
public function __construct(IntegratorConfig $config, ProcessExecutorInterface $processExecutor)
public function __construct(IntegratorConfig $config, ProcessRunnerServiceInterface $processRunner)
{
$this->config = $config;
$this->processExecutor = $processExecutor;
$this->processRunner = $processRunner;
}

/**
Expand Down Expand Up @@ -66,13 +66,13 @@ public function getErrorMessage(): ?string
public function normalize(array $filePaths): void
{
$command = [$this->getCSFixPath(), ...$this->getAbsoluteFilePaths($filePaths)];
$process = $this->processExecutor->execute($command);
$process = $this->processRunner->run($command);

// TODO remove when phpcbf will be able to fix all issues in file during the one iteration
if (defined('TEST_INTEGRATOR_MODE') && TEST_INTEGRATOR_MODE === 'true' && $process->getExitCode() !== 0) {
$process = $this->processExecutor->execute($command);
$process = $this->processRunner->run($command);
if ($process->getExitCode() !== 0) {
$process = $this->processExecutor->execute($command);
$process = $this->processRunner->run($command);
}
}

Expand Down
32 changes: 0 additions & 32 deletions src/Common/UtilText/Filter/CamelCaseToDash.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/Common/UtilText/TextCaseHelper.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Composer/ComposerLockReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace SprykerSdk\Integrator\Composer;

use SprykerSdk\Integrator\Common\UtilText\TextCaseHelper;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Helper\StrHelper;

class ComposerLockReader implements ComposerLockReaderInterface
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public function getPackageData(string $packageName): ?array
protected function getPackageVersion(array $packageData): array
{
[$org, $module] = explode('/', $packageData['name']);
$packageName = sprintf('%s.%s', TextCaseHelper::dashToCamelCase($org), TextCaseHelper::dashToCamelCase($module));
$packageName = sprintf('%s.%s', StrHelper::dashToCamelCase($org), StrHelper::dashToCamelCase($module));

if (strpos($packageData['version'], 'dev-') !== false) {
$versionFromExtra = $packageData['extra']['branch-alias']['dev-master'] ?? false;
Expand Down
14 changes: 7 additions & 7 deletions src/IntegratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@
use SprykerSdk\Integrator\Executor\ManifestExecutorInterface;
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutor;
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutorInterface;
use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\Executor\ProcessExecutorInterface;
use SprykerSdk\Integrator\Executor\ReleaseGroup\DiffGenerator;
use SprykerSdk\Integrator\FileStorage\BucketFileStorage;
use SprykerSdk\Integrator\FileStorage\BucketFileStorageInterface;
Expand Down Expand Up @@ -156,6 +154,8 @@
use SprykerSdk\Integrator\ManifestStrategy\WireTransferManifestStrategy;
use SprykerSdk\Integrator\ManifestStrategy\WireWidgetManifestStrategy;
use SprykerSdk\Integrator\VersionControlSystem\GitRepository;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerService;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface;
use Symfony\Component\Filesystem\Filesystem;

class IntegratorFactory
Expand Down Expand Up @@ -574,23 +574,23 @@ public function createCodeSnifferCompositeNormalizer(): FileNormalizerInterface
*/
public function createCodeSniffStyleFileNormalizer(): FileNormalizerInterface
{
return new CodeSniffStyleFileNormalizer($this->getConfig(), $this->createProcessExecutor());
return new CodeSniffStyleFileNormalizer($this->getConfig(), $this->createProcessRunnerService());
}

/**
* @return \SprykerSdk\Integrator\Builder\FileNormalizer\FileNormalizerInterface
*/
public function createPhpCSFixerNormalizer(): FileNormalizerInterface
{
return new PhpCSFixerFileNormalizer($this->getConfig(), $this->createProcessExecutor());
return new PhpCSFixerFileNormalizer($this->getConfig(), $this->createProcessRunnerService());
}

/**
* @return \SprykerSdk\Integrator\Executor\ProcessExecutorInterface
* @return \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface
*/
public function createProcessExecutor(): ProcessExecutorInterface
public function createProcessRunnerService(): ProcessRunnerServiceInterface
{
return new ProcessExecutor();
return new ProcessRunnerService();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ManifestStrategy/CopyModuleFileManifestStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace SprykerSdk\Integrator\ManifestStrategy;

use SprykerSdk\Integrator\Common\UtilText\TextCaseHelper;
use SprykerSdk\Integrator\Dependency\Console\InputOutputInterface;
use SprykerSdk\Integrator\Exception\ManifestApplyingException;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Helper\StrHelper;

class CopyModuleFileManifestStrategy extends AbstractManifestStrategy
{
Expand Down Expand Up @@ -81,9 +81,9 @@ protected function getSourcePath(string $source, string $moduleName): string
[$organisation, $moduleName] = explode('.', $moduleName);

return $this->config->getVendorDirectory()
. mb_strtolower(TextCaseHelper::camelCaseToDash($organisation))
. mb_strtolower(StrHelper::camelCaseToDash($organisation))
. DIRECTORY_SEPARATOR
. mb_strtolower(TextCaseHelper::camelCaseToDash($moduleName))
. mb_strtolower(StrHelper::camelCaseToDash($moduleName))
. DIRECTORY_SEPARATOR
. $source;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use RuntimeException;
use SprykerSdk\Integrator\Builder\FileNormalizer\CodeSniffStyleFileNormalizer;
use SprykerSdk\Integrator\Builder\FileStorage\FileStorage;
use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\Executor\ProcessExecutorInterface;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerService;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface;
use Symfony\Component\Process\Process;

class CodeSniffStyleFileNormalizerTest extends TestCase
Expand All @@ -27,7 +27,7 @@ public function testExecuteSuccess(): void
{
// Arrange
$processExecutorMock = $this->createProcessExecutorMock(0, '');
$processExecutorMock->expects($this->once())->method('execute')->with(
$processExecutorMock->expects($this->once())->method('run')->with(
$this->callback(function ($command) {
return $command[1] === 'code:sniff:style -f';
}),
Expand Down Expand Up @@ -85,13 +85,13 @@ public function testGetErrorMessageShouldReturnErrorMessage(): void
* @param int $exitCode
* @param string $errorOutput
*
* @return \SprykerSdk\Integrator\Executor\ProcessExecutorInterface
* @return \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface
*/
protected function createProcessExecutorMock(int $exitCode, string $errorOutput = ''): ProcessExecutorInterface
protected function createProcessExecutorMock(int $exitCode, string $errorOutput = ''): ProcessRunnerServiceInterface
{
$processMock = $this->createProcessMock($exitCode, $errorOutput);
$processExecutorMock = $this->createMock(ProcessExecutor::class);
$processExecutorMock->method('execute')->willReturn($processMock);
$processExecutorMock = $this->createMock(ProcessRunnerService::class);
$processExecutorMock->method('run')->willReturn($processMock);

return $processExecutorMock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use RuntimeException;
use SprykerSdk\Integrator\Builder\FileNormalizer\PhpCSFixerFileNormalizer;
use SprykerSdk\Integrator\Builder\FileStorage\FileStorage;
use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\Executor\ProcessExecutorInterface;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerService;
use SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface;
use Symfony\Component\Process\Process;

class PhpCSFixerFileNormalizerTest extends TestCase
Expand All @@ -27,7 +27,7 @@ public function testExecuteSuccess(): void
{
// Arrange
$processExecutorMock = $this->createProcessExecutorMock(0, '');
$processExecutorMock->expects($this->atLeastOnce())->method('execute')->with(
$processExecutorMock->expects($this->atLeastOnce())->method('run')->with(
$this->callback(function ($command) {
return strpos($command[0], 'vendor/bin/phpcbf') !== false;
}),
Expand Down Expand Up @@ -85,13 +85,13 @@ public function testGetErrorMessageShouldReturnErrorMessage(): void
* @param int $exitCode
* @param string $errorOutput
*
* @return \SprykerSdk\Integrator\Executor\ProcessExecutorInterface
* @return \SprykerSdk\Utils\Infrastructure\Service\ProcessRunnerServiceInterface
*/
protected function createProcessExecutorMock(int $exitCode, string $errorOutput = ''): ProcessExecutorInterface
protected function createProcessExecutorMock(int $exitCode, string $errorOutput = ''): ProcessRunnerServiceInterface
{
$processMock = $this->createProcessMock($exitCode, $errorOutput);
$processExecutorMock = $this->createMock(ProcessExecutor::class);
$processExecutorMock->method('execute')->willReturn($processMock);
$processExecutorMock = $this->createMock(ProcessRunnerService::class);
$processExecutorMock->method('run')->willReturn($processMock);

return $processExecutorMock;
}
Expand Down
Loading
Loading