Skip to content

Commit

Permalink
Merge pull request #12 from Althinect:refactor/general-refactor
Browse files Browse the repository at this point in the history
chore: Update .gitignore and refactor EnumPermissionCommand methods to protected; adjust model path in config
  • Loading branch information
tharindarodrigo authored Jan 2, 2025
2 parents efbc39b + addffaf commit f00cebe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.history
.idea
.phpunit.cache
build
Expand Down
4 changes: 2 additions & 2 deletions config/enum-permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

return [
// ---------------------------------------------------------------------------
// The path where the Models can be discovered within the "app" directory
// The path to the Models
// ---------------------------------------------------------------------------

'models_app_path' => 'Models',
'models_path' => 'app/Models',

// ---------------------------------------------------------------------------
// Enums will be generated in a similar path to the models
Expand Down
13 changes: 6 additions & 7 deletions src/Commands/EnumPermissionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ protected function createNewModel($model): bool
) === 'yes';

$this->call('make:model', $modelOptions);
sleep(1);
$this->info('Model created successfully');

return $this->generatePermissionEnums([implode('\\', explode('/', $model))]) === self::SUCCESS;
Expand Down Expand Up @@ -218,9 +217,9 @@ protected function promptForMissingArgumentsUsing(): array
];
}

private function getAllModels(): array
protected function getAllModels(): array
{
$models = array_filter($this->getClassesInDirectory(app_path(config('enum-permission.models_app_path'))), function ($model) {
$models = array_filter($this->getClassesInDirectory(base_path(config(key: 'enum-permission.models_path'))), function ($model) {
return collect(config('enum-permission.model_super_classes'))->contains(fn ($superClass): mixed => $model->isSubclassOf($superClass));
});

Expand All @@ -229,7 +228,7 @@ private function getAllModels(): array
}, $models);
}

private function getClassesInDirectory($path): array
protected function getClassesInDirectory(string $path): array
{
$files = File::allFiles($path);
$models = [];
Expand All @@ -246,7 +245,7 @@ private function getClassesInDirectory($path): array
return $models;
}

private function extractNamespace($file): string
protected function extractNamespace($file): string
{
$ns = '';
$handle = fopen($file, 'r');
Expand All @@ -263,7 +262,7 @@ private function extractNamespace($file): string
return $ns;
}

private function getPermissionsStringCasesForEnum($model): string
protected function getPermissionsStringCasesForEnum($model): string
{
$permissions = config('enum-permission.permissions');
$cases = '';
Expand All @@ -281,7 +280,7 @@ private function getPermissionsStringCasesForEnum($model): string
return $cases;
}

private function getPolicyMethodStructure(): string
protected function getPolicyMethodStructure(): string
{
return
' public function {{method}}({{arguments}}): bool'.PHP_EOL.
Expand Down

0 comments on commit f00cebe

Please sign in to comment.