Skip to content

Commit

Permalink
ENUM: added command to list
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjude committed Jun 1, 2023
1 parent 52f8ba3 commit 1192094
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 41 deletions.
3 changes: 0 additions & 3 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

'class_namespace' => '',


/*
|--------------------------------------------------------------------------
| Default Abstract Class Namespace
Expand All @@ -26,7 +25,6 @@

'abstract_class_namespace' => '',


/*
|--------------------------------------------------------------------------
| Default Interface Namespace
Expand All @@ -39,7 +37,6 @@

'interface_namespace' => '\Contracts',


/*
|--------------------------------------------------------------------------
| Default Trait Namespace
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/ClassMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Stephenjude\ExtendedArtisanCommands\Commands;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Stephenjude\ExtendedArtisanCommands\Concerns\WithAbstractClass;
use Stephenjude\ExtendedArtisanCommands\Concerns\WithInterface;
use Stephenjude\ExtendedArtisanCommands\Concerns\WithStubCleaner;
Expand All @@ -14,6 +13,7 @@
class ClassMakeCommand extends GeneratorCommand
{
use WithInterface, WithAbstractClass, WithTrait, WithStubCleaner;

/**
* The console command name.
*
Expand Down Expand Up @@ -68,7 +68,7 @@ public function handle()
}
}

public function setUp() : void
public function setUp(): void
{
$this->className = class_basename($this->argument('name'));

Expand Down Expand Up @@ -142,7 +142,6 @@ protected function getArguments()
];
}


/**
* Get the console command options.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Commands/EnumMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ protected function getArguments()

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions(): array
{
Expand Down
8 changes: 2 additions & 6 deletions src/Concerns/WithAbstractClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function createAbstractClass()

$alias = $this->classPrefix.$baseName;

$abstractClass = Str::studly(str_replace($baseName, $alias, (string) $name));
$abstractClass = Str::studly(str_replace($baseName, $alias, (string) $name));

$this->call('make:abstract-class', [
'name' => "{$abstractClass}",
Expand All @@ -40,9 +40,8 @@ protected function createAbstractClass()
* Replace the abstract class name for the given stub.
*
* @param string $stub
* @return string
*/
protected function replaceAbstractClassStubs($stub) : string
protected function replaceAbstractClassStubs($stub): string
{
$alias = $this->classPrefix.$this->enumName;

Expand All @@ -59,7 +58,6 @@ protected function replaceAbstractClassStubs($stub) : string
* Parse the abstract class name and format according to abstract class root namespace.
*
* @param string $name
* @return string
*/
protected function getAbstractClassNamespace($name): string
{
Expand All @@ -68,5 +66,3 @@ protected function getAbstractClassNamespace($name): string
return str_replace('\\\\', '\\', $namespace);
}
}


