From 0c8c8214be3e8789e41737495424216ff5b92070 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Thu, 20 Dec 2018 12:28:13 +0200 Subject: [PATCH] Added `Plugin::addFile()` and used in loadDotEnv to prevent dublicating --- src/Plugin.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 78b67de..77f8d1c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -155,7 +155,7 @@ protected function loadDotEnv(Package $package) { $path = $package->preparePath('.env'); if (file_exists($path) && class_exists('Dotenv\Dotenv')) { - array_push($this->files['dotenv'], $path); + $this->addFile($package, 'dotenv', $path); } } @@ -174,22 +174,27 @@ protected function addFiles(Package $package, array $files) $paths = array_reverse($paths); } foreach ($paths as $path) { - if (!isset($this->files[$name])) { - $this->files[$name] = []; - } - $path = $package->preparePath($path); - if (in_array($path, $this->files[$name], true)) { - continue; - } - if ('defines' === $name) { - array_unshift($this->files[$name], $path); - } else { - array_push($this->files[$name], $path); - } + $this->addFile($package, $name, $path); } } } + protected function addFile(Package $package, string $name, string $path) + { + $path = $package->preparePath($path); + if (!isset($this->files[$name])) { + $this->files[$name] = []; + } + if (in_array($path, $this->files[$name], true)) { + return; + } + if ('defines' === $name) { + array_unshift($this->files[$name], $path); + } else { + array_push($this->files[$name], $path); + } + } + /** * Sets [[packages]]. * @param Package[] $packages