-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f13181
commit 803e63a
Showing
5 changed files
with
88 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SwissKnife\Composer; | ||
|
||
use Nette\Utils\FileSystem; | ||
use Rector\SwissKnife\ValueObject\ComposerJson; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ComposerJsonResolver | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const TEMP_PROJECT_COMPOSER_JSON = 'temp-project-composer.json'; | ||
|
||
/** | ||
* @param string[] $repositories | ||
* @return ComposerJson[] | ||
*/ | ||
public function resolveFromRepositories(array $repositories): array | ||
{ | ||
Assert::allString($repositories); | ||
|
||
$projectsComposerJsons = []; | ||
foreach ($repositories as $repository) { | ||
// clones only "composer.json" file | ||
exec(sprintf( | ||
'git archive --remote=%s HEAD composer.json | tar -xO composer.json > %s', | ||
$repository, | ||
self::TEMP_PROJECT_COMPOSER_JSON | ||
)); | ||
|
||
$projectsComposerJsonContents = FileSystem::read(self::TEMP_PROJECT_COMPOSER_JSON); | ||
|
||
Assert::string($projectsComposerJsonContents); | ||
Assert::notEmpty($projectsComposerJsonContents); | ||
|
||
$projectsComposerJsons[] = new ComposerJson($repository, $projectsComposerJsonContents); | ||
} | ||
|
||
// tidy up temporary file | ||
FileSystem::delete(self::TEMP_PROJECT_COMPOSER_JSON); | ||
|
||
return $projectsComposerJsons; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SwissKnife\Sorting; | ||
|
||
use Webmozart\Assert\Assert; | ||
|
||
final class ArrayFilter | ||
{ | ||
/** | ||
* @param array<mixed[]> $items | ||
* @return array<mixed[]> | ||
*/ | ||
public static function filterOnlyAtLeast2(array $items): array | ||
{ | ||
Assert::allIsArray($items); | ||
|
||
return array_filter($items, function (array $item): bool { | ||
$nonEmptyValues = array_filter($item); | ||
|
||
// +1 for the package name | ||
return count($nonEmptyValues) >= 3; | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters