Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 4d11dbf

Browse files
committed
update the format style with laravel
1 parent 787dcd8 commit 4d11dbf

File tree

9 files changed

+40
-58
lines changed

9 files changed

+40
-58
lines changed

common/helpers.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@
22

33
use Lbil\LaravelGenerator\Exceptions\LaravelGeneratorException;
44

5-
if (!function_exists('laravel_generator_dist_path')) {
5+
if (! function_exists('laravel_generator_dist_path')) {
66
/**
77
* Returns laravel-generator composer dist path.
88
*
99
* @param string|null $asset string
10-
*
1110
* @return string
1211
*/
1312
function laravel_generator_dist_path(string $asset = null): string
1413
{
1514
$defaultPath = config('laravel-generator.defaults.paths.ui_package_path').'/dist/';
1615
$path = base_path(config('laravel-generator.defaults.paths.laravel_generator_assets_path', $defaultPath));
1716

18-
if (!$asset) {
17+
if (! $asset) {
1918
return realpath($path);
2019
}
2120

2221
return realpath($path.$asset);
2322
}
2423
}
2524

26-
if (!function_exists('laravel_generator_asset')) {
25+
if (! function_exists('laravel_generator_asset')) {
2726
/**
2827
* Returns asset from laravel-generator composer package.
2928
*
3029
* @param $asset string
31-
*
3230
* @return string
3331
*
3432
* @throws LaravelGeneratorException
@@ -37,7 +35,7 @@ function laravel_generator_asset(string $asset): string
3735
{
3836
$file = laravel_generator_dist_path($asset);
3937

40-
if (!file_exists($file)) {
38+
if (! file_exists($file)) {
4139
throw new LaravelGeneratorException(sprintf('%s - this Laravel Generator asset does not exist', $asset));
4240
}
4341

@@ -47,12 +45,11 @@ function laravel_generator_asset(string $asset): string
4745
}
4846
}
4947

50-
if (!function_exists('laravel_generator_dist_path_allowed')) {
48+
if (! function_exists('laravel_generator_dist_path_allowed')) {
5149
/**
5250
* Returns asset allowed from laravel-generator composer package.
5351
*
5452
* @param $asset string
55-
*
5653
* @return string
5754
*
5855
* @throws LaravelGeneratorException
@@ -64,7 +61,7 @@ function laravel_generator_asset_allowed(string $asset): string
6461
'favicon-32x32.png',
6562
];
6663

67-
if (!in_array($asset, $allowed_files)) {
64+
if (! in_array($asset, $allowed_files)) {
6865
throw new LaravelGeneratorException(sprintf('%s - this Laravel Generator asset is not allowed', $asset));
6966
}
7067

src/Helpers/ConfigHelper.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
class ConfigHelper
88
{
99
/**
10-
* Get config
10+
* Get config.
1111
*
1212
* @param string|null $generatorName
13-
*
1413
* @return array
14+
*
1515
* @throws LaravelGeneratorException
1616
*/
1717
public function generatorConfig(?string $generatorName = null): array
@@ -23,19 +23,18 @@ public function generatorConfig(?string $generatorName = null): array
2323
$defaults = config('laravel-generator.defaults', []);
2424
$generators = config('laravel-generator.generators', []);
2525

26-
if (!isset($generators[$generatorName])) {
26+
if (! isset($generators[$generatorName])) {
2727
throw new LaravelGeneratorException('Generator name not found');
2828
}
2929

3030
return $this->mergeConfig($defaults, $generators[$generatorName]);
3131
}
3232

3333
/**
34-
* Merge config
34+
* Merge config.
3535
*
3636
* @param array $defaults
3737
* @param array $generatorName
38-
*
3938
* @return array
4039
*/
4140
private function mergeConfig(array $defaults, array $generatorName): array
@@ -58,10 +57,9 @@ private function mergeConfig(array $defaults, array $generatorName): array
5857
}
5958

6059
/**
61-
* Check is associative key array
60+
* Check is associative key array.
6261
*
6362
* @param mixed $key
64-
*
6563
* @return bool
6664
*/
6765
private function isAssociativeArray(mixed $key): bool

src/Http/Controllers/Asset/AssetController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class AssetController extends BaseController
1313
{
1414
/**
1515
* @param Request $request
16-
*
1716
* @return string
1817
*/
1918
public function index(Request $request)
@@ -28,7 +27,7 @@ public function index(Request $request)
2827
$fileSystem->get($path),
2928
200,
3029
[
31-
'Content-Type' => (pathinfo($asset))['extension'] == 'css'
30+
'Content-Type' => pathinfo($asset)['extension'] == 'css'
3231
? 'text/css'
3332
: 'application/javascript',
3433
]

src/Http/Controllers/Detect/DetectController.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class DetectController extends Controller
1212
{
1313
/**
1414
* @param $file
15-
*
1615
* @return ReflectionClass|null
1716
*/
1817
public function getClassFromFile($file)
@@ -22,7 +21,7 @@ public function getClassFromFile($file)
2221

2322
// Match namespace and class name
2423
preg_match('/namespace\s+(.*?);.*?class\s+(\w+)/s', $content, $matches);
25-
if (!isset($matches[1]) || !isset($matches[2])) {
24+
if (! isset($matches[1]) || ! isset($matches[2])) {
2625
return null;
2726
}
2827

@@ -34,7 +33,6 @@ public function getClassFromFile($file)
3433

3534
/**
3635
* @param ReflectionClass $class
37-
*
3836
* @return bool
3937
*/
4038
private function dependsOnModels(ReflectionClass $class)
@@ -45,14 +43,14 @@ private function dependsOnModels(ReflectionClass $class)
4543
return true;
4644
}
4745
}
46+
4847
return false;
4948
}
5049

5150
/**
52-
* Check if the class implements the CRUD methods
51+
* Check if the class implements the CRUD methods.
5352
*
5453
* @param ReflectionClass $class
55-
*
5654
* @return bool
5755
*/
5856
protected function implementsCrudMethods(ReflectionClass $class)
@@ -62,7 +60,7 @@ protected function implementsCrudMethods(ReflectionClass $class)
6260
'create',
6361
'read',
6462
'update',
65-
'delete'
63+
'delete',
6664
];
6765

6866
foreach ($methods as $method) {
@@ -78,10 +76,9 @@ protected function implementsCrudMethods(ReflectionClass $class)
7876
* Check if the class is a repository class
7977
* A repository class must have a name ending with "Repository" or "EloquentRepository"
8078
* and implement the CRUD methods
81-
* and have a dependency on a model
79+
* and have a dependency on a model.
8280
*
8381
* @param ReflectionClass $class
84-
*
8582
* @return bool
8683
*/
8784
public function isRepositoryClass(ReflectionClass $class)
@@ -91,10 +88,9 @@ public function isRepositoryClass(ReflectionClass $class)
9188

9289
/**
9390
* Check if the class is a service class
94-
* A service class must have a name ending with "Service" or "EloquentService"
91+
* A service class must have a name ending with "Service" or "EloquentService".
9592
*
9693
* @param ReflectionClass $class
97-
*
9894
* @return bool
9995
*/
10096
public function isServiceClass(ReflectionClass $class)
@@ -106,10 +102,9 @@ public function isServiceClass(ReflectionClass $class)
106102
* Check if the class is a controller class
107103
* A controller class must have a name ending with "Controller" or "EloquentController"
108104
* and implement the CRUD methods
109-
* and have a dependency on a model
105+
* and have a dependency on a model.
110106
*
111107
* @param ReflectionClass $class
112-
*
113108
* @return bool
114109
*/
115110
public function isControllerClass(ReflectionClass $class)
@@ -119,10 +114,9 @@ public function isControllerClass(ReflectionClass $class)
119114

120115
/**
121116
* Check if the class is an action class
122-
* An action class must have a name ending with "Action" or "EloquentAction"
117+
* An action class must have a name ending with "Action" or "EloquentAction".
123118
*
124119
* @param ReflectionClass $class
125-
*
126120
* @return bool
127121
*/
128122
public function isActionClass(ReflectionClass $class)
@@ -132,27 +126,26 @@ public function isActionClass(ReflectionClass $class)
132126

133127
/**
134128
* Check if the class is a class of the given type
135-
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type
129+
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type.
136130
*
137131
* @param ReflectionClass $class
138132
* @param $type
139-
*
140133
* @return bool
141134
*/
142135
protected function checkClassType(ReflectionClass $class, $type)
143136
{
144137
$type = ucfirst($type);
138+
145139
return preg_match('/'.$type.'$/', $class->getName()) === 1
146140
|| preg_match('/Eloquent'.$type.'$/', $class->getName()) === 1
147141
&& $this->implementsCrudMethods($class)
148142
&& $this->dependsOnModels($class);
149143
}
150144

151145
/**
152-
* Get the type of the given class
146+
* Get the type of the given class.
153147
*
154148
* @param ReflectionClass $class
155-
*
156149
* @return string
157150
*/
158151
protected function getClassType(ReflectionClass $class)
@@ -178,7 +171,7 @@ protected function getClassType(ReflectionClass $class)
178171
}
179172

180173
/**
181-
* Get the type of all classes in the app folder
174+
* Get the type of all classes in the app folder.
182175
*
183176
* @return array[]
184177
*/
@@ -189,7 +182,7 @@ public function detect()
189182
$type = [];
190183

191184
foreach ($files as $file) {
192-
if (!$file->isFile() || $file->getExtension() !== 'php') {
185+
if (! $file->isFile() || $file->getExtension() !== 'php') {
193186
continue;
194187
}
195188

src/Http/Controllers/Generator/RepositoryGeneratorController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Support\Str;
66
use Lbil\LaravelGenerator\Http\Controllers\Detect\DetectController;
7-
use Lbil\LaravelGenerator\Http\Requests\Generator\RepositoryGeneratorRequest;
87

98
class RepositoryGeneratorController extends GeneratorController
109
{
@@ -44,7 +43,7 @@ public function saveFile($fileName, $fileContent)
4443
{
4544
$filePath = app_path("Repositories/{$fileName}");
4645

47-
if (!is_dir(dirname($filePath))) {
46+
if (! is_dir(dirname($filePath))) {
4847
mkdir(dirname($filePath), 0777, true);
4948
}
5049

src/Http/Controllers/LaravelGeneratorController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
namespace Lbil\LaravelGenerator\Http\Controllers;
44

5-
use Illuminate\Http\Request;
6-
use Illuminate\Routing\Controller;
75
use Illuminate\Contracts\Foundation\Application;
86
use Illuminate\Contracts\View\Factory;
97
use Illuminate\Contracts\View\View;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Routing\Controller;
1010
use Lbil\LaravelGenerator\Http\Controllers\Detect\DetectController;
1111

1212
class LaravelGeneratorController extends Controller
1313
{
1414
/**
1515
* @param Request $request
16-
*
1716
* @return Application|Factory|View
1817
*/
1918
public function index(Request $request)

src/Http/Requests/ApiRequest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99

1010
/**
1111
* Class ApiRequest.
12-
* @package Lbil\LaravelGenerator\Http\Requests
13-
*
14-
* This class is used to handle the validation error response. It will return the error message in JSON format.
1512
*/
1613
abstract class ApiRequest extends FormRequest
1714
{
1815
/**
19-
* @param Validator $validator
16+
* @param Validator $validator
2017
*
2118
* @return void
2219
*/

src/Providers/LaravelGeneratorServiceProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ class LaravelGeneratorServiceProvider extends ServiceProvider
1414
*/
1515
public function boot(): void
1616
{
17-
$viewPath = __DIR__ . '/../../resources/views';
17+
$viewPath = __DIR__.'/../../resources/views';
1818
$this->loadViewsFrom($viewPath, 'laravel-generator');
1919

2020
// Publish a config file
21-
$configPath = __DIR__ . '/../../config/laravel-generator.php';
21+
$configPath = __DIR__.'/../../config/laravel-generator.php';
2222
$this->publishes([
2323
$configPath => config_path('laravel-generator.php'),
2424
], 'config');
2525

2626
// Publish views
2727
$this->publishes([
28-
__DIR__ . '/../../resources/views' => config('laravel-generator.defaults.paths.views'),
28+
__DIR__.'/../../resources/views' => config('laravel-generator.defaults.paths.views'),
2929
], 'views');
3030

3131
// Include routes
32-
$routePath = __DIR__ . '/../../routes/web.php';
32+
$routePath = __DIR__.'/../../routes/web.php';
3333
if (file_exists($routePath)) {
3434
$this->loadRoutesFrom($routePath);
3535
}
3636

3737
// Load package helpers file
38-
$helpersPath = __DIR__ . '/../../common/helpers.php';
38+
$helpersPath = __DIR__.'/../../common/helpers.php';
3939
if (file_exists($helpersPath)) {
4040
require_once $helpersPath;
4141
}
4242

4343
// Load language files
44-
$this->loadTranslationsFrom(__DIR__ . '/../../lang', 'laravel-generator');
44+
$this->loadTranslationsFrom(__DIR__.'/../../lang', 'laravel-generator');
4545

4646
// Publish language files
4747
$this->publishes([
48-
__DIR__ . '/../../lang' => resource_path('lang/vendor/laravel-generator'),
48+
__DIR__.'/../../lang' => resource_path('lang/vendor/laravel-generator'),
4949
], 'lang');
5050
}
5151

@@ -56,7 +56,7 @@ public function boot(): void
5656
*/
5757
public function register(): void
5858
{
59-
$configPath = __DIR__ . '/../../config/laravel-generator.php';
59+
$configPath = __DIR__.'/../../config/laravel-generator.php';
6060
$this->mergeConfigFrom($configPath, 'laravel-generator');
6161

6262
$this->app->singleton('laravel-generator', function () {

0 commit comments

Comments
 (0)