From 8f6abd9a98138b571b66e080c7e123b658e5c8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ayax=20C=C3=B3rdova?= Date: Sun, 24 Sep 2023 14:03:39 -0600 Subject: [PATCH] fix: rename property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ayax Córdova --- src/Package/Concerns/HasConfig.php | 54 +++++++++++++------------- src/Package/Concerns/HasMigrations.php | 46 +++++++++++----------- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/Package/Concerns/HasConfig.php b/src/Package/Concerns/HasConfig.php index 711f47b..93f9088 100644 --- a/src/Package/Concerns/HasConfig.php +++ b/src/Package/Concerns/HasConfig.php @@ -10,6 +10,8 @@ trait HasConfig protected array $configFiles = []; + protected bool $preventLoadDefaultConfigFolder = false; + protected bool $shouldIncludeConfigFromFolder = false; protected array $excludedConfig = []; @@ -21,6 +23,11 @@ public function hasConfig(): bool return $this->shouldLoadDefaultConfigFolder() || filled($this->configFiles); } + private function shouldLoadDefaultConfigFolder(): bool + { + return !$this->preventLoadDefaultConfigFolder && $this->shouldIncludeConfigFromFolder; + } + public function withConfig(string|array $config = [], bool $publish = true): static { if (filled($config)) { @@ -37,7 +44,7 @@ public function withConfig(string|array $config = [], bool $publish = true): sta public function preventDefaultConfig(): static { - $this->preventLoadDefault = true; + $this->preventLoadDefaultConfigFolder = true; return $this; } @@ -49,21 +56,23 @@ public function getRegisteredConfig(): Collection return collect($this->configFiles) ->merge($config) ->filter(function (bool $_, string $config) { - return ! in_array($config, $this->excludedConfig); + return !in_array($config, $this->excludedConfig); }) ->keys(); } - public function getPublishableConfig(): Collection + private function loadConfigDefaultFolder(): array { - $config = $this->loadConfigDefaultFolder(); + if (!$this->shouldLoadDefaultConfigFolder()) { + return []; + } - return collect($this->configFiles) - ->merge($config) - ->filter(function (bool $publish, string $config) { - return $publish && ! in_array($config, [...$this->excludedConfig, ...$this->unpublishedConfig]); - }) - ->keys(); + return $this->loadFilesFrom($this->getConfigPath())->all(); + } + + public function getConfigPath(string $path = ''): string + { + return join_paths($this->configPath, $path); } public function setConfigPath(string $path): static @@ -73,9 +82,16 @@ public function setConfigPath(string $path): static return $this; } - public function getConfigPath(string $path = ''): string + public function getPublishableConfig(): Collection { - return join_paths($this->configPath, $path); + $config = $this->loadConfigDefaultFolder(); + + return collect($this->configFiles) + ->merge($config) + ->filter(function (bool $publish, string $config) { + return $publish && !in_array($config, [...$this->excludedConfig, ...$this->unpublishedConfig]); + }) + ->keys(); } public function unregisterConfig(string $path): static @@ -91,18 +107,4 @@ public function unpublishConfig(string $path): static return $this; } - - private function shouldLoadDefaultConfigFolder(): bool - { - return ! $this->preventLoadDefault && $this->shouldIncludeConfigFromFolder; - } - - private function loadConfigDefaultFolder(): array - { - if (! $this->shouldLoadDefaultConfigFolder()) { - return []; - } - - return $this->loadFilesFrom($this->getConfigPath())->all(); - } } diff --git a/src/Package/Concerns/HasMigrations.php b/src/Package/Concerns/HasMigrations.php index 930bc41..ccebaae 100644 --- a/src/Package/Concerns/HasMigrations.php +++ b/src/Package/Concerns/HasMigrations.php @@ -10,7 +10,7 @@ trait HasMigrations protected array $migrations = []; - protected bool $preventLoadDefault = false; + protected bool $preventLoadDefaultMigrationFolder = false; protected bool $shouldIncludeMigrationsFromFolder = false; @@ -23,6 +23,11 @@ public function hasMigrations(): bool return $this->shouldLoadDefaultMigrationsFolder() || filled($this->migrations); } + private function shouldLoadDefaultMigrationsFolder(): bool + { + return !$this->preventLoadDefaultMigrationFolder && $this->shouldIncludeMigrationsFromFolder; + } + public function withMigrations(string|array $migration = [], bool $publish = true): static { if (filled($migration)) { @@ -41,7 +46,7 @@ public function withMigrations(string|array $migration = [], bool $publish = tru public function preventDefaultMigrations(): static { - $this->preventLoadDefault = true; + $this->preventLoadDefaultMigrationFolder = true; return $this; } @@ -53,11 +58,25 @@ public function getRegisteredMigrations(): Collection return collect($this->migrations) ->merge($migrations) ->filter(function (bool $_, string $migration) { - return ! in_array($migration, $this->excludedMigrations); + return !in_array($migration, $this->excludedMigrations); }) ->keys(); } + private function loadMigrationsDefaultFolder(): array + { + if (!$this->shouldLoadDefaultMigrationsFolder()) { + return []; + } + + return $this->loadFilesFrom($this->getMigrationPath())->all(); + } + + public function getMigrationPath(string $path = ''): string + { + return join_paths($this->migrationsPath, $path); + } + public function getPublishableMigrations(): Collection { $migrations = $this->loadMigrationsDefaultFolder(); @@ -65,7 +84,7 @@ public function getPublishableMigrations(): Collection return collect($this->migrations) ->merge($migrations) ->filter(function (bool $publish, string $migration) { - return $publish && ! in_array($migration, [...$this->excludedMigrations, ...$this->unpublishedMigrations]); + return $publish && !in_array($migration, [...$this->excludedMigrations, ...$this->unpublishedMigrations]); }) ->keys(); } @@ -77,11 +96,6 @@ public function setMigrationPath(string $path): static return $this; } - public function getMigrationPath(string $path = ''): string - { - return join_paths($this->migrationsPath, $path); - } - /** * Un-register a previously registered migration */ @@ -101,18 +115,4 @@ public function unpublishMigration(string $path): static return $this; } - - private function shouldLoadDefaultMigrationsFolder(): bool - { - return ! $this->preventLoadDefault && $this->shouldIncludeMigrationsFromFolder; - } - - private function loadMigrationsDefaultFolder(): array - { - if (! $this->shouldLoadDefaultMigrationsFolder()) { - return []; - } - - return $this->loadFilesFrom($this->getMigrationPath())->all(); - } }