Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Commands/Actions/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Nwidart\Modules\Commands\Actions;

use Illuminate\Console\Command;
use Nwidart\Modules\Enums\ModuleStatus;
use Nwidart\Modules\Module;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -62,12 +63,12 @@ public function getModules()
{
switch ($this->option('only')) {
case 'enabled':
return $this->laravel['modules']->getByStatus(1);
return $this->laravel['modules']->getByStatus(ModuleStatus::ACTIVE);

break;

case 'disabled':
return $this->laravel['modules']->getByStatus(0);
return $this->laravel['modules']->getByStatus(ModuleStatus::INACTIVE);

break;

Expand Down
3 changes: 2 additions & 1 deletion src/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Filesystem\Filesystem;
use Nwidart\Modules\Collection;
use Nwidart\Modules\Enums\ModuleStatus;
use Nwidart\Modules\Exceptions\ModuleNotFoundException;
use Nwidart\Modules\Module;

Expand Down Expand Up @@ -52,7 +53,7 @@ public function getOrdered(string $direction = 'asc');
/**
* Get modules by the given status.
*/
public function getByStatus(int|bool $status);
public function getByStatus(ModuleStatus $status);

/**
* Find a specific module.
Expand Down
9 changes: 9 additions & 0 deletions src/Enums/ModuleStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Nwidart\Modules\Enums;

enum ModuleStatus: int
{
case ACTIVE = 1;
case INACTIVE = 0;
}
11 changes: 6 additions & 5 deletions src/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Laravel\Lumen\Application;
use Nwidart\Modules\Constants\ModuleEvent;
use Nwidart\Modules\Contracts\RepositoryInterface;
use Nwidart\Modules\Enums\ModuleStatus;
use Nwidart\Modules\Exceptions\InvalidAssetPath;
use Nwidart\Modules\Exceptions\ModuleNotFoundException;
use Nwidart\Modules\Process\Installer;
Expand Down Expand Up @@ -164,13 +165,13 @@ public function toCollection(): Collection
/**
* Get modules by status.
*/
public function getByStatus($status): array
public function getByStatus(ModuleStatus $status): array
{
$modules = [];

/** @var Module $module */
foreach ($this->all() as $name => $module) {
if ($module->isStatus($status)) {
if ($module->isStatus((bool) $status->value)) {
$modules[$name] = $module;
}
}
Expand All @@ -191,15 +192,15 @@ public function has($name): bool
*/
public function allEnabled(): array
{
return $this->getByStatus(true);
return $this->getByStatus(ModuleStatus::ACTIVE);
}

/**
* Get list of disabled modules.
*/
public function allDisabled(): array
{
return $this->getByStatus(false);
return $this->getByStatus(ModuleStatus::INACTIVE);
}

/**
Expand Down Expand Up @@ -287,7 +288,7 @@ public function findOrFail(string $name): Module
/**
* Get all modules as laravel collection instance.
*/
public function collections($status = 1): Collection
public function collections(ModuleStatus $status = ModuleStatus::ACTIVE): Collection
{
return new Collection($this->getByStatus($status));
}
Expand Down
5 changes: 3 additions & 2 deletions tests/LaravelFileRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Filesystem\Filesystem;
use Nwidart\Modules\Collection;
use Nwidart\Modules\Contracts\ActivatorInterface;
use Nwidart\Modules\Enums\ModuleStatus;
use Nwidart\Modules\Exceptions\InvalidAssetPath;
use Nwidart\Modules\Exceptions\ModuleNotFoundException;
use Nwidart\Modules\Laravel\LaravelFileRepository;
Expand Down Expand Up @@ -57,15 +58,15 @@ public function test_it_returns_all_enabled_modules()
{
$this->repository->addLocation(__DIR__.'/stubs/valid');

$this->assertCount(0, $this->repository->getByStatus(true));
$this->assertCount(0, $this->repository->getByStatus(ModuleStatus::ACTIVE));
$this->assertCount(0, $this->repository->allEnabled());
}

public function test_it_returns_all_disabled_modules()
{
$this->repository->addLocation(__DIR__.'/stubs/valid');

$this->assertCount(2, $this->repository->getByStatus(false));
$this->assertCount(2, $this->repository->getByStatus(ModuleStatus::INACTIVE));
$this->assertCount(2, $this->repository->allDisabled());
}

Expand Down