diff --git a/src/Builder.php b/src/Builder.php index 2c98dd2..0c3f403 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -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; diff --git a/src/Helper.php b/src/Helper.php index 62e937e..1a0b1df 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -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; @@ -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 { @@ -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)); } } @@ -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 { diff --git a/src/Package.php b/src/Package.php index 601f1b1..6b8e006 100644 --- a/src/Package.php +++ b/src/Package.php @@ -44,6 +44,8 @@ class Package */ protected $filesystem; + private $composer; + public function __construct(PackageInterface $package, Composer $composer) { $this->package = $package; @@ -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) @@ -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 diff --git a/src/Plugin.php b/src/Plugin.php index 7aef851..be70727 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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 @@ -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` */ @@ -304,6 +306,4 @@ protected function showDepsTree() $this->io->write(sprintf('%s - %s %s %s', $indent, $color, $name, $package->getFullPrettyVersion(), $showdeps)); } } - - protected $colors = ['red', 'green', 'yellow', 'cyan', 'magenta', 'blue']; } diff --git a/src/configs/Config.php b/src/configs/Config.php index 0aa009a..73a5f4d 100644 --- a/src/configs/Config.php +++ b/src/configs/Config.php @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/src/configs/ConfigFactory.php b/src/configs/ConfigFactory.php index e663f1d..1d2f889 100644 --- a/src/configs/ConfigFactory.php +++ b/src/configs/ConfigFactory.php @@ -20,8 +20,6 @@ */ class ConfigFactory { - private static $loaders; - private static $knownTypes = [ '__rebuild' => Rebuild::class, '__files' => System::class, @@ -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); } diff --git a/src/readers/EnvReader.php b/src/readers/EnvReader.php index 7587947..645c459 100644 --- a/src/readers/EnvReader.php +++ b/src/readers/EnvReader.php @@ -10,6 +10,8 @@ namespace hiqdev\composer\config\readers; +use hiqdev\composer\config\exceptions\UnsupportedFileTypeException; + /** * EnvReader - reads `.env` files. * diff --git a/src/readers/YamlReader.php b/src/readers/YamlReader.php index c7b6caa..746cf32 100644 --- a/src/readers/YamlReader.php +++ b/src/readers/YamlReader.php @@ -10,6 +10,8 @@ namespace hiqdev\composer\config\readers; +use hiqdev\composer\config\exceptions\UnsupportedFileTypeException; + /** * YamlReader - reads YAML files. *