Browse Source

Use replace string helpers with Str class

tags/1.2.13^0 1.2.13
Nafies Luthfi 6 years ago
parent
commit
2074cb9832
  1. 11
      src/GeneratorCommand.php
  2. 4
      src/Generators/LangFileGenerator.php
  3. 5
      tests/Generators/LangGeneratorTest.php
  4. 9
      tests/TestCase.php

11
src/GeneratorCommand.php

@ -2,6 +2,7 @@
namespace Luthfi\CrudGenerator; namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Console\DetectsApplicationNamespace; use Illuminate\Console\DetectsApplicationNamespace;
@ -61,7 +62,7 @@ class GeneratorCommand extends Command
{ {
$modelName = is_null($modelName) ? $this->argument('name') : $modelName; $modelName = is_null($modelName) ? $this->argument('name') : $modelName;
$model_name = ucfirst(class_basename($modelName)); $model_name = ucfirst(class_basename($modelName));
$plural_model_name = str_plural($model_name);
$plural_model_name = Str::plural($model_name);
$modelPath = $this->getModelPath($modelName); $modelPath = $this->getModelPath($modelName);
$modelNamespace = $this->getModelNamespace($modelPath); $modelNamespace = $this->getModelNamespace($modelPath);
@ -70,10 +71,10 @@ class GeneratorCommand extends Command
'full_model_name' => $modelNamespace.'\\'.$model_name, 'full_model_name' => $modelNamespace.'\\'.$model_name,
'plural_model_name' => $plural_model_name, 'plural_model_name' => $plural_model_name,
'model_name' => $model_name, 'model_name' => $model_name,
'table_name' => snake_case($plural_model_name),
'lang_name' => snake_case($model_name),
'collection_model_var_name' => camel_case($plural_model_name),
'single_model_var_name' => camel_case($model_name),
'table_name' => Str::snake($plural_model_name),
'lang_name' => Str::snake($model_name),
'collection_model_var_name' => Str::camel($plural_model_name),
'single_model_var_name' => Str::camel($model_name),
'model_path' => $modelPath, 'model_path' => $modelPath,
]; ];
} }

4
src/Generators/LangFileGenerator.php

@ -2,6 +2,8 @@
namespace Luthfi\CrudGenerator\Generators; namespace Luthfi\CrudGenerator\Generators;
use Illuminate\Support\Str;
/** /**
* Lang File Generator Class * Lang File Generator Class
*/ */
@ -35,7 +37,7 @@ class LangFileGenerator extends BaseGenerator
$stub = $this->files->get(__DIR__.'/../stubs/resources/lang/en/master.stub'); $stub = $this->files->get(__DIR__.'/../stubs/resources/lang/en/master.stub');
} }
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->modelNames['model_name'])));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->modelNames['model_name'])));
$properLangFileContent = str_replace( $properLangFileContent = str_replace(
$this->modelNames['model_name'], $this->modelNames['model_name'],

5
tests/Generators/LangGeneratorTest.php

@ -3,6 +3,7 @@
namespace Tests\Generators; namespace Tests\Generators;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Support\Str;
class LangGeneratorTest extends TestCase class LangGeneratorTest extends TestCase
{ {
@ -13,7 +14,7 @@ class LangGeneratorTest extends TestCase
$locale = config('app.locale'); $locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php'); $langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath); $this->assertFileExists($langPath);
$langFileContent = "<?php $langFileContent = "<?php
@ -60,7 +61,7 @@ return [
$locale = config('app.locale'); $locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php'); $langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath); $this->assertFileExists($langPath);
$langFileContent = "<?php $langFileContent = "<?php

9
tests/TestCase.php

@ -2,6 +2,7 @@
namespace Tests; namespace Tests;
use Illuminate\Support\Str;
use Orchestra\Testbench\TestCase as BaseTestCase; use Orchestra\Testbench\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
@ -21,10 +22,10 @@ abstract class TestCase extends BaseTestCase
$this->full_model_name = 'App\\'.$this->model_name; $this->full_model_name = 'App\\'.$this->model_name;
$this->plural_model_name = str_plural($this->model_name); $this->plural_model_name = str_plural($this->model_name);
$this->table_name = snake_case($this->plural_model_name);
$this->lang_name = snake_case($this->model_name);
$this->collection_model_var_name = camel_case($this->plural_model_name);
$this->single_model_var_name = camel_case($this->model_name);
$this->table_name = Str::snake($this->plural_model_name);
$this->lang_name = Str::snake($this->model_name);
$this->collection_model_var_name = Str::camel($this->plural_model_name);
$this->single_model_var_name = Str::camel($this->model_name);
} }
public function tearDown() public function tearDown()

Loading…
Cancel
Save