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

Commit a12772b

Browse files
authored
Merge pull request #32 from tanhongit/develop
update format style
2 parents 8a63cb9 + edbfb1f commit a12772b

File tree

13 files changed

+79
-99
lines changed

13 files changed

+79
-99
lines changed

.styleci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
preset: psr12
1+
preset: laravel

common/helpers.php

Lines changed: 10 additions & 13 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
*
9-
* @param string|null $asset string
10-
*
9+
* @param string|null $asset string
1110
* @return string
1211
*/
1312
function laravel_generator_dist_path(string $asset = null): string
1413
{
15-
$defaultPath = config('laravel-generator.defaults.paths.ui_package_path') . '/dist/';
14+
$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

22-
return realpath($path . $asset);
21+
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,22 +35,21 @@ 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

4442
$useAbsolutePath = config('laravel-generator.defaults.paths.use_absolute_path', true);
4543

46-
return route('laravel_generator.asset', ['asset' => $asset], $useAbsolutePath) . '?v=' . filemtime($file);
44+
return route('laravel_generator.asset', ['asset' => $asset], $useAbsolutePath).'?v='.filemtime($file);
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

resources/views/layouts/app.blade.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
@yield('title', config('laravel-generator.app_name', __('laravel-generator::generator.app_name')))
1111
</title>
1212
<!-- Fonts and icons -->
13-
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900|Roboto+Slab:400,700"/>
13+
<link rel="stylesheet" type="text/css"
14+
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900|Roboto+Slab:400,700"/>
1415

1516
<!-- Font Awesome Icons -->
1617
<script src="https://kit.fontawesome.com/42d5adcbca.js" crossorigin="anonymous"></script>
@@ -21,17 +22,17 @@
2122
</head>
2223

2324
<body class="g-sidenav-show bg-gray-200">
24-
@include('laravel-generator::shared.left_bar')
25+
@include('laravel-generator::shared.left_bar')
2526

26-
<div class="main-content position-relative max-height-vh-100 h-100">
27-
<!-- Navbar -->
28-
@include('laravel-generator::shared.navbar')
29-
<!-- End Navbar -->
27+
<div class="main-content position-relative max-height-vh-100 h-100">
28+
<!-- Navbar -->
29+
@include('laravel-generator::shared.navbar')
30+
<!-- End Navbar -->
3031

31-
@yield('laravel-generator-content')
32-
</div>
32+
@yield('laravel-generator-content')
33+
</div>
3334

34-
@include('laravel-generator::shared.configurator_settings')
35+
@include('laravel-generator::shared.configurator_settings')
3536

36-
@include('laravel-generator::shared.footer')
37-
</body>
37+
@include('laravel-generator::shared.footer')
38+
</body>

src/Exceptions/LaravelGeneratorException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class LaravelGeneratorException extends Exception
88
{
99
/**
10-
* @param string $message
11-
* @param int $code
12-
* @param Exception|null $previous
10+
* @param string $message
11+
* @param int $code
12+
* @param Exception|null $previous
1313
*/
1414
public function __construct(string $message = '', int $code = 0, Exception $previous = null)
1515
{

src/Helpers/ConfigHelper.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
class ConfigHelper
88
{
99
/**
10-
* Get config
11-
*
12-
* @param string|null $generatorName
10+
* Get config.
1311
*
12+
* @param string|null $generatorName
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
35-
*
36-
* @param array $defaults
37-
* @param array $generatorName
34+
* Merge config.
3835
*
36+
* @param array $defaults
37+
* @param array $generatorName
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
62-
*
63-
* @param mixed $key
60+
* Check is associative key array.
6461
*
62+
* @param mixed $key
6563
* @return bool
6664
*/
6765
private function isAssociativeArray(mixed $key): bool

src/Http/Controllers/Asset/AssetController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
class AssetController extends BaseController
1313
{
1414
/**
15-
* @param Request $request
16-
*
15+
* @param Request $request
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: 24 additions & 31 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,19 +21,18 @@ 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

2928
$namespace = $matches[1];
30-
$class = $namespace . '\\' . $matches[2];
29+
$class = $namespace.'\\'.$matches[2];
3130

3231
return class_exists($class) ? new ReflectionClass($class) : null;
3332
}
3433

3534
/**
36-
* @param ReflectionClass $class
37-
*
35+
* @param ReflectionClass $class
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
53-
*
54-
* @param ReflectionClass $class
51+
* Check if the class implements the CRUD methods.
5552
*
53+
* @param ReflectionClass $class
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
82-
*
83-
* @param ReflectionClass $class
79+
* and have a dependency on a model.
8480
*
81+
* @param ReflectionClass $class
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"
95-
*
96-
* @param ReflectionClass $class
91+
* A service class must have a name ending with "Service" or "EloquentService".
9792
*
93+
* @param ReflectionClass $class
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
110-
*
111-
* @param ReflectionClass $class
105+
* and have a dependency on a model.
112106
*
107+
* @param ReflectionClass $class
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"
123-
*
124-
* @param ReflectionClass $class
117+
* An action class must have a name ending with "Action" or "EloquentAction".
125118
*
119+
* @param ReflectionClass $class
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
*
137-
* @param ReflectionClass $class
131+
* @param ReflectionClass $class
138132
* @param $type
139-
*
140133
* @return bool
141134
*/
142135
protected function checkClassType(ReflectionClass $class, $type)
143136
{
144137
$type = ucfirst($type);
145-
return preg_match('/' . $type . '$/', $class->getName()) === 1
146-
|| preg_match('/Eloquent' . $type . '$/', $class->getName()) === 1
138+
139+
return preg_match('/'.$type.'$/', $class->getName()) === 1
140+
|| 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
153-
*
154-
* @param ReflectionClass $class
146+
* Get the type of the given class.
155147
*
148+
* @param ReflectionClass $class
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/GeneratorController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Lbil\LaravelGenerator\Http\Controllers\Generator;
44

5-
use Illuminate\Http\Request;
65
use Illuminate\Routing\Controller;
7-
use Illuminate\Support\Facades\DB;
86

97
class GeneratorController extends Controller
108
{

src/Http/Controllers/Generator/RepositoryGeneratorController.php

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

33
namespace Lbil\LaravelGenerator\Http\Controllers\Generator;
44

5-
use Str;
5+
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

0 commit comments

Comments
 (0)