Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #16

Merged
merged 8 commits into from
Oct 8, 2018
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
2 changes: 1 addition & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function findOutputDir($vendor = null)
if ($vendor) {
$dir = $vendor . '/hiqdev/' . basename(dirname(__DIR__));
} else {
$dir = dirname(__DIR__);
$dir = \dirname(__DIR__);
}

return $dir . static::OUTPUT_DIR_SUFFIX;
Expand Down
14 changes: 8 additions & 6 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class Helper
*/
public static function mergeConfig(): array
{
$args = func_get_args();
$args = \func_get_args();
$res = array_shift($args) ?: [];
foreach ($args as $items) {
if (!is_array($items)) {
if (!\is_array($items)) {
continue;
}
foreach ($items as $k => $v) {
if (is_int($k)) {
if (\is_int($k)) {
if (isset($res[$k])) {
$res[] = $v;
} else {
$res[$k] = $v;
}
} elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) {
} elseif (\is_array($v) && isset($res[$k]) && \is_array($res[$k])) {
$res[$k] = self::mergeConfig($res[$k], $v);
} else {
$res[$k] = $v;
Expand All @@ -67,6 +67,7 @@ public static function exportDefines(array $defines): string
* In contrast to var_dump outputs Closures as PHP code.
* @param mixed $value
* @return string
* @throws \ReflectionException
*/
public static function exportVar($value): string
{
Expand All @@ -93,9 +94,9 @@ private static function collectClosures(&$input): array
{
static $closureNo = 1;
$closures = [];
if (is_array($input)) {
if (\is_array($input)) {
foreach ($input as &$value) {
if (is_array($value) || $value instanceof Closure) {
if (\is_array($value) || $value instanceof Closure) {
$closures = array_merge($closures, self::collectClosures($value));
}
}
Expand All @@ -114,6 +115,7 @@ private static function collectClosures(&$input): array
* Based on http://www.metashock.de/2013/05/dump-source-code-of-closure-in-php/.
* @param Closure $closure
* @return string
* @throws \ReflectionException
*/
public static function dumpClosure(Closure $closure): string
{
Expand Down
6 changes: 4 additions & 2 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Package
*/
protected $filesystem;

private $composer;

public function __construct(PackageInterface $package, Composer $composer)
{
$this->package = $package;
Expand Down Expand Up @@ -73,6 +75,7 @@ public function collectAliases(): array
/**
* Prepare aliases.
* @param string 'psr-0' or 'psr-4'
* @param bool $dev
* @return array
*/
protected function prepareAliases($psr, $dev = false)
Expand Down Expand Up @@ -244,8 +247,7 @@ protected function readRawData(): array

/**
* Builds path inside of a package.
* @param Package $package
* @param mixed $path can be absolute or relative
* @param string $file
* @return string absolute paths will stay untouched
*/
public function preparePath(string $file): string
Expand Down
6 changes: 3 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class Plugin implements PluginInterface, EventSubscriberInterface
{
const EXTRA_OPTION_NAME = 'config-plugin';
private const EXTRA_OPTION_NAME = 'config-plugin';

/**
* @var Package[] the array of active composer packages
Expand All @@ -41,6 +41,8 @@ class Plugin implements PluginInterface, EventSubscriberInterface
'params' => [],
];

protected $colors = ['red', 'green', 'yellow', 'cyan', 'magenta', 'blue'];

/**
* @var array package name => configs as listed in `composer.json`
*/
Expand Down Expand Up @@ -304,6 +306,4 @@ protected function showDepsTree()
$this->io->write(sprintf('%s - <fg=%s;options=bold>%s</> %s %s', $indent, $color, $name, $package->getFullPrettyVersion(), $showdeps));
}
}

protected $colors = ['red', 'green', 'yellow', 'cyan', 'magenta', 'blue'];
}
7 changes: 5 additions & 2 deletions src/configs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ protected function loadFile($path): array

/**
* Merges given configs and writes at given name.
* @param mixed $name
* @param array $configs
* @return Config
*/
public function build(): self
{
Expand Down Expand Up @@ -130,6 +129,8 @@ protected function writeFile(string $path, array $data): void
* @param string|array $data
* @param bool $withEnv
* @param bool $withDefines
* @throws FailedWriteException
* @throws \ReflectionException
*/
protected function writePhpFile(string $path, $data, bool $withEnv, bool $withDefines): void
{
Expand All @@ -146,6 +147,7 @@ protected function writePhpFile(string $path, $data, bool $withEnv, bool $withDe
/**
* @param array $vars array to be exported
* @return string
* @throws \ReflectionException
*/
protected function renderVars(array $vars): string
{
Expand All @@ -163,6 +165,7 @@ protected function replaceMarkers(string $content): string
* Writes file if content changed.
* @param string $path
* @param string $content
* @throws FailedWriteException
*/
protected static function putFile($path, $content): void
{
Expand Down
10 changes: 4 additions & 6 deletions src/configs/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
class ConfigFactory
{
private static $loaders;

private static $knownTypes = [
'__rebuild' => Rebuild::class,
'__files' => System::class,
Expand All @@ -33,13 +31,13 @@ class ConfigFactory
];

/**
* @param Builder $builder
* @param string $name
* @return Config
*/
public static function create(Builder $builder, string $name)
public static function create(Builder $builder, string $name): Config
{
$class = isset(static::$knownTypes[$name])
? static::$knownTypes[$name]
: Config::class;
$class = static::$knownTypes[$name] ?? Config::class;

return new $class($builder, $name);
}
Expand Down
2 changes: 2 additions & 0 deletions src/readers/EnvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace hiqdev\composer\config\readers;

use hiqdev\composer\config\exceptions\UnsupportedFileTypeException;

/**
* EnvReader - reads `.env` files.
*
Expand Down
2 changes: 2 additions & 0 deletions src/readers/YamlReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace hiqdev\composer\config\readers;

use hiqdev\composer\config\exceptions\UnsupportedFileTypeException;

/**
* YamlReader - reads YAML files.
*
Expand Down