Skip to content

Commit

Permalink
fix: json files to use correct author field
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-devfront committed Feb 4, 2025
1 parent 39e846d commit bf13e4c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/Command/UpdateLicensesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,38 @@ private function addLicenseToJsonFile(SplFileInfo $file): bool

$content = json_decode($file->getContents(), true);
$oldContent = $content;
$content['author'] = 'PrestaShop';

$authorDetails = [
'name' => 'PrestaShop SA',
'email' => '[email protected]',
];

// update author information depending of file
if ('composer.json' === $file->getFilename()) {
$content['authors'] = [$authorDetails];
} else { // package.json
$content['author'] = $authorDetails;
}

$content['license'] = (false !== strpos($this->license, 'afl')) ? 'AFL-3.0' : 'OSL-3.0';

$encodedContent = json_encode($content, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

// add blank line in end of file if not exist
if (substr($encodedContent, -1) !== "\n") {

Check failure on line 428 in src/Command/UpdateLicensesCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $string of function substr expects string, string|false given.
$encodedContent .= "\n";
}

if (!$this->runAsDry) {
$result = file_put_contents(
$this->targetDirectory . '/' . $file->getRelativePathname(),
json_encode($content, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
$encodedContent
);
} else {
$result = true;
}

$newFileContent = (string) json_encode($content);
$oldFileContent = (string) json_encode($oldContent);

$this->reportOperationResult($newFileContent, $oldFileContent, $file->getFilename());
$this->reportOperationResult($encodedContent, json_encode($oldContent), $file->getFilename());

Check failure on line 441 in src/Command/UpdateLicensesCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $newFileContent of method PrestaShop\HeaderStamp\Command\UpdateLicensesCommand::reportOperationResult() expects string, string|false given.

Check failure on line 441 in src/Command/UpdateLicensesCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #2 $oldFileContent of method PrestaShop\HeaderStamp\Command\UpdateLicensesCommand::reportOperationResult() expects string, string|false given.

return false !== $result;
}
Expand Down

0 comments on commit bf13e4c

Please sign in to comment.