Skip to content
This repository was archived by the owner on Oct 5, 2026. It is now read-only.
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
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"require": {
"php": ">=8.4",
"composer/semver": "^3.4",
"entropy/entropy": "^0.4",
"nette/utils": "^4.1",
"symfony/process": "^8.1",
"webmozart/assert": "^2.4"
"entropy/entropy": "^0.4.17",
"symfony/process": "^8.1"
},
"require-dev": {
"symplify/easy-coding-standard": "^13.2",
Expand Down
4 changes: 2 additions & 2 deletions src/Command/BreakPointCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Nette\Utils\Json;
use Entropy\Utils\Json;
use Rector\Jack\Composer\ComposerOutdatedResponseProvider;
use Rector\Jack\Enum\ComposerKey;
use Rector\Jack\OutdatedComposerFactory;
Expand All @@ -34,7 +34,7 @@ public function run(bool $dev = false, int $limit = 5, int $minDays = 0, array $

$responseJsonContents = $this->composerOutdatedResponseProvider->provide();

$responseJson = Json::decode($responseJsonContents, true);
$responseJson = Json::decode($responseJsonContents);
if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) {
$this->outputPrinter->green('All packages are up to date');

Expand Down
8 changes: 4 additions & 4 deletions src/Command/OpenVersionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Nette\Utils\FileSystem;
use Nette\Utils\Json;
use Entropy\Utils\FileSystem;
use Entropy\Utils\Json;
use Rector\Jack\Composer\ComposerOutdatedResponseProvider;
use Rector\Jack\ComposerProcessor\OpenVersionsComposerProcessor;
use Rector\Jack\Enum\ComposerKey;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function run(int $limit = 5, bool $dryRun = false, bool $dev = false, ?st

$responseJsonContents = $this->composerOutdatedResponseProvider->provide();

$responseJson = Json::decode($responseJsonContents, true);
$responseJson = Json::decode($responseJsonContents);
if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) {
$this->outputPrinter->greenBackground('All packages are up to date. You are the best!');

Expand Down Expand Up @@ -98,7 +98,7 @@ public function run(int $limit = 5, bool $dryRun = false, bool $dev = false, ?st

if ($dryRun === false) {
// update composer.json file, only if no --dry-run
FileSystem::write($composerJsonFilePath, rtrim($changedComposerJson) . PHP_EOL, null);
FileSystem::write($composerJsonFilePath, rtrim($changedComposerJson) . PHP_EOL);
}

$this->outputPrinter->greenBackground(
Expand Down
6 changes: 3 additions & 3 deletions src/Command/RaiseToInstalledCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Entropy\Console\Contract\CommandInterface;
use Entropy\Console\Enum\ExitCode;
use Entropy\Console\Output\OutputPrinter;
use Nette\Utils\FileSystem;
use Entropy\Utils\FileSystem;
use Entropy\Validation\Assert;
use Rector\Jack\ComposerProcessor\RaiseToInstalledComposerProcessor;
use Webmozart\Assert\Assert;

final readonly class RaiseToInstalledCommand implements CommandInterface
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public function run(bool $dryRun = false): int

if ($dryRun === false) {
$changedComposerJsonContents = $changedPackageVersionsResult->getComposerJsonContents();
FileSystem::write($composerJsonFilePath, rtrim($changedComposerJsonContents) . PHP_EOL, null);
FileSystem::write($composerJsonFilePath, rtrim($changedComposerJsonContents) . PHP_EOL);
}

$this->outputPrinter->greenBackground(sprintf(
Expand Down
5 changes: 3 additions & 2 deletions src/Composer/ComposerOutdatedResponseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Jack\Composer;

use Nette\Utils\FileSystem;
use Entropy\Utils\FileSystem;
use Symfony\Component\Process\Process;

final class ComposerOutdatedResponseProvider
Expand Down Expand Up @@ -34,7 +34,8 @@ public function provide(): string
$processResult = $composerOutdatedProcess->getOutput();

if (is_string($composerOutdatedFilePath)) {
FileSystem::write($composerOutdatedFilePath, $processResult, null);
FileSystem::ensureDirectoryExists(dirname($composerOutdatedFilePath));
FileSystem::write($composerOutdatedFilePath, $processResult);
}

return $processResult;
Expand Down
6 changes: 4 additions & 2 deletions src/Composer/InstalledVersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Rector\Jack\Composer;

use Rector\Jack\Exception\ShouldNotHappenException;
use Rector\Jack\Utils\JsonFileLoader;
use Webmozart\Assert\Assert;

final class InstalledVersionResolver
{
Expand All @@ -17,7 +17,9 @@ public function resolve(): array
$installedJsonFilePath = getcwd() . '/vendor/composer/installed.json';

$installedJson = JsonFileLoader::loadFileToJson($installedJsonFilePath);
Assert::keyExists($installedJson, 'packages');
if (! array_key_exists('packages', $installedJson)) {
throw new ShouldNotHappenException('Missing "packages" key in "installed.json"');
}

$installedPackagesToVersions = [];
foreach ($installedJson['packages'] as $installedPackage) {
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/NextVersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\Jack\Composer;

use Composer\Semver\VersionParser;
use Nette\Utils\Strings;
use Entropy\Utils\Regex;
use Rector\Jack\Exception\ShouldNotHappenException;

/**
Expand All @@ -27,12 +27,12 @@ public function resolve(string $packageName, string $composerVersion): string
$constraint = $this->versionParser->parseConstraints($composerVersion);

$nextBound = $constraint->getUpperBound();
$matchVersion = Strings::match(
$matchVersion = Regex::match(
$nextBound->getVersion(),
'#^(?<' . self::MAJOR . '>\d+)\.(?<' . self::MINOR . '>\d+)#'
);

if ($matchVersion === null) {
if ($matchVersion === []) {
throw new ShouldNotHappenException(
sprintf('Unable to parse major and minor value from composer version "%s"', $composerVersion)
);
Expand Down
6 changes: 3 additions & 3 deletions src/ComposerProcessor/RaiseToInstalledComposerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Composer\Semver\Comparator;
use Composer\Semver\VersionParser;
use Entropy\Attributes\RelatedTest;
use Nette\Utils\Json;
use Entropy\Attribute\RelatedTest;
use Entropy\Utils\Json;
use Rector\Jack\Composer\InstalledVersionResolver;
use Rector\Jack\Composer\VersionComparator;
use Rector\Jack\FileSystem\ComposerJsonPackageVersionUpdater;
Expand All @@ -27,7 +27,7 @@ public function __construct(
public function process(string $composerJsonContents): ChangedPackageVersionsResult
{
$installedPackagesToVersions = $this->installedVersionResolver->resolve();
$composerJson = Json::decode($composerJsonContents, true);
$composerJson = Json::decode($composerJsonContents);

$changedPackageVersions = [];

Expand Down
10 changes: 5 additions & 5 deletions src/FileSystem/ComposerJsonPackageVersionUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Rector\Jack\FileSystem;

use Nette\Utils\Strings;
use Entropy\Utils\Regex;

final class ComposerJsonPackageVersionUpdater
{
public static function update(string $composerJsonContents, string $packageName, string $newVersion): string
{
// replace using regex, to keep original composer.json format
$allChanges = Strings::replace(
$allChanges = Regex::replace(
$composerJsonContents,
// find
sprintf('#"%s": "(.*?)"#', $packageName),
Expand All @@ -23,10 +23,10 @@ public static function update(string $composerJsonContents, string $packageName,

foreach ($skippedKeys as $skippedKey) {
$regexKeyContent = sprintf('#"%s"\s*:\s*{[^}]*}#', $skippedKey);
$skippedContent = Strings::match($composerJsonContents, $regexKeyContent);
$skippedContent = Regex::match($composerJsonContents, $regexKeyContent);

if ($skippedContent !== null) {
$allChanges = Strings::replace($allChanges, $regexKeyContent, $skippedContent[0]);
if (isset($skippedContent[0]) && is_string($skippedContent[0])) {
$allChanges = Regex::replace($allChanges, $regexKeyContent, $skippedContent[0]);
}
}

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

namespace Rector\Jack\Utils;

use Nette\Utils\FileSystem;
use Nette\Utils\Json;
use Webmozart\Assert\Assert;
use Entropy\Utils\FileSystem;
use Entropy\Utils\Json;
use Entropy\Validation\Assert;

final class JsonFileLoader
{
Expand All @@ -19,6 +19,6 @@ public static function loadFileToJson(string $filePath): array

$fileContents = FileSystem::read($filePath);

return Json::decode($fileContents, true);
return Json::decode($fileContents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Rector\Jack\ValueObject\ComposerProcessorResult;

use Entropy\Validation\Assert;
use Rector\Jack\ValueObject\ChangedPackageVersion;
use Webmozart\Assert\Assert;

final readonly class ChangedPackageVersionsResult
{
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObject/OutdatedComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Jack\ValueObject;

use Webmozart\Assert\Assert;
use Entropy\Validation\Assert;

final readonly class OutdatedComposer
{
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/OutdatedPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Jack\ValueObject;

use Nette\Utils\Strings;
use Entropy\Utils\Regex;

final readonly class OutdatedPackage
{
Expand Down Expand Up @@ -55,8 +55,8 @@ public function isVeryOld(): bool
return true;
}

$matchYears = Strings::match($this->currentVersionAge, '#[3-9] years#');
return $matchYears !== null;
$matchYears = Regex::match($this->currentVersionAge, '#[3-9] years#');
return $matchYears !== [];
}

public function lastestIsDevBranch(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Jack\Tests\ComposerProcessor\OpenVersionsComposerProcessor;

use Nette\Utils\FileSystem;
use Entropy\Utils\FileSystem;
use Rector\Jack\ComposerProcessor\OpenVersionsComposerProcessor;
use Rector\Jack\Tests\AbstractTestCase;
use Rector\Jack\ValueObject\ChangedPackageVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\Jack\Tests\ComposerProcessor\RaiseToInstalledComposerProcessor;

use Nette\Utils\FileSystem;
use Entropy\Utils\FileSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Jack\ComposerProcessor\RaiseToInstalledComposerProcessor;
use Rector\Jack\Tests\AbstractTestCase;
Expand Down
Loading