Skip to content

Commit

Permalink
Merge branch '6.x' into 7.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Sep 1, 2023
2 parents d5c6ef9 + 90b28f6 commit a740617
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Orchestra\Canvas\Processors\GeneratesCodeWithComponent;
use Orchestra\Canvas\Core\GeneratesCodeWithComponent;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

Expand Down
8 changes: 0 additions & 8 deletions src/Commands/Database/Eloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Support\Str;
use Orchestra\Canvas\Commands\Generator;
use Orchestra\Canvas\Processors\GeneratesEloquentCode;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

Expand All @@ -24,13 +23,6 @@ class Eloquent extends Generator
*/
protected string $type = 'Model';

/**
* Generator processor.
*
* @var class-string<\Orchestra\Canvas\Core\GeneratesCode>
*/
protected string $processor = GeneratesEloquentCode::class;

/**
* Run after code successfully generated.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Database/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Orchestra\Canvas\Commands\Database;

use Orchestra\Canvas\Commands\Generator;
use Orchestra\Canvas\Processors\GeneratesObserverCode;
use Orchestra\Canvas\Core\GeneratesCodeWithEloquent;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

Expand All @@ -25,7 +25,7 @@ class Observer extends Generator
*
* @var class-string<\Orchestra\Canvas\Core\GeneratesCode>
*/
protected string $processor = GeneratesObserverCode::class;
protected string $processor = GeneratesCodeWithEloquent::class;

/**
* Get the stub file name for the generator.
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Support\Str;
use Orchestra\Canvas\Processors\GeneratesCodeWithMarkdown;
use Orchestra\Canvas\Core\GeneratesCodeWithMarkdown;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Support\Str;
use Orchestra\Canvas\Processors\GeneratesCodeWithMarkdown;
use Orchestra\Canvas\Core\GeneratesCodeWithMarkdown;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

Expand Down
22 changes: 0 additions & 22 deletions src/Processors/GeneratesCodeWithMarkdown.php

This file was deleted.

11 changes: 6 additions & 5 deletions src/Processors/GeneratesControllerCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
class GeneratesControllerCode extends GeneratesCode
{
/**
* Build the class with the given name.
*
* Remove the base controller import if we are already in base namespace.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = parent::replaceNamespace($stub, $name);

$controllerNamespace = $this->getNamespace($name);

$rootNamespace = $this->rootNamespace();
Expand All @@ -34,13 +34,14 @@ protected function buildClass(string $name): string
$replace = $this->buildModelReplacements($replace);
}

// Remove the base controller import if we are already in base namespace.
$replace = array_merge($replace, [
"use {$controllerNamespace}\Controller;\n" => '',
"use {$rootNamespace}\Http\Controllers\Controller;" => "use {$rootNamespace}Http\Controllers\Controller;",
]);

return str_replace(
array_keys($replace), array_values($replace), parent::buildClass($name)
array_keys($replace), array_values($replace), $stub
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Processors/GeneratesFactoryCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
class GeneratesFactoryCode extends GeneratesCode
{
/**
* Build the class with the given name.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = parent::replaceNamespace($stub, $name);

$namespaceModel = ! empty($this->options['model'])
? $this->qualifyClass($this->options['model'])
: trim($this->rootNamespace(), '\\').'\\Model';
Expand Down Expand Up @@ -44,7 +46,7 @@ protected function buildClass(string $name): string
];

return str_replace(
array_keys($replace), array_values($replace), parent::buildClass($name)
array_keys($replace), array_values($replace), $stub
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Processors/GeneratesListenerCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
class GeneratesListenerCode extends GeneratesCode
{
/**
* Build the class with the given name.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = parent::replaceNamespace($stub, $name);

$event = $this->options['event'];

if (\is_null($event) || ! Str::startsWith($event, [
Expand All @@ -30,7 +32,7 @@ protected function buildClass(string $name): string
$stub = str_replace(
['DummyEvent', '{{ event }}', '{{event}}'],
class_basename($event),
parent::buildClass($name)
$stub
);

return str_replace(
Expand Down
6 changes: 3 additions & 3 deletions src/Processors/GeneratesPolicyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
class GeneratesPolicyCode extends GeneratesCode
{
/**
* Build the class with the given name.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = $this->replaceUserNamespace(
parent::buildClass($name)
parent::replaceNamespace($stub, $name)
);

$model = $this->options['model'];
Expand Down
10 changes: 5 additions & 5 deletions src/Processors/GeneratesRuleCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
class GeneratesRuleCode extends GeneratesCode
{
/**
* Build the class with the given name.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = parent::replaceNamespace($stub, $name);

return str_replace(
'{{ ruleType }}',
$this->options['implicit'] ? 'ImplicitRule' : 'Rule',
parent::buildClass($name)
'{{ ruleType }}', $this->options['implicit'] ? 'ImplicitRule' : 'Rule', $stub
);
}
}
8 changes: 5 additions & 3 deletions src/Processors/GeneratesTestingCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
class GeneratesTestingCode extends GeneratesCode
{
/**
* Build the class with the given name.
* Replace the namespace for the given stub.
*/
protected function buildClass(string $name): string
protected function replaceNamespace(string $stub, string $name): string
{
$stub = parent::replaceNamespace($stub, $name);

$testCase = $this->options['unit']
? $this->preset->config('testing.extends.unit', 'PHPUnit\Framework\TestCase')
: $this->preset->config(
'testing.extends.feature',
$this->preset instanceof Laravel ? 'Tests\TestCase' : 'Orchestra\Testbench\TestCase'
);

return $this->replaceTestCase(parent::buildClass($name), $testCase);
return $this->replaceTestCase($stub, $testCase);
}

/**
Expand Down

0 comments on commit a740617

Please sign in to comment.