Skip to content

Commit 13ceec6

Browse files
authored
Merge pull request #1 from caneco/release-1.1.0
[1.1.0] added a couple of features and tests
2 parents 98a804a + 367bc1c commit 13ceec6

17 files changed

+254
-66
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
composer.lock
33
vendor
44
tests/temp
5-
.idea
5+
.idea
6+
.phpintel

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/logo.png" width="400"/></p>
1+
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/logo.png" width="400"/>
2+
</p><br>
23

3-
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/preview.png"/></p>
4+
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/preview.png" width="560"/></p>
45

56
<p align="center">
67
<a href="https://packagist.org/packages/caneco/artisan-aliases"><img src="https://poser.pugx.org/caneco/artisan-aliases/d/total.svg" alt="Total Downloads"></a>
@@ -100,7 +101,7 @@ To list the current alias available you can run the following command:
100101

101102
```
102103
>_ php artisan alias --list
103-
Laravel `Artisan Aliases` 1.0.0
104+
Laravel `Artisan Aliases` 1.1.0
104105
105106
Usage:
106107
alias [-g|--global] [--] [<as>]
@@ -206,16 +207,16 @@ Laravel Framework | Artisan Alias
206207

207208
## Road map
208209

209-
Artisan Alias was released so you can use it normally, but there's still some things that I would like to see in the package.
210+
Artisan Alias is stable but there is still some things that I would like to add in the package.
210211

211212
Here's the plan for what's coming:
212213

213214
- [ ] Remove an existing alias using the option `--d|delete`
214-
- [ ] Allow to replace an existing alias using the option `--force`
215-
- [ ] Firing a `@handle` method if
215+
- [ ] Firing a `@handle` method if alias has a `::class` reference
216216
- [ ] Alert the user try to add an alias with `sudo` in the command **(usefull?)**
217217
- [ ] Add comments
218-
- [ ] Add tests
218+
- [x] Allow to replace an existing alias using the option `--force`
219+
- [x] Add tests
219220

220221

221222

phpunit.xml renamed to phpunit.xml.dist

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
backupGlobals="false"
44
backupStaticAttributes="false"
55
colors="true"
6-
verbose="true"
76
convertErrorsToExceptions="true"
87
convertNoticesToExceptions="true"
98
convertWarningsToExceptions="true"
109
processIsolation="false"
1110
stopOnFailure="false"
1211
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
1312
<testsuites>
14-
<testsuite name="ArtisanAliases Test Suite">
15-
<directory>tests</directory>
13+
<testsuite name="Feature">
14+
<directory suffix="Test.php">./tests/Feature</directory>
15+
</testsuite>
16+
<testsuite name="Functional">
17+
<directory suffix="Test.php">./tests/Functional</directory>
1618
</testsuite>
1719
</testsuites>
1820
<filter>
19-
<whitelist>
21+
<whitelist processUncoveredFilesFromWhitelist="true">
2022
<directory suffix=".php">src/</directory>
2123
</whitelist>
2224
</filter>
23-
</phpunit>
25+
<php>
26+
<env name="APP_ENV" value="testing"/>
27+
</php>
28+
</phpunit>

src/Alias.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77

88
class Alias
99
{
10-
public const VERSION = '1.0.0';
10+
public const VERSION = '1.1.0';
1111

12-
public static function store(string $name, string $line, bool $global)
12+
public static function store(string $name, string $line, ?bool $global = false, ?bool $force = false)
1313
{
14-
$manager = new AliasManager(
15-
$global ? AliasFile::global() : AliasFile::local()
16-
);
1714

18-
return $manager->save(new AliasModel($name, $line));
15+
return self::manager($global)->save(new AliasModel($name, $line), $force);
1916
}
2017

2118
public static function load(?string $location = null): array
@@ -43,4 +40,11 @@ public static function global(): array
4340
AliasFile::global()
4441
))->load();
4542
}
43+
44+
public static function manager(bool $global): AliasManager
45+
{
46+
return new AliasManager(
47+
$global ? AliasFile::global() : AliasFile::local()
48+
);
49+
}
4650
}

src/AliasFile.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Caneco\ArtisanAliases;
44

5-
use Illuminate\Support\Facades\Config;
6-
75
class AliasFile
86
{
97
public static function local(): string
@@ -15,4 +13,4 @@ public static function global(): string
1513
{
1614
return $_SERVER['HOME'] . '/.laravel_aliases';
1715
}
18-
}
16+
}

src/AliasManager.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Caneco\ArtisanAliases;
44

5+
use Caneco\ArtisanAliases\Alias;
56
use Caneco\ArtisanAliases\AliasDirectory;
67
use Caneco\ArtisanAliases\AliasModel;
78
use Caneco\ArtisanAliases\Exceptions\AliasException;
9+
use Caneco\ArtisanAliases\Helpers\Art;
810
use Illuminate\Support\Facades\Artisan;
911
use sixlive\DotenvEditor\DotenvEditor;
12+
use sixlive\DotenvEditor\EnvFile;
1013

1114
class AliasManager
1215
{
@@ -50,13 +53,13 @@ public function safeLoadFile(): array
5053
}
5154
}
5255

53-
public function save(AliasModel $command)
56+
public function save(AliasModel $command, ?bool $force = false)
5457
{
5558
if (! file_exists($this->filePath)) {
5659
throw new AliasException("Expected file '{$this->filePath}' does not exists!");
5760
}
5861

59-
if (array_key_exists($command->getName(), Artisan::all())) {
62+
if (array_key_exists($command->getName(), Artisan::all()) && !$force) {
6063
throw new AliasException("Artisan command/alias already exists!");
6164
}
6265

@@ -67,13 +70,13 @@ public function save(AliasModel $command)
6770
return $file->save();
6871
}
6972

70-
public function looksValid(string $string): bool
73+
private function looksValid(string $string): bool
7174
{
7275
return strpos($string, '=') !== false;
7376
}
7477

75-
public function isNotComment(string $string): bool
78+
private function isNotComment(string $string): bool
7679
{
7780
return isset($string[0]) && $string[0] !== '#';
7881
}
79-
}
82+
}

src/AliasModel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Caneco\ArtisanAliases;
44

5+
use Caneco\ArtisanAliases\Exceptions\AliasException;
6+
57
class AliasModel
68
{
79
private $name;
@@ -72,4 +74,4 @@ public function sanitizeCommand(string $string): string
7274

7375
return trim($string);
7476
}
75-
}
77+
}

src/ArtisanAliasesServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private function registerPublishing()
3131
], 'config');
3232

3333
$this->publishes([
34-
__DIR__.'/../stubs/.laravel_aliases' => base_path('.laravel_aliases'),
34+
__DIR__.'/../stubs/laravel_aliases' => base_path('.laravel_aliases'),
3535
], 'aliases');
3636
}
3737

@@ -52,4 +52,4 @@ function () use ($alias, $command) {
5252
$this->commands($list ?? []);
5353
}
5454
}
55-
}
55+
}

src/Commands/AliasCommand.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@ class AliasCommand extends Command
1313
{name? : The name of the alias}
1414
{line? : The command line to be aliased}
1515
{--list : list all alias defined}
16-
{--g|global : Add alias globally [`~/.laravel_alias`]}
17-
{--force : Force alias to be replaced}';
16+
{--force : Force alias to be replaced}
17+
{--g|global : Add alias globally [`~/.laravel_alias`]}';
1818

1919
protected $description = 'Create an alias of another command.';
2020

2121
public function handle()
2222
{
23-
if (empty($this->argument('name'))
24-
or empty($this->argument('line'))
25-
or $this->option('list')
26-
) {
27-
$this->handleList();
28-
exit;
23+
if (empty($this->argument('name')) or $this->option('list')) {
24+
return $this->listAliases();
2925
}
3026

31-
Alias::store(
32-
trim($this->argument('name')),
33-
trim($this->argument('line')),
34-
$this->option('global')
35-
);
27+
if (! empty($this->argument('line'))) {
28+
return $this->storeAlias();
29+
}
30+
31+
return $this->listAliases();
3632
}
3733

38-
private function handleList()
34+
private function listAliases()
3935
{
4036
$list = Alias::load();
4137

@@ -59,4 +55,19 @@ private function handleList()
5955
$this->getOutput()->block('All aliases are currently disabled, to enable set `enabled = true` in your config file to use them.', 'Notice', 'fg=black;bg=yellow', '! ', true);
6056
}
6157
}
62-
}
58+
59+
private function storeAlias()
60+
{
61+
Alias::store(
62+
trim($this->argument('name')),
63+
trim($this->argument('line')),
64+
$this->option('global'),
65+
$this->option('force')
66+
);
67+
}
68+
69+
// private function deleteAlias()
70+
// {
71+
// // SOON
72+
// }
73+
}

src/Commands/AliasedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ private function process(string $command)
5858
$this->error($e->getMessage());
5959
}
6060
}
61-
}
61+
}

0 commit comments

Comments
 (0)