forked from composer/satis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use more type hints where possible
- Loading branch information
Showing
22 changed files
with
158 additions
and
501 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/node_modules/ | ||
/vendor/ | ||
/.php_cs.cache | ||
/.phpunit.result.cache | ||
/composer.phar | ||
/phpunit.xml | ||
/satis.phar |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
isCommand() { | ||
for cmd in \ | ||
|
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 |
---|---|---|
|
@@ -17,29 +17,21 @@ | |
use Composer\Downloader\DownloadManager; | ||
use Composer\Factory; | ||
use Composer\Package\Archiver\ArchiveManager; | ||
use Composer\Package\CompletePackage; | ||
use Composer\Package\PackageInterface; | ||
use Composer\Util\Filesystem; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Builds the archives of the repository. | ||
* | ||
* @author James Hautot <[email protected]> | ||
*/ | ||
class ArchiveBuilder extends Builder | ||
{ | ||
/** @var Composer A Composer instance. */ | ||
private $composer; | ||
|
||
/** @var InputInterface */ | ||
private $input; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function dump(array $packages) | ||
public function dump(array $packages): void | ||
{ | ||
$helper = new ArchiveBuilderHelper($this->output, $this->config['archive']); | ||
$basedir = $helper->getDirectory($this->outputDir); | ||
|
@@ -48,9 +40,9 @@ public function dump(array $packages) | |
$includeArchiveChecksum = (bool) ($this->config['archive']['checksum'] ?? true); | ||
$composerConfig = $this->composer->getConfig(); | ||
$factory = new Factory(); | ||
/* @var \Composer\Downloader\DownloadManager $downloadManager */ | ||
/* @var DownloadManager $downloadManager */ | ||
$downloadManager = $this->composer->getDownloadManager(); | ||
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */ | ||
/* @var ArchiveManager $archiveManager */ | ||
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager); | ||
$archiveManager->setOverwriteFiles(false); | ||
|
||
|
@@ -76,7 +68,7 @@ public function dump(array $packages) | |
); | ||
} | ||
|
||
/* @var \Composer\Package\CompletePackage $package */ | ||
/* @var CompletePackage $package */ | ||
foreach ($packages as $package) { | ||
if ($helper->isSkippable($package)) { | ||
continue; | ||
|
@@ -173,48 +165,21 @@ public function dump(array $packages) | |
} | ||
} | ||
|
||
/** | ||
* Sets the Composer instance. | ||
* | ||
* @param Composer $composer A Composer instance | ||
* | ||
* @return $this | ||
*/ | ||
public function setComposer(Composer $composer) | ||
public function setComposer(Composer $composer): self | ||
{ | ||
$this->composer = $composer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* | ||
* @return $this; | ||
*/ | ||
public function setInput(InputInterface $input) | ||
public function setInput(InputInterface $input): self | ||
{ | ||
$this->input = $input; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Archive a package if it is missing | ||
* | ||
* @param DownloadManager $downloadManager | ||
* DownloadManager used to retrieve existing archives under distSource | ||
* @param ArchiveManager $archiveManager | ||
* ArchiveManager used to create archives | ||
* @param PackageInterface $package | ||
* The Package to save | ||
* @param string $targetDir | ||
* Directory for the archive file | ||
* | ||
* @return string | ||
* The filename of the archive | ||
*/ | ||
private function archive(DownloadManager $downloadManager, ArchiveManager $archiveManager, PackageInterface $package, string $targetDir) | ||
private function archive(DownloadManager $downloadManager, ArchiveManager $archiveManager, PackageInterface $package, string $targetDir): string | ||
{ | ||
$format = (string) ($this->config['archive']['format'] ?? 'zip'); | ||
$ignoreFilters = (bool) ($this->config['archive']['ignore-filters'] ?? false); | ||
|
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 |
---|---|---|
|
@@ -16,25 +16,13 @@ | |
use Composer\Package\PackageInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Builds the archives of the repository. | ||
* | ||
* @author James Hautot <[email protected]> | ||
*/ | ||
class ArchiveBuilderHelper | ||
{ | ||
/** @var OutputInterface The output Interface. */ | ||
private $output; | ||
|
||
/** @var array The 'archive' part of a configuration file. */ | ||
private $archiveConfig; | ||
|
||
/** | ||
* Helper Constructor. | ||
* | ||
* @param OutputInterface $output The output Interface | ||
* @param array $archiveConfig The 'archive' part of a configuration file | ||
*/ | ||
public function __construct(OutputInterface $output, array $archiveConfig) | ||
{ | ||
$this->output = $output; | ||
|
@@ -44,14 +32,7 @@ public function __construct(OutputInterface $output, array $archiveConfig) | |
$this->archiveConfig['blacklist'] = (array) ($archiveConfig['blacklist'] ?? []); | ||
} | ||
|
||
/** | ||
* Gets the directory where to dump archives. | ||
* | ||
* @param string $outputDir The directory where to build | ||
* | ||
* @return string $directory The directory where to dump archives | ||
*/ | ||
public function getDirectory($outputDir) | ||
public function getDirectory(string $outputDir): string | ||
{ | ||
if (isset($this->archiveConfig['absolute-directory'])) { | ||
$directory = $this->archiveConfig['absolute-directory']; | ||
|
@@ -62,14 +43,7 @@ public function getDirectory($outputDir) | |
return $directory; | ||
} | ||
|
||
/** | ||
* Tells if a package has to be dumped or not. | ||
* | ||
* @param PackageInterface $package The package to be dumped | ||
* | ||
* @return bool false if the package has to be dumped | ||
*/ | ||
public function isSkippable(PackageInterface $package) | ||
public function isSkippable(PackageInterface $package): bool | ||
{ | ||
if ('metapackage' === $package->getType()) { | ||
return true; | ||
|
@@ -100,17 +74,7 @@ public function isSkippable(PackageInterface $package) | |
return false; | ||
} | ||
|
||
/** | ||
* Check if any of the names is in the list. | ||
* | ||
* Any * in the list is treated as a wildcard. | ||
* | ||
* @param array $names Names to check | ||
* @param array $list List to check the names against | ||
* | ||
* @return bool true if any of the names is in the list | ||
*/ | ||
protected function isOneOfNamesInList(array $names, array $list) | ||
protected function isOneOfNamesInList(array $names, array $list): bool | ||
{ | ||
$patterns = $this->convertListToRegexPatterns($list); | ||
|
||
|
@@ -123,15 +87,7 @@ protected function isOneOfNamesInList(array $names, array $list) | |
return false; | ||
} | ||
|
||
/** | ||
* Check if the name matches any of the patterns. | ||
* | ||
* @param string $name Name to check | ||
* @param array $patterns Patterns to check the name against | ||
* | ||
* @return bool true if the name matches any of the patterns | ||
*/ | ||
protected function doesNameMatchOneOfPatterns($name, array $patterns) | ||
protected function doesNameMatchOneOfPatterns(string $name, array $patterns): bool | ||
{ | ||
foreach ($patterns as $pattern) { | ||
if (preg_match($pattern, $name)) { | ||
|
@@ -142,16 +98,7 @@ protected function doesNameMatchOneOfPatterns($name, array $patterns) | |
return false; | ||
} | ||
|
||
/** | ||
* Convert a list to regex patterns for use in preg_ functions. | ||
* | ||
* Any * is replaced with .* and the rest is escaped. | ||
* | ||
* @param array $list List to convert to patterns | ||
* | ||
* @return array array of patterns | ||
*/ | ||
protected function convertListToRegexPatterns(array $list) | ||
protected function convertListToRegexPatterns(array $list): array | ||
{ | ||
$patterns = []; | ||
|
||
|
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 |
---|---|---|
|
@@ -15,38 +15,22 @@ | |
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Base class for Satis Builders. | ||
* | ||
* @author James Hautot <[email protected]> | ||
*/ | ||
abstract class Builder implements BuilderInterface | ||
{ | ||
/** @var OutputInterface $output The output Interface. */ | ||
protected $output; | ||
|
||
/** @var string $outputDir The directory where to build. */ | ||
protected $outputDir; | ||
|
||
/** @var array $config The parameters from ./satis.json. */ | ||
protected $config; | ||
|
||
/** @var bool $skipErrors Skips Exceptions if true. */ | ||
protected $skipErrors; | ||
|
||
/** | ||
* Base Constructor. | ||
* | ||
* @param OutputInterface $output The output Interface | ||
* @param string $outputDir The directory where to build | ||
* @param array $config The parameters from ./satis.json | ||
* @param bool $skipErrors Skips Exceptions if true | ||
*/ | ||
public function __construct(OutputInterface $output, $outputDir, $config, $skipErrors) | ||
public function __construct(OutputInterface $output, string $outputDir, array $config, bool $skipErrors) | ||
{ | ||
$this->output = $output; | ||
$this->outputDir = $outputDir; | ||
$this->config = $config; | ||
$this->skipErrors = (bool) $skipErrors; | ||
$this->skipErrors = $skipErrors; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,11 +15,6 @@ | |
|
||
use Composer\Package\PackageInterface; | ||
|
||
/** | ||
* Builder interface. | ||
* | ||
* @author James Hautot <[email protected]> | ||
*/ | ||
interface BuilderInterface | ||
{ | ||
/** | ||
|
Oops, something went wrong.