Skip to content

Commit 147bebd

Browse files
authored
Merge pull request #6 from syntafin/main
Change Command Name and fix Typo
2 parents e8896fe + d97aa97 commit 147bebd

5 files changed

+93
-60
lines changed

composer.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@
4848
"test-coverage": "vendor/bin/pest --coverage"
4949
},
5050
"config": {
51-
"sort-packages": true
51+
"sort-packages": true,
52+
"allow-plugins": {
53+
"pestphp/pest-plugin-laravel": true,
54+
"pestphp/pest-plugin": true,
55+
"phpstan/extension-installer": true,
56+
"phpstan/phpstan-deprecation-rules": true,
57+
"phpstan/phpstan-phpunit": true
58+
}
5259
},
5360
"extra": {
5461
"laravel": {

src/Console/MakePresenterCommand.php

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Coderflex\LaravelPresenter\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakePresenterCommand extends GeneratorCommand
8+
{
9+
public $name = 'make:presenter';
10+
11+
public $description = 'Create a new presenter class';
12+
13+
/**
14+
* The type of class being generated.
15+
*
16+
* @var string
17+
*/
18+
protected $type = 'Presenter';
19+
20+
/**
21+
* Determine if the class already exists.
22+
*
23+
* @param string $rawName
24+
* @return bool
25+
*/
26+
protected function alreadyExists($rawName)
27+
{
28+
return class_exists($rawName) ||
29+
$this->files->exists($this->getPath($this->qualifyClass($rawName)));
30+
}
31+
32+
/**
33+
* Get the stub file for the generator.
34+
*
35+
* @return string
36+
*/
37+
protected function getStub()
38+
{
39+
return $this->resolveStubPath('/stubs/presenter.stub');
40+
}
41+
42+
/**
43+
* Resolve the fully-qualified path to the stub.
44+
*
45+
* @param string $stub
46+
* @return string
47+
*/
48+
protected function resolveStubPath($stub)
49+
{
50+
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
51+
? $customPath
52+
: __DIR__ . $stub;
53+
}
54+
55+
/**
56+
* Get the default namespace for the class.
57+
*
58+
* @param string $rootNamespace
59+
* @return string
60+
*/
61+
protected function getDefaultNamespace($rootNamespace)
62+
{
63+
$configNamespace = config('laravel-presenter.presenter_namespace');
64+
65+
return is_null($configNamespace)
66+
? $rootNamespace . '\Presenters'
67+
: $configNamespace;
68+
}
69+
}

src/Console/PresenterMakeCommand.php

+5-58
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,13 @@
44

55
use Illuminate\Console\GeneratorCommand;
66

7-
class PresenterMakeCommand extends GeneratorCommand
7+
class PresenterMakeCommand extends MakePresenterCommand
88
{
99
public $name = 'presenter:make';
10-
11-
public $description = 'create a new presenter class';
12-
13-
/**
14-
* The type of class being generated.
15-
*
16-
* @var string
17-
*/
18-
protected $type = 'Presenter';
19-
20-
/**
21-
* Determine if the class already exists.
22-
*
23-
* @param string $rawName
24-
* @return bool
25-
*/
26-
protected function alreadyExists($rawName)
10+
11+
protected function configure()
2712
{
28-
return class_exists($rawName) ||
29-
$this->files->exists($this->getPath($this->qualifyClass($rawName)));
30-
}
31-
32-
/**
33-
* Get the stub file for the generator.
34-
*
35-
* @return string
36-
*/
37-
protected function getStub()
38-
{
39-
return $this->resolveStubPath('/stubs/presenter.stub');
40-
}
41-
42-
/**
43-
* Resolve the fully-qualified path to the stub.
44-
*
45-
* @param string $stub
46-
* @return string
47-
*/
48-
protected function resolveStubPath($stub)
49-
{
50-
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
51-
? $customPath
52-
: __DIR__ . $stub;
53-
}
54-
55-
/**
56-
* Get the default namespace for the class.
57-
*
58-
* @param string $rootNamespace
59-
* @return string
60-
*/
61-
protected function getDefaultNamespace($rootNamespace)
62-
{
63-
$configNamespace = config('laravel-presenter.presenter_namespace');
64-
65-
return is_null($configNamespace)
66-
? $rootNamespace . '\Presenters'
67-
: $configNamespace;
13+
$this->setHidden(true);
6814
}
15+
6916
}

src/LaravelPresenterServiceProvider.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Coderflex\LaravelPresenter;
44

5-
use Coderflex\LaravelPresenter\Console\PresenterMakeCommand;
5+
use Coderflex\LaravelPresenter\Console\{
6+
PresenterMakeCommand,
7+
MakePresenterCommand
8+
};
69
use Spatie\LaravelPackageTools\Package;
710
use Spatie\LaravelPackageTools\PackageServiceProvider;
811

@@ -18,6 +21,7 @@ public function configurePackage(Package $package): void
1821
$package
1922
->name('laravel-presenter')
2023
->hasConfigFile('laravel-presenter')
24+
->hasCommand(MakePresenterCommand::class)
2125
->hasCommand(PresenterMakeCommand::class);
2226
}
2327
}

tests/PresentersTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
->assertExitCode(0);
1717
})->group('Presenter Command');
1818

19+
20+
it('can create new presenter class with the alias command', function () {
21+
$this->artisan('make:presenter UserPresenter')
22+
->assertExitCode(0);
23+
})->group('Presenter Command');
24+
1925
it('presents user full name', function () {
2026
$user = new User([
2127
'first_name' => 'John',

0 commit comments

Comments
 (0)