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

Commit 6314b2b

Browse files
committed
revert style ci and format code
1 parent 59e6708 commit 6314b2b

File tree

5 files changed

+99
-96
lines changed

5 files changed

+99
-96
lines changed

.styleci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
preset: laravel
2+
3+
disabled:
4+
- not_operator_with_successor_space

common/helpers.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
*
@@ -13,20 +13,20 @@ function laravel_generator_dist_path(string $asset = null): string
1313
{
1414
$defaultPath = config('laravel-generator.defaults.paths.ui_package_path').'/dist/';
1515
$assetPath = config('laravel-generator.defaults.paths.laravel_generator_assets_path', $defaultPath);
16-
if (! str_ends_with($assetPath, '/')) {
16+
if (!str_ends_with($assetPath, '/')) {
1717
$assetPath .= '/';
1818
}
1919
$path = base_path($assetPath);
2020

21-
if (! $asset) {
21+
if (!$asset) {
2222
return realpath($path);
2323
}
2424

2525
return realpath($path.$asset);
2626
}
2727
}
2828

29-
if (! function_exists('laravel_generator_asset')) {
29+
if (!function_exists('laravel_generator_asset')) {
3030
/**
3131
* Returns asset from laravel-generator composer package.
3232
*
@@ -39,7 +39,7 @@ function laravel_generator_asset(string $asset): string
3939
{
4040
$file = laravel_generator_dist_path($asset);
4141

42-
if (! file_exists($file)) {
42+
if (!file_exists($file)) {
4343
throw new LaravelGeneratorException(sprintf('%s - this Laravel Generator asset does not exist', $asset));
4444
}
4545

@@ -49,7 +49,7 @@ function laravel_generator_asset(string $asset): string
4949
}
5050
}
5151

52-
if (! function_exists('laravel_generator_dist_path_allowed')) {
52+
if (!function_exists('laravel_generator_dist_path_allowed')) {
5353
/**
5454
* Returns asset allowed from laravel-generator composer package.
5555
*
@@ -65,7 +65,7 @@ function laravel_generator_asset_allowed(string $asset): string
6565
'favicon-32x32.png',
6666
];
6767

68-
if (! in_array($asset, $allowed_files)) {
68+
if (!in_array($asset, $allowed_files)) {
6969
throw new LaravelGeneratorException(sprintf('%s - this Laravel Generator asset is not allowed', $asset));
7070
}
7171

src/Helpers/ConfigHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ 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

src/Http/Controllers/Detect/DetectController.php

+87-87
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010

1111
class DetectController extends Controller
1212
{
13+
/**
14+
* Get the type of all classes in the app folder.
15+
*
16+
* @return array[]
17+
*/
18+
public function detect()
19+
{
20+
$recursiveDirectoryIterator = new RecursiveDirectoryIterator(app_path());
21+
$files = new RecursiveIteratorIterator($recursiveDirectoryIterator);
22+
$type = [];
23+
24+
foreach ($files as $file) {
25+
if (!$file->isFile() || $file->getExtension() !== 'php') {
26+
continue;
27+
}
28+
29+
$class = $this->getClassFromFile($file);
30+
if ($class !== null) {
31+
$type[] = $this->getClassType($class);
32+
}
33+
}
34+
35+
return $type;
36+
}
37+
1338
/**
1439
* @param $file
1540
* @return ReflectionClass|null
@@ -21,7 +46,7 @@ public function getClassFromFile($file)
2146

2247
// Match namespace and class name
2348
preg_match('/namespace\s+(.*?);.*?class\s+(\w+)/s', $content, $matches);
24-
if (! isset($matches[1]) || ! isset($matches[2])) {
49+
if (!isset($matches[1]) || !isset($matches[2])) {
2550
return null;
2651
}
2752

@@ -32,19 +57,63 @@ public function getClassFromFile($file)
3257
}
3358

3459
/**
60+
* Get the type of the given class.
61+
*
3562
* @param ReflectionClass $class
36-
* @return bool
63+
* @return string
3764
*/
38-
private function dependsOnModels(ReflectionClass $class)
65+
protected function getClassType(ReflectionClass $class)
3966
{
40-
$dependencies = $class->getConstructor()->getParameters();
41-
foreach ($dependencies as $dependency) {
42-
if (preg_match('/Model$/', $dependency->getClass()->getName()) === 1) {
43-
return true;
44-
}
67+
$type = 'other';
68+
69+
switch (true) {
70+
case $this->isRepositoryClass($class):
71+
$type = 'repository';
72+
break;
73+
case $this->isServiceClass($class):
74+
$type = 'service';
75+
break;
76+
case $this->isControllerClass($class):
77+
$type = 'controller';
78+
break;
79+
case $this->isActionClass($class):
80+
$type = 'action';
81+
break;
4582
}
4683

47-
return false;
84+
return $type;
85+
}
86+
87+
/**
88+
* Check if the class is a repository class
89+
* A repository class must have a name ending with "Repository" or "EloquentRepository"
90+
* and implement the CRUD methods
91+
* and have a dependency on a model.
92+
*
93+
* @param ReflectionClass $class
94+
* @return bool
95+
*/
96+
public function isRepositoryClass(ReflectionClass $class)
97+
{
98+
return $this->checkClassType($class, 'repository');
99+
}
100+
101+
/**
102+
* Check if the class is a class of the given type
103+
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type.
104+
*
105+
* @param ReflectionClass $class
106+
* @param $type
107+
* @return bool
108+
*/
109+
protected function checkClassType(ReflectionClass $class, $type)
110+
{
111+
$type = ucfirst($type);
112+
113+
return preg_match('/'.$type.'$/', $class->getName()) === 1
114+
|| preg_match('/Eloquent'.$type.'$/', $class->getName()) === 1
115+
&& $this->implementsCrudMethods($class)
116+
&& $this->dependsOnModels($class);
48117
}
49118

50119
/**
@@ -73,17 +142,19 @@ protected function implementsCrudMethods(ReflectionClass $class)
73142
}
74143

75144
/**
76-
* Check if the class is a repository class
77-
* A repository class must have a name ending with "Repository" or "EloquentRepository"
78-
* and implement the CRUD methods
79-
* and have a dependency on a model.
80-
*
81145
* @param ReflectionClass $class
82146
* @return bool
83147
*/
84-
public function isRepositoryClass(ReflectionClass $class)
148+
private function dependsOnModels(ReflectionClass $class)
85149
{
86-
return $this->checkClassType($class, 'repository');
150+
$dependencies = $class->getConstructor()->getParameters();
151+
foreach ($dependencies as $dependency) {
152+
if (preg_match('/Model$/', $dependency->getClass()->getName()) === 1) {
153+
return true;
154+
}
155+
}
156+
157+
return false;
87158
}
88159

89160
/**
@@ -123,75 +194,4 @@ public function isActionClass(ReflectionClass $class)
123194
{
124195
return $this->checkClassType($class, 'action');
125196
}
126-
127-
/**
128-
* Check if the class is a class of the given type
129-
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type.
130-
*
131-
* @param ReflectionClass $class
132-
* @param $type
133-
* @return bool
134-
*/
135-
protected function checkClassType(ReflectionClass $class, $type)
136-
{
137-
$type = ucfirst($type);
138-
139-
return preg_match('/'.$type.'$/', $class->getName()) === 1
140-
|| preg_match('/Eloquent'.$type.'$/', $class->getName()) === 1
141-
&& $this->implementsCrudMethods($class)
142-
&& $this->dependsOnModels($class);
143-
}
144-
145-
/**
146-
* Get the type of the given class.
147-
*
148-
* @param ReflectionClass $class
149-
* @return string
150-
*/
151-
protected function getClassType(ReflectionClass $class)
152-
{
153-
$type = 'other';
154-
155-
switch (true) {
156-
case $this->isRepositoryClass($class):
157-
$type = 'repository';
158-
break;
159-
case $this->isServiceClass($class):
160-
$type = 'service';
161-
break;
162-
case $this->isControllerClass($class):
163-
$type = 'controller';
164-
break;
165-
case $this->isActionClass($class):
166-
$type = 'action';
167-
break;
168-
}
169-
170-
return $type;
171-
}
172-
173-
/**
174-
* Get the type of all classes in the app folder.
175-
*
176-
* @return array[]
177-
*/
178-
public function detect()
179-
{
180-
$recursiveDirectoryIterator = new RecursiveDirectoryIterator(app_path());
181-
$files = new RecursiveIteratorIterator($recursiveDirectoryIterator);
182-
$type = [];
183-
184-
foreach ($files as $file) {
185-
if (! $file->isFile() || $file->getExtension() !== 'php') {
186-
continue;
187-
}
188-
189-
$class = $this->getClassFromFile($file);
190-
if ($class !== null) {
191-
$type[] = $this->getClassType($class);
192-
}
193-
}
194-
195-
return $type;
196-
}
197197
}

src/Http/Controllers/Generator/RepositoryGeneratorController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function saveFile($fileName, $fileContent)
4343
{
4444
$filePath = app_path("Repositories/{$fileName}");
4545

46-
if (! is_dir(dirname($filePath))) {
46+
if (!is_dir(dirname($filePath))) {
4747
mkdir(dirname($filePath), 0777, true);
4848
}
4949

0 commit comments

Comments
 (0)