Skip to content

Commit

Permalink
[10.x] Fixes GeneratorCommand not able to prevent uppercase reserved (
Browse files Browse the repository at this point in the history
laravel#48667)

name such as  `__CLASS__`

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored and timacdonald committed Oct 24, 2023
1 parent a3480a9 commit 598b10f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,12 @@ protected function userProviderModel()
*/
protected function isReservedName($name)
{
$name = strtolower($name);

return in_array($name, $this->reservedNames);
return in_array(
strtolower($name),
collect($this->reservedNames)
->transform(fn ($name) => strtolower($name))
->all()
);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/Console/GeneratorCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Illuminate\Tests\Integration\Console;

use Orchestra\Testbench\TestCase;

class GeneratorCommandTest extends TestCase
{
/**
* @dataProvider reservedNamesDataProvider
*/
public function testItCannotGenerateClassUsingReservedName($given)
{
$this->artisan('make:command', ['name' => $given])
->expectsOutputToContain('The name "'.$given.'" is reserved by PHP.')
->assertExitCode(0);
}

public static function reservedNamesDataProvider()
{
yield ['__halt_compiler'];
yield ['__HALT_COMPILER'];
yield ['array'];
yield ['ARRAY'];
yield ['__class__'];
yield ['__CLASS__'];
}
}

0 comments on commit 598b10f

Please sign in to comment.