diff --git a/src/Helper.php b/src/Helper.php index 817605b..f96bc32 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -20,17 +20,12 @@ */ class Helper { - public static function className() - { - return get_called_class(); - } - /** * Merges two or more arrays into one recursively. * Based on Yii2 yii\helpers\BaseArrayHelper::merge. * @return array the merged array */ - public static function mergeConfig() + public static function mergeConfig(): array { $args = func_get_args(); $res = array_shift($args) ?: []; @@ -62,7 +57,7 @@ public static function mergeConfig() * @param Closure $closure * @return string */ - public static function dumpClosure(Closure $closure) + public static function dumpClosure(Closure $closure): string { $res = 'function ('; $fun = new ReflectionFunction($closure); @@ -99,7 +94,7 @@ public static function dumpClosure(Closure $closure) * @param mixed $value * @return string */ - public static function exportVar($value) + public static function exportVar($value): string { $closures = self::collectClosures($value); $res = var_export($value, true); @@ -114,7 +109,7 @@ public static function exportVar($value) return $res; } - public static function exportDefines(array $defines) + public static function exportDefines(array $defines): string { $res = ''; foreach ($defines as $key => $value) { @@ -131,7 +126,7 @@ public static function exportDefines(array $defines) * @param mixed $input will be changed * @return array array of found closures */ - private static function collectClosures(&$input) + private static function collectClosures(&$input): array { static $closureNo = 1; $closures = []; diff --git a/src/configs/Config.php b/src/configs/Config.php index 9075a2c..41d75e7 100644 --- a/src/configs/Config.php +++ b/src/configs/Config.php @@ -66,7 +66,7 @@ public function getValues(): array return $this->values; } - public function load(array $paths = []) + public function load(array $paths = []): self { $configs = []; foreach ($paths as $path) { @@ -86,7 +86,7 @@ public function load(array $paths = []) * @param string $path * @return array configuration read from file */ - protected function loadFile($path) + protected function loadFile($path): array { $reader = ReaderFactory::get($this->builder, $path); @@ -98,28 +98,28 @@ protected function loadFile($path) * @param mixed $name * @param array $configs */ - public function build() + public function build(): self { $this->values = $this->calcValues($this->sources); return $this; } - public function write() + public function write(): self { $this->writeFile($this->getOutputPath(), $this->values); return $this; } - protected function calcValues(array $sources) + protected function calcValues(array $sources): array { $values = call_user_func_array([Helper::class, 'mergeConfig'], $sources); return $this->substituteOutputDirs($values); } - protected function writeFile(string $path, array $data) + protected function writeFile(string $path, array $data): void { $this->writePhpFile($path, $data, true); } @@ -130,7 +130,7 @@ protected function writeFile(string $path, array $data) * @param string|array $data * @param bool $withEnvAndDefines */ - protected function writePhpFile(string $path, $data, bool $withEnvAndDefines) + protected function writePhpFile(string $path, $data, bool $withEnvAndDefines): void { static::putFile($path, $this->replaceMarkers(implode("\n\n", array_filter([ 'header' => 'getOutputDir())))); @@ -190,7 +194,7 @@ public function substituteOutputDirs(array $data) * @param string $ds directory separator * @return string */ - public static function normalizePath($path, $ds = self::UNIX_DS) + public static function normalizePath($path, $ds = self::UNIX_DS): string { return rtrim(strtr($path, '/\\', $ds . $ds), $ds); } @@ -202,7 +206,7 @@ public static function normalizePath($path, $ds = self::UNIX_DS) * @param string $alias * @return array */ - public static function substitutePaths($data, $dir, $alias) + public static function substitutePaths($data, $dir, $alias): array { foreach ($data as &$value) { if (is_string($value)) { @@ -222,7 +226,7 @@ public static function substitutePaths($data, $dir, $alias) * @param string $alias * @return string */ - protected static function substitutePath($path, $dir, $alias) + protected static function substitutePath($path, $dir, $alias): string { $end = $dir . self::UNIX_DS; $skippable = 0 === strncmp($path, '?', 1) ? '?' : ''; diff --git a/src/configs/Defines.php b/src/configs/Defines.php index 15fe70a..a5d8235 100644 --- a/src/configs/Defines.php +++ b/src/configs/Defines.php @@ -17,7 +17,7 @@ */ class Defines extends Config { - protected function loadFile($path) + protected function loadFile($path): array { parent::loadFile($path); if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') { @@ -37,7 +37,7 @@ public function buildRequires(): string return implode("\n", $res); } - protected function writeFile(string $path, array $data) + protected function writeFile(string $path, array $data): void { $this->writePhpFile($path, $this->buildRequires(), false); } diff --git a/src/configs/DotEnv.php b/src/configs/DotEnv.php index 273d504..40b6843 100644 --- a/src/configs/DotEnv.php +++ b/src/configs/DotEnv.php @@ -17,7 +17,7 @@ */ class DotEnv extends Config { - protected function writeFile(string $path, array $data) + protected function writeFile(string $path, array $data): void { $this->writePhpFile($path, $data, false); } diff --git a/src/configs/Params.php b/src/configs/Params.php index 86c79df..4c9307a 100644 --- a/src/configs/Params.php +++ b/src/configs/Params.php @@ -17,12 +17,12 @@ */ class Params extends Config { - protected function calcValues(array $sources) + protected function calcValues(array $sources): array { return $this->pushEnvVars(parent::calcValues($sources)); } - protected function pushEnvVars($vars) + protected function pushEnvVars($vars): array { $env = $this->builder->getConfig('dotenv')->getValues(); if (!empty($vars)) { diff --git a/src/configs/Rebuild.php b/src/configs/Rebuild.php index b371bc0..af92420 100644 --- a/src/configs/Rebuild.php +++ b/src/configs/Rebuild.php @@ -17,7 +17,7 @@ */ class Rebuild extends Config { - protected function writeFile(string $path, array $data) + protected function writeFile(string $path, array $data): void { static::putFile($path, file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '__rebuild.php')); } diff --git a/src/configs/System.php b/src/configs/System.php index 3741710..d982293 100644 --- a/src/configs/System.php +++ b/src/configs/System.php @@ -18,29 +18,33 @@ */ class System extends Config { - public function setValue(string $name, $value) + public function setValue(string $name, $value): Config { $this->values[$name] = $value; + + return $this; } - public function setValues(array $values) + public function setValues(array $values): Config { $this->values = $values; return $this; } - public function mergeValues(array $values) + public function mergeValues(array $values): Config { $this->values = array_merge($this->values, $values); + + return $this; } - protected function writeFile(string $path, array $data) + protected function writeFile(string $path, array $data): void { $this->writePhpFile($path, $data, false); } - public function load(array $paths = []) + public function load(array $paths = []): Config { $path = $this->getOutputPath(); if (!file_exists($path)) { @@ -52,7 +56,7 @@ public function load(array $paths = []) return $this; } - public function build() + public function build(): Config { $this->values = $this->substituteOutputDirs($this->values);