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

DQA-7989: Component check improvements #712

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions src/TaskRunner/AbstractCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,28 @@ public function getWorkingDir(): string
return (string) $this->input->getParameterOption('--working-dir', getcwd());
}

/**
* Returns the composer.json parsed content.
*/
public function getComposerJson(): array
{
$file = $this->getWorkingDir() . '/composer.json';
if (!file_exists($file)) {
throw new \Exception("The '$file' was not found.");
}
return (array) json_decode(file_get_contents($file), true);
}

/**
* Returns the composer.lock parsed content.
*/
public function getComposerLock(): array
{
$file = $this->getWorkingDir() . '/composer.lock';
if (!file_exists($file)) {
throw new \Exception("The '$file' was not found.");
}
return (array) json_decode(file_get_contents($file), true);
}

}
209 changes: 106 additions & 103 deletions src/TaskRunner/Commands/ComponentCheckCommands.php

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions src/TaskRunner/Commands/PatchCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,12 @@ public function toolkitPatchDownload(ConsoleIO $io, array $options = [
return $this->collectionBuilder()->addTaskList($tasks);
}

/**
* Returns the composer.json content.
*/
private function getComposer()
{
$composer = $this->input()->getOption('composer');
$file = $this->getWorkingDir() . '/' . trim($composer, '/');
if (!file_exists($file)) {
$this->writeln("The file '$file' not found.");
return ResultData::EXITCODE_OK;
}
return json_decode(file_get_contents($file), true);
}

/**
* Returns the patches to be downloaded.
*/
private function getPatches(): array
{
$composer = $this->getComposer();
$composer = $this->getComposerJson();
$patches = $composer['extra']['patches'] ?? [];
// Check if there's any patch.
if (empty($patches)) {
Expand Down
13 changes: 2 additions & 11 deletions src/TaskRunner/Commands/SymlinkProjectCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getConfigurationFile()
*/
public function symlinkProjectValidate(): void
{
$composer = $this->getComposer();
$composer = $this->getComposerJson();
// Check if the project name is present.
if (empty($composer['name'])) {
throw new \Exception('Could not find the project name in the composer.json file.');
Expand Down Expand Up @@ -77,7 +77,7 @@ public function symlinkProject(array $options = [
{
Toolkit::ensureArray($options['ignore']);
$workingDir = $this->getConfig()->get('runner.working_dir');
$composer = $this->getComposer();
$composer = $this->getComposerJson();
$projectId = explode('/', $composer['name'])[1];
$projectType = $this->types[$composer['type']];
$destination = $workingDir . '/' . $options['root'] . '/' . $projectType . '/' . $projectId;
Expand All @@ -97,15 +97,6 @@ public function symlinkProject(array $options = [
return $this->collectionBuilder()->addTask($task);
}

private function getComposer()
{
$composer = $this->getWorkingDir() . '/composer.json';
if (!file_exists($composer)) {
throw new \Exception("The $composer was not found.");
}
return json_decode(file_get_contents($composer), true);
}

private function scanDir(string $directory, array $ignore = []): array
{
$ignore = array_merge(['.', '..', '.git'], $ignore);
Expand Down
13 changes: 5 additions & 8 deletions src/TaskRunner/Commands/TestsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,11 @@ protected function toolkitRunGrumphp()
}
}

$composerFile = './composer.json';
if (file_exists($composerFile)) {
$composerArray = json_decode(file_get_contents($composerFile), true);
if (isset($composerArray['extra']['grumphp']['config-default-path'])) {
$configDefaultPath = $composerArray['extra']['grumphp']['config-default-path'];
$this->say('You should remove the following from your composer.json extra array:');
echo "\n\"grumphp\": {\n \"config-default-path\": \"$configDefaultPath\"\n}\n\n";
}
$composer = $this->getComposerJson();
if (isset($composer['extra']['grumphp']['config-default-path'])) {
$configDefaultPath = $composer['extra']['grumphp']['config-default-path'];
$this->say('You should remove the following from your composer.json extra array:');
echo "\n\"grumphp\": {\n \"config-default-path\": \"$configDefaultPath\"\n}\n\n";
}

if ($containsQaConventions) {
Expand Down
Loading