Skip to content

Commit

Permalink
Install Laravel pint and run
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaidQadirB committed Sep 8, 2023
1 parent 0cab104 commit f1655b1
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 50 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"laravel/framework": "^6.0|^7.0|^8.0|^9.0|^10"
},
"require-dev": {
"laravel/pint": "^1.13",
"orchestra/testbench": "^4.0|^5.0|v6.0.0",
"phpunit/phpunit": "^8.0|^9.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/Console/Commands/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ class ControllerMakeCommand extends GeneratorCommand
* @var mixed|string
*/
public $routeBase;

/**
* The console command name.
*
* @var string
*/
protected $name = 'cray:controller';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new controller class';

/**
* The type of class being generated.
*
Expand Down Expand Up @@ -140,7 +143,6 @@ protected function parseModel($model)
/**
* Build the model replacement values.
*
* @param array $replace
* @return array
*/
protected function buildModelReplacements(array $replace)
Expand Down
1 change: 1 addition & 0 deletions src/Console/Commands/Cray.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Cray extends GeneratorCommand
* @var string
*/
protected $name = 'cray';

/**
* The name and signature of the console command.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Console/Commands/DeleteResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ class DeleteResourceCommand extends Command
'path' => 'database/factories',
],
];

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cray:rm';

/**
* The console command description.
*
Expand Down
2 changes: 0 additions & 2 deletions src/Console/Commands/MigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class MigrateMakeCommand extends BaseCommand
/**
* Create a new migration install command instance.
*
* @param MigrationCreator $creator
* @param Composer $composer
* @return void
*/
public function __construct(MigrationCreator $creator, Composer $composer)
Expand Down
8 changes: 0 additions & 8 deletions src/Console/Commands/RequestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ protected function buildClass($name)

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub(): string
{
Expand All @@ -105,9 +103,6 @@ protected function getStub(): string

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath(string $stub): string
{
Expand All @@ -120,7 +115,6 @@ protected function resolveStubPath(string $stub): string
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace): string
{
Expand All @@ -129,8 +123,6 @@ protected function getDefaultNamespace($rootNamespace): string

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions(): array
{
Expand Down
47 changes: 22 additions & 25 deletions src/Console/Commands/ViewMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle()
/* if (parent::handle() === false && ! $this->option('force')) {
return;
}*/
if (!$this->option('index') && !$this->option('create') && !$this->option('edit') && !$this->option('show') && !$this->option('all')) {
if (! $this->option('index') && ! $this->option('create') && ! $this->option('edit') && ! $this->option('show') && ! $this->option('all')) {
$this->input->setOption('all', true);
}
$this->createView();
Expand Down Expand Up @@ -117,13 +117,13 @@ protected function createViewDirectory()

$dir = $this->option('dir');

$path = $viewPath . '/' . $viewDirSlug;
$path = $viewPath.'/'.$viewDirSlug;

if ($dir) {
$path = $viewPath . '/' . $dir;
$path = $viewPath.'/'.$dir;
}

if (!file_exists($path)) {
if (! file_exists($path)) {
mkdir($path, 0777, true);
}

Expand All @@ -133,10 +133,10 @@ protected function createViewDirectory()
private function chooseViewPath()
{
if ($this->option('base')) {
return base_path($this->option('base') . '/resources/views');
return base_path($this->option('base').'/resources/views');
}

if (!Config::has('view.paths') || (Config::has('view.paths') && count(Config::get('view.paths')) < 1)) {
if (! Config::has('view.paths') || (Config::has('view.paths') && count(Config::get('view.paths')) < 1)) {
return $this->viewPath();
}

Expand All @@ -155,8 +155,8 @@ private function chooseViewPath()

$otherRespone = $this->ask('Enter view path');

if ((Str::startsWith(base_path(), $otherRespone) && !is_dir(base_path($otherRespone))) || !is_dir(base_path($otherRespone))) {
$this->error($otherRespone . ' does not exist.');
if ((Str::startsWith(base_path(), $otherRespone) && ! is_dir(base_path($otherRespone))) || ! is_dir(base_path($otherRespone))) {
$this->error($otherRespone.' does not exist.');
$this->chooseViewPath();
}

Expand All @@ -172,14 +172,14 @@ protected function buildView($type, $path)
$viewName = Str::camel($viewLabel);
$stub = $this->replacePlaceholders($stub, $name, $path);

$target = $path . '/' . $type . '.blade.php';
$target = $path.'/'.$type.'.blade.php';

if ($type == 'delete') {
$target = $path . '/modals/' . $type . '.blade.php';
$target = $path.'/modals/'.$type.'.blade.php';
}
$displayPath = str_replace(resource_path(), '/resources', $target);
$message = "View created successfully in {$displayPath}";
if (file_exists($target) && !$this->option('force')) {
if (file_exists($target) && ! $this->option('force')) {
$this->error("File already exists. Cannot overwrite {$displayPath}.");
} else {
if ($this->option('force')) {
Expand All @@ -192,12 +192,12 @@ protected function buildView($type, $path)
/**
* Create the _form partial form the stub.
*/
$formPartial = $path . '/_form.blade.php';
$formPartial = $path.'/_form.blade.php';
$formPartialDisplayPath = str_replace(resource_path(), '/resources', $formPartial);
$formStub = $this->files->get($this->getStub('_form'));

if (file_exists($formPartial) && !$this->option('force')) {
// $this->error("File already exists. Cannot overwrite {$formPartialDisplayPath}.");
if (file_exists($formPartial) && ! $this->option('force')) {
// $this->error("File already exists. Cannot overwrite {$formPartialDisplayPath}.");
} else {
if (config('cray.fields.generate')) {
$tableName = Str::plural(Str::snake(class_basename($this->argument('name'))));
Expand All @@ -214,7 +214,7 @@ protected function buildView($type, $path)
/**
* Get the stub file for the generator.
*
* @param null|string $fileName
* @param null|string $fileName
* @return string
*/
protected function getStub($fileName = null)
Expand All @@ -228,7 +228,7 @@ protected function getStub($fileName = null)
$stubs = $this->option('stubs');

if ($stubs) {
$stubsPath = $stubs . '/' . $this->fileName . '.stub';
$stubsPath = $stubs.'/'.$this->fileName.'.stub';
}

return resource_path($stubsPath);
Expand All @@ -237,9 +237,6 @@ protected function getStub($fileName = null)
/**
* Replace all placeholders.
*
* @param $stub
* @param $name
* @param null $path
* @return mixed
*/
protected function replacePlaceholders($stub, $name, $path = null)
Expand All @@ -257,7 +254,7 @@ protected function replacePlaceholders($stub, $name, $path = null)
$viewName = Str::camel($name);

if ($this->option('base')) {
$path = $modelSlug . '::' . $path;
$path = $modelSlug.'::'.$path;
}

$replace = array_merge([], [
Expand All @@ -266,8 +263,8 @@ protected function replacePlaceholders($stub, $name, $path = null)
'$name$' => $viewName,
'$modelSlug$' => $modelSlug,
'$model$' => $name,
'$rows$' => '$' . Str::camel(Str::plural($name, 2)),
'$row$' => '$' . Str::camel(Str::singular($name)),
'$rows$' => '$'.Str::camel(Str::plural($name, 2)),
'$row$' => '$'.Str::camel(Str::singular($name)),
'$routeBase$' => $routeBase,
'$viewDir$' => $path,
]);
Expand All @@ -281,8 +278,8 @@ protected function replacePlaceholders($stub, $name, $path = null)

protected function createDeleteView($path)
{
if (!file_exists($path . '/modals')) {
mkdir($path . '/modals');
if (! file_exists($path.'/modals')) {
mkdir($path.'/modals');
}

$this->buildView('delete', $path);
Expand All @@ -291,7 +288,7 @@ protected function createDeleteView($path)
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
Expand Down
4 changes: 0 additions & 4 deletions src/Console/Contracts/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ public function getArtifactPath($base)

/**
* Add route for the generated resource to the relevant routes file.
*
* @param string $route
* @param string $controllerClassPath
*/
public function addRoute(
string $route,
Expand Down Expand Up @@ -186,7 +183,6 @@ public function addRoute(
}
}


$routeContent = file_exists($routeFile)
? file_get_contents($routeFile)
: null;
Expand Down
1 change: 0 additions & 1 deletion src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
4 changes: 2 additions & 2 deletions src/Cray.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function fields($tableName, $model = null, $markup = false)
'type' => 'text',
'label' => $label,
'name' => $name,
'value' => $model->$name ?? null,
'value' => "$$model->$name",
];
break;
case 'text':
Expand Down Expand Up @@ -103,7 +103,7 @@ public static function generateMarkup($fields)
$valueAttribute = ":value=\"old('{$field['name']}')\"";

if (trim($field['value']) != '') {
$valueAttribute = ":value=\"old('{$field['name']}'), '{$field['value']}')\"";
$valueAttribute = ":value=\"old('{$field['name']}', {$field['value']})\"";
}
$labelAttribute = "label=\"{$field['label']}\"";

Expand Down
2 changes: 0 additions & 2 deletions src/CrayFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class CrayFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/CrayServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function boot()
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');

// if ($this->app->runningInConsole()) {
// if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('cray.php'),
], 'cray');
Expand Down Expand Up @@ -68,7 +68,7 @@ public function boot()

// Registering package commands.
$this->commands($this->commands);
// }
// }
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/**
* Get instance class name without namespace.
*
* @param $instance
* @return string
*/
function className($instance)
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ControllerMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function test_it_uses_the_specified_route_or_falls_back_to_model_slug()
$controllerContents = file_get_contents(app_path('/Http/Controllers/PostController.php'));
$this->assertStringContainsStringIgnoringCase("return \$this->success('Post added successfully!', 'my-posts.index');", $controllerContents);*/

// unlink(app_path('Http/Controllers/PostController.php'));
// unlink(app_path('Http/Controllers/PostController.php'));

//Scenario 1
$this->artisan('cray:controller PostController --model=Post --views-dir=posts');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function tearDown(): void
{
parent::tearDown();
if (file_exists(resource_path('views/posts'))) {
// $this->rmdirRecursive(resource_path('views/posts'));
// $this->rmdirRecursive(resource_path('views/posts'));
}
}
}

0 comments on commit f1655b1

Please sign in to comment.