Skip to content

Commit

Permalink
update src and test files
Browse files Browse the repository at this point in the history
use more type hints where possible
  • Loading branch information
alcohol committed May 2, 2019
1 parent 795e091 commit 7297e61
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 501 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/node_modules/
/vendor/
/.php_cs.cache
/.phpunit.result.cache
/composer.phar
/phpunit.xml
/satis.phar
1 change: 0 additions & 1 deletion bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
set -e

isCommand() {
for cmd in \
Expand Down
51 changes: 8 additions & 43 deletions src/Builder/ArchiveBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
63 changes: 5 additions & 58 deletions src/Builder/ArchiveBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'];
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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)) {
Expand All @@ -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 = [];

Expand Down
20 changes: 2 additions & 18 deletions src/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 0 additions & 5 deletions src/Builder/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

use Composer\Package\PackageInterface;

/**
* Builder interface.
*
* @author James Hautot <[email protected]>
*/
interface BuilderInterface
{
/**
Expand Down
Loading

0 comments on commit 7297e61

Please sign in to comment.