Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
preset: psr12
preset: laravel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the format style to Laravel

23 changes: 10 additions & 13 deletions common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@

use Lbil\LaravelGenerator\Exceptions\LaravelGeneratorException;

if (!function_exists('laravel_generator_dist_path')) {
if (! function_exists('laravel_generator_dist_path')) {
/**
* Returns laravel-generator composer dist path.
*
* @param string|null $asset string
*
* @param string|null $asset string
* @return string
*/
function laravel_generator_dist_path(string $asset = null): string
{
$defaultPath = config('laravel-generator.defaults.paths.ui_package_path') . '/dist/';
$defaultPath = config('laravel-generator.defaults.paths.ui_package_path').'/dist/';
$path = base_path(config('laravel-generator.defaults.paths.laravel_generator_assets_path', $defaultPath));

if (!$asset) {
if (! $asset) {
return realpath($path);
}

return realpath($path . $asset);
return realpath($path.$asset);
}
}

if (!function_exists('laravel_generator_asset')) {
if (! function_exists('laravel_generator_asset')) {
/**
* Returns asset from laravel-generator composer package.
*
* @param $asset string
*
* @return string
*
* @throws LaravelGeneratorException
Expand All @@ -37,22 +35,21 @@ function laravel_generator_asset(string $asset): string
{
$file = laravel_generator_dist_path($asset);

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

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

return route('laravel_generator.asset', ['asset' => $asset], $useAbsolutePath) . '?v=' . filemtime($file);
return route('laravel_generator.asset', ['asset' => $asset], $useAbsolutePath).'?v='.filemtime($file);
}
}

if (!function_exists('laravel_generator_dist_path_allowed')) {
if (! function_exists('laravel_generator_dist_path_allowed')) {
/**
* Returns asset allowed from laravel-generator composer package.
*
* @param $asset string
*
* @return string
*
* @throws LaravelGeneratorException
Expand All @@ -64,7 +61,7 @@ function laravel_generator_asset_allowed(string $asset): string
'favicon-32x32.png',
];

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

Expand Down
23 changes: 12 additions & 11 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
@yield('title', config('laravel-generator.app_name', __('laravel-generator::generator.app_name')))
</title>
<!-- Fonts and icons -->
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900|Roboto+Slab:400,700"/>
<link rel="stylesheet" type="text/css"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900|Roboto+Slab:400,700"/>

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

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

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

@yield('laravel-generator-content')
</div>
@yield('laravel-generator-content')
</div>

@include('laravel-generator::shared.configurator_settings')
@include('laravel-generator::shared.configurator_settings')

@include('laravel-generator::shared.footer')
</body>
@include('laravel-generator::shared.footer')
</body>
6 changes: 3 additions & 3 deletions src/Exceptions/LaravelGeneratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class LaravelGeneratorException extends Exception
{
/**
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param string $message
* @param int $code
* @param Exception|null $previous
*/
public function __construct(string $message = '', int $code = 0, Exception $previous = null)
{
Expand Down
20 changes: 9 additions & 11 deletions src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class ConfigHelper
{
/**
* Get config
*
* @param string|null $generatorName
* Get config.
*
* @param string|null $generatorName
* @return array
*
* @throws LaravelGeneratorException
*/
public function generatorConfig(?string $generatorName = null): array
Expand All @@ -23,19 +23,18 @@ public function generatorConfig(?string $generatorName = null): array
$defaults = config('laravel-generator.defaults', []);
$generators = config('laravel-generator.generators', []);

if (!isset($generators[$generatorName])) {
if (! isset($generators[$generatorName])) {
throw new LaravelGeneratorException('Generator name not found');
}

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

/**
* Merge config
*
* @param array $defaults
* @param array $generatorName
* Merge config.
*
* @param array $defaults
* @param array $generatorName
* @return array
*/
private function mergeConfig(array $defaults, array $generatorName): array
Expand All @@ -58,10 +57,9 @@ private function mergeConfig(array $defaults, array $generatorName): array
}

/**
* Check is associative key array
*
* @param mixed $key
* Check is associative key array.
*
* @param mixed $key
* @return bool
*/
private function isAssociativeArray(mixed $key): bool
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Controllers/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
class AssetController extends BaseController
{
/**
* @param Request $request
*
* @param Request $request
* @return string
*/
public function index(Request $request)
Expand All @@ -28,7 +27,7 @@ public function index(Request $request)
$fileSystem->get($path),
200,
[
'Content-Type' => (pathinfo($asset))['extension'] == 'css'
'Content-Type' => pathinfo($asset)['extension'] == 'css'
? 'text/css'
: 'application/javascript',
]
Expand Down
55 changes: 24 additions & 31 deletions src/Http/Controllers/Detect/DetectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DetectController extends Controller
{
/**
* @param $file
*
* @return ReflectionClass|null
*/
public function getClassFromFile($file)
Expand All @@ -22,19 +21,18 @@ public function getClassFromFile($file)

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

$namespace = $matches[1];
$class = $namespace . '\\' . $matches[2];
$class = $namespace.'\\'.$matches[2];

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

/**
* @param ReflectionClass $class
*
* @param ReflectionClass $class
* @return bool
*/
private function dependsOnModels(ReflectionClass $class)
Expand All @@ -45,14 +43,14 @@ private function dependsOnModels(ReflectionClass $class)
return true;
}
}

return false;
}

/**
* Check if the class implements the CRUD methods
*
* @param ReflectionClass $class
* Check if the class implements the CRUD methods.
*
* @param ReflectionClass $class
* @return bool
*/
protected function implementsCrudMethods(ReflectionClass $class)
Expand All @@ -62,7 +60,7 @@ protected function implementsCrudMethods(ReflectionClass $class)
'create',
'read',
'update',
'delete'
'delete',
];

foreach ($methods as $method) {
Expand All @@ -78,10 +76,9 @@ protected function implementsCrudMethods(ReflectionClass $class)
* Check if the class is a repository class
* A repository class must have a name ending with "Repository" or "EloquentRepository"
* and implement the CRUD methods
* and have a dependency on a model
*
* @param ReflectionClass $class
* and have a dependency on a model.
*
* @param ReflectionClass $class
* @return bool
*/
public function isRepositoryClass(ReflectionClass $class)
Expand All @@ -91,10 +88,9 @@ public function isRepositoryClass(ReflectionClass $class)

/**
* Check if the class is a service class
* A service class must have a name ending with "Service" or "EloquentService"
*
* @param ReflectionClass $class
* A service class must have a name ending with "Service" or "EloquentService".
*
* @param ReflectionClass $class
* @return bool
*/
public function isServiceClass(ReflectionClass $class)
Expand All @@ -106,10 +102,9 @@ public function isServiceClass(ReflectionClass $class)
* Check if the class is a controller class
* A controller class must have a name ending with "Controller" or "EloquentController"
* and implement the CRUD methods
* and have a dependency on a model
*
* @param ReflectionClass $class
* and have a dependency on a model.
*
* @param ReflectionClass $class
* @return bool
*/
public function isControllerClass(ReflectionClass $class)
Expand All @@ -119,10 +114,9 @@ public function isControllerClass(ReflectionClass $class)

/**
* Check if the class is an action class
* An action class must have a name ending with "Action" or "EloquentAction"
*
* @param ReflectionClass $class
* An action class must have a name ending with "Action" or "EloquentAction".
*
* @param ReflectionClass $class
* @return bool
*/
public function isActionClass(ReflectionClass $class)
Expand All @@ -132,27 +126,26 @@ public function isActionClass(ReflectionClass $class)

/**
* Check if the class is a class of the given type
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type
* A class of the given type must have a name ending with the given type or "Eloquent" + the given type.
*
* @param ReflectionClass $class
* @param ReflectionClass $class
* @param $type
*
* @return bool
*/
protected function checkClassType(ReflectionClass $class, $type)
{
$type = ucfirst($type);
return preg_match('/' . $type . '$/', $class->getName()) === 1
|| preg_match('/Eloquent' . $type . '$/', $class->getName()) === 1

return preg_match('/'.$type.'$/', $class->getName()) === 1
|| preg_match('/Eloquent'.$type.'$/', $class->getName()) === 1
&& $this->implementsCrudMethods($class)
&& $this->dependsOnModels($class);
}

/**
* Get the type of the given class
*
* @param ReflectionClass $class
* Get the type of the given class.
*
* @param ReflectionClass $class
* @return string
*/
protected function getClassType(ReflectionClass $class)
Expand All @@ -178,7 +171,7 @@ protected function getClassType(ReflectionClass $class)
}

/**
* Get the type of all classes in the app folder
* Get the type of all classes in the app folder.
*
* @return array[]
*/
Expand All @@ -189,7 +182,7 @@ public function detect()
$type = [];

foreach ($files as $file) {
if (!$file->isFile() || $file->getExtension() !== 'php') {
if (! $file->isFile() || $file->getExtension() !== 'php') {
continue;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Http/Controllers/Generator/GeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Lbil\LaravelGenerator\Http\Controllers\Generator;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;

class GeneratorController extends Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Lbil\LaravelGenerator\Http\Controllers\Generator;

use Str;
use Illuminate\Support\Str;
use Lbil\LaravelGenerator\Http\Controllers\Detect\DetectController;
use Lbil\LaravelGenerator\Http\Requests\Generator\RepositoryGeneratorRequest;

class RepositoryGeneratorController extends GeneratorController
{
Expand Down Expand Up @@ -44,7 +43,7 @@ public function saveFile($fileName, $fileContent)
{
$filePath = app_path("Repositories/{$fileName}");

if (!is_dir(dirname($filePath))) {
if (! is_dir(dirname($filePath))) {
mkdir(dirname($filePath), 0777, true);
}

Expand Down
Loading