4 changes: 1 addition & 3 deletions src/Concerns/WithInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ protected function createInterface()
* Replace the interface name for the given stub.
*
* @param string $stub
* @return string
*/
protected function replaceInterfaceStubs($stub) : string
protected function replaceInterfaceStubs($stub): string
{
$namespace = $this->getInterfaceNamespace($this->enumName);

Expand All @@ -50,7 +49,6 @@ protected function replaceInterfaceStubs($stub) : string
* Parse the interface name and format according to interface root namespace.
*
* @param string $name
* @return string
*/
protected function getInterfaceNamespace($name): string
{
Expand Down
14 changes: 9 additions & 5 deletions src/Concerns/WithStubCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

trait WithStubCleaner
{
protected function cleanStubs($stub) : string
protected function cleanStubs($stub): string
{
if ($this->option('all')) {
return $stub;
Expand All @@ -20,39 +20,43 @@ protected function cleanStubs($stub) : string
return $stub;
}

public function cleanTraitStub($stub) : string
public function cleanTraitStub($stub): string
{
if (! $this->option('trait')) {
$stub = str_replace('use DummyTraitNamespace;', '', (string) $stub);
$stub = str_replace(' use DummyTrait;', '', $stub);
}

return $stub;
}

public function cleanEnumStub($stub) : string
public function cleanEnumStub($stub): string
{
if (! $this->option('enum')) {
$stub = str_replace('use DummyEnumNamespace;', '', (string) $stub);
$stub = str_replace(' use DummyEnum;', '', $stub);
}

return $stub;
}

public function cleanInterfaceStub($stub) : string
public function cleanInterfaceStub($stub): string
{
if (! $this->option('interface')) {
$stub = str_replace('use DummyInterfaceNamespace;', '', (string) $stub);
$stub = str_replace('implements DummyInterface', '', $stub);
}

return $stub;
}

public function cleanAbstractClassStub($stub) : string
public function cleanAbstractClassStub($stub): string
{
if (! $this->option('abstract')) {
$stub = str_replace('use DummyAbstractClassNamespace;', '', (string) $stub);
$stub = str_replace('extends DummyAbstractClass ', '', $stub);
}

return $stub;
}
}
4 changes: 1 addition & 3 deletions src/Concerns/WithTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ protected function createTrait()
* Replace the trait name for the given stub.
*
* @param string $stub
* @return string
*/
protected function replaceTraitStubs($stub) : string
protected function replaceTraitStubs($stub): string
{
$namespace = $this->getTraitNamespace($this->enumName);

Expand All @@ -45,7 +44,6 @@ protected function replaceTraitStubs($stub) : string
* Parse the trait name and format according to trait root namespace.
*
* @param string $name
* @return string
*/
protected function getTraitNamespace($name): string
{
Expand Down
3 changes: 2 additions & 1 deletion src/ExtendedArtisanCommandsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function boot()
\Stephenjude\ExtendedArtisanCommands\Commands\ClassMakeCommand::class,
\Stephenjude\ExtendedArtisanCommands\Commands\AbstractClassMakeCommand::class,
\Stephenjude\ExtendedArtisanCommands\Commands\InterfaceMakeCommand::class,
\Stephenjude\ExtendedArtisanCommands\Commands\TraitMakeCommand::class
\Stephenjude\ExtendedArtisanCommands\Commands\TraitMakeCommand::class,
\Stephenjude\ExtendedArtisanCommands\Commands\EnumMakeCommand::class,
]);
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/MakeInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Stephenjude\ExtendedArtisanCommands\Tests;

use Illuminate\Support\Facades\File;

class MakeInterfaceTest extends TestCase
{
/** @test */
Expand Down
2 changes: 0 additions & 2 deletions tests/MakeTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ public function test_make_trait()
->expectsOutput($this->traitConsoleOutput)
->assertExitCode(0);
}


}
20 changes: 9 additions & 11 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,37 @@ class TestCase extends Orchestra
*
* @var string
*/
protected $interfaceConsoleOutput = "Interface created successfully.";
protected $interfaceConsoleOutput = 'Interface created successfully.';

/**
* Console output for make:trait command
*
* @var string
*/
protected $traitConsoleOutput = "Trait created successfully.";
protected $traitConsoleOutput = 'Trait created successfully.';

/**
* Console output for make:trait command
*
* @var string
*/
protected $enumConsoleOutput = "Enum created successfully.";
protected $enumConsoleOutput = 'Enum created successfully.';

/**
* Console output for make:class command
*
* @var string
*/
protected $classConsoleOutput = "Class created successfully.";

protected $classConsoleOutput = 'Class created successfully.';

/**
* Console output for make:abstract-class command
*
* @var string
*/
protected $abstractClassConsoleOutput = "Abstract Class created successfully.";
protected $abstractClassConsoleOutput = 'Abstract Class created successfully.';

public function setUp() : void
public function setUp(): void
{
parent::setUp();

Expand All @@ -60,18 +59,17 @@ protected function getPackageProviders($app)
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app) : void
protected function getEnvironmentSetUp($app): void
{
$app['config']->set('extended-artisan-commands.class_namespace', '');
$app['config']->set('extended-artisan-commands.abstract_class_namespace', '');
$app['config']->set('extended-artisan-commands.interface_namespace', '\Contracts');
$app['config']->set('extended-artisan-commands.trait_namespace', '\Traits');
}

private function cleanOutputDirectory() : void
private function cleanOutputDirectory(): void
{
File::deleteDirectory(base_path('app'));
File::deleteDirectory(base_path('app'));
}
}

0 comments on commit 1192094

Please sign in to comment.