Skip to content

Change Command Name and fix Typo #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 14, 2022
Merged
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
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@
"test-coverage": "vendor/bin/pest --coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin-laravel": true,
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true,
"phpstan/phpstan-deprecation-rules": true,
"phpstan/phpstan-phpunit": true
}
},
"extra": {
"laravel": {
Expand Down
69 changes: 69 additions & 0 deletions src/Console/MakePresenterCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Coderflex\LaravelPresenter\Console;

use Illuminate\Console\GeneratorCommand;

class MakePresenterCommand extends GeneratorCommand
{
public $name = 'make:presenter';

public $description = 'Create a new presenter class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Presenter';

/**
* Determine if the class already exists.
*
* @param string $rawName
* @return bool
*/
protected function alreadyExists($rawName)
{
return class_exists($rawName) ||
$this->files->exists($this->getPath($this->qualifyClass($rawName)));
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/presenter.stub');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__ . $stub;
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
$configNamespace = config('laravel-presenter.presenter_namespace');

return is_null($configNamespace)
? $rootNamespace . '\Presenters'
: $configNamespace;
}
}
63 changes: 5 additions & 58 deletions src/Console/PresenterMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,13 @@

use Illuminate\Console\GeneratorCommand;

class PresenterMakeCommand extends GeneratorCommand
class PresenterMakeCommand extends MakePresenterCommand
{
public $name = 'presenter:make';

public $description = 'create a new presenter class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Presenter';

/**
* Determine if the class already exists.
*
* @param string $rawName
* @return bool
*/
protected function alreadyExists($rawName)

protected function configure()
{
return class_exists($rawName) ||
$this->files->exists($this->getPath($this->qualifyClass($rawName)));
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/presenter.stub');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__ . $stub;
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
$configNamespace = config('laravel-presenter.presenter_namespace');

return is_null($configNamespace)
? $rootNamespace . '\Presenters'
: $configNamespace;
$this->setHidden(true);
}

}
6 changes: 5 additions & 1 deletion src/LaravelPresenterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Coderflex\LaravelPresenter;

use Coderflex\LaravelPresenter\Console\PresenterMakeCommand;
use Coderflex\LaravelPresenter\Console\{
PresenterMakeCommand,
MakePresenterCommand
};
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -18,6 +21,7 @@ public function configurePackage(Package $package): void
$package
->name('laravel-presenter')
->hasConfigFile('laravel-presenter')
->hasCommand(MakePresenterCommand::class)
->hasCommand(PresenterMakeCommand::class);
}
}
6 changes: 6 additions & 0 deletions tests/PresentersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
->assertExitCode(0);
})->group('Presenter Command');


it('can create new presenter class with the alias command', function () {
$this->artisan('make:presenter UserPresenter')
->assertExitCode(0);
})->group('Presenter Command');

it('presents user full name', function () {
$user = new User([
'first_name' => 'John',
Expand Down