Skip to content

Commit

Permalink
fix: rename property
Browse files Browse the repository at this point in the history
Signed-off-by: Ayax Córdova <ayax.cordova@aydev.mx>
  • Loading branch information
asciito committed Sep 24, 2023
1 parent 1b2339b commit 8f6abd9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
54 changes: 28 additions & 26 deletions src/Package/Concerns/HasConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ trait HasConfig

protected array $configFiles = [];

protected bool $preventLoadDefaultConfigFolder = false;

protected bool $shouldIncludeConfigFromFolder = false;

protected array $excludedConfig = [];
Expand All @@ -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)) {
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
}
}
46 changes: 23 additions & 23 deletions src/Package/Concerns/HasMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait HasMigrations

protected array $migrations = [];

protected bool $preventLoadDefault = false;
protected bool $preventLoadDefaultMigrationFolder = false;

protected bool $shouldIncludeMigrationsFromFolder = false;

Expand All @@ -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)) {
Expand All @@ -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;
}
Expand All @@ -53,19 +58,33 @@ 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();

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();
}
Expand All @@ -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
*/
Expand All @@ -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();
}
}

0 comments on commit 8f6abd9

Please sign in to comment.