Skip to content

Commit

Permalink
Merge pull request #54 from pluswerk/bugfix/use-minimal-typo3-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Feb 3, 2023
2 parents 41197ca + 835afa8 commit 2913700
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/RectorSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public static function sets(bool $entirety = false): array
*/
public static function setsTypo3(bool $entirety = false): array
{
if (!VersionUtility::isInstalled('typo3/cms-core')) {
$minimalTypo3Version = VersionUtility::getMinimalTypo3Version();
if (!$minimalTypo3Version) {
return [];
}

[$typo3MajorVersion] = explode('.', (string)VersionUtility::getVersion('typo3/cms-core'), 2);
[$typo3MajorVersion] = explode('.', $minimalTypo3Version, 2);
$setList = constant(Typo3SetList::class . '::TYPO3_' . $typo3MajorVersion);
if ($entirety) {
$setList = constant(Typo3LevelSetList::class . '::UP_TO_TYPO3_' . $typo3MajorVersion);
Expand Down
40 changes: 25 additions & 15 deletions src/VersionUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@ final class VersionUtility

public static function getMinimalPhpVersion(): ?string
{
$phpVersionConstrain = self::getRootComposerJsonData()['require']['php'] ?? false;
if (!$phpVersionConstrain) {
return null;
}

if (!is_string($phpVersionConstrain)) {
return null;
}

$parser = new VersionParser();
$lowerPhpVersion = $parser->parseConstraints($phpVersionConstrain)->getLowerBound()->getVersion();
if (!preg_match('#(?<major>\d)\.(?<minor>\d)\..*#', $lowerPhpVersion, $matches)) {
return null;
}
return self::getMinimalVersion('php');
}

return $matches['major'] . $matches['minor'];
public static function getMinimalTypo3Version(): ?string
{
return self::getMinimalVersion('typo3/cms-core');
}

/**
Expand Down Expand Up @@ -79,4 +69,24 @@ private static function readJson(string $file): array
{
return json_decode((string)(file_get_contents($file)), true, 512, JSON_THROW_ON_ERROR) ?: [];
}

private static function getMinimalVersion(string $packageName): ?string
{
$versionConstrain = self::getRootComposerJsonData()['require'][$packageName] ?? false;
if (!$versionConstrain) {
return null;
}

if (!is_string($versionConstrain)) {
return null;
}

$parser = new VersionParser();
$lowerVersion = $parser->parseConstraints($versionConstrain)->getLowerBound()->getVersion();
if (!preg_match('#(?<major>\d+)\.(?<minor>\d+)\..*#', $lowerVersion, $matches)) {
return null;
}

return $matches['major'] . $matches['minor'];
}
}

0 comments on commit 2913700

Please sign in to comment.