Skip to content
Open
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
1 change: 0 additions & 1 deletion config/reversekit.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,3 @@
],

];

1 change: 0 additions & 1 deletion examples/generated/app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ public function destroy(Post $post): JsonResponse
return response()->json(null, 204);
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ public function destroy(User $user): JsonResponse
return response()->json(null, 204);
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ public function toArray(Request $request): array
];
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ public function toArray(Request $request): array
];
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ public function user(): BelongsTo
return $this->belongsTo(User::class, 'user_id');
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ public function posts(): HasMany
return $this->hasMany(Post::class, 'user_id');
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Policies/PostPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ public function forceDelete(User $user, Post $post): bool
return $user->id === $post->user_id;
}
}

1 change: 0 additions & 1 deletion examples/generated/app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ public function forceDelete(User $user, User $model): bool
return true;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*/
Expand All @@ -27,4 +26,3 @@ public function down(): void
Schema::dropIfExists('users');
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*/
Expand All @@ -29,4 +28,3 @@ public function down(): void
Schema::dropIfExists('posts');
}
};

1 change: 0 additions & 1 deletion examples/generated/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

Route::apiResource('users', \App\Http\Controllers\UserController::class);
Route::apiResource('posts', \App\Http\Controllers\PostController::class);

1 change: 0 additions & 1 deletion examples/generated/tests/Feature/PostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ public function test_can_delete_post(): void
$this->assertDatabaseMissing('posts', ['id' => $post->id]);
}
}

1 change: 0 additions & 1 deletion examples/generated/tests/Feature/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,3 @@ public function test_can_delete_user(): void
$this->assertDatabaseMissing('users', ['id' => $targetUser->id]);
}
}

5 changes: 2 additions & 3 deletions src/Commands/ReverseGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,10 @@ private function displaySummary(): void
$this->newLine();
$this->info('📊 Generation Summary:');

$created = count(array_filter($this->generatedFiles, fn($f) => $f['created']));
$skipped = count(array_filter($this->generatedFiles, fn($f) => $f['existed'] && !$f['created']));
$created = count(array_filter($this->generatedFiles, fn ($f) => $f['created']));
$skipped = count(array_filter($this->generatedFiles, fn ($f) => $f['existed'] && !$f['created']));

$this->line(" ✓ Created: {$created} files");
$this->line(" ○ Skipped: {$skipped} files (already existed)");
}
}

4 changes: 2 additions & 2 deletions src/Commands/ReverseInteractiveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function collectEntities(RelationshipDetector $relationshipDetector): vo
label: 'Enter model name (e.g., User, BlogPost)',
placeholder: 'User',
required: true,
validate: fn(string $value) => preg_match('/^[A-Z][a-zA-Z0-9]*$/', $value)
validate: fn (string $value) => preg_match('/^[A-Z][a-zA-Z0-9]*$/', $value)
? null
: 'Model name must be PascalCase (e.g., User, BlogPost)'
);
Expand Down Expand Up @@ -213,7 +213,7 @@ private function collectFields(string $entityName): array
label: 'Field name (snake_case)',
placeholder: 'title',
required: true,
validate: fn(string $value) => preg_match('/^[a-z][a-z0-9_]*$/', $value)
validate: fn (string $value) => preg_match('/^[a-z][a-z0-9_]*$/', $value)
? null
: 'Field name must be snake_case (e.g., title, created_at)'
);
Expand Down
1 change: 0 additions & 1 deletion src/Contracts/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ public function parse(string $input): array;
*/
public function getEntities(): array;
}

3 changes: 1 addition & 2 deletions src/Generators/BaseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function indent(string $code, int $levels = 1): string
{
$indent = str_repeat(' ', $levels);
$lines = explode("\n", $code);
return implode("\n", array_map(fn($line) => $line ? $indent . $line : $line, $lines));
return implode("\n", array_map(fn ($line) => $line ? $indent . $line : $line, $lines));
}

/**
Expand Down Expand Up @@ -171,4 +171,3 @@ protected function getPath(string $className): string
return $this->getBasePath() . '/' . $className . '.php';
}
}

1 change: 0 additions & 1 deletion src/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,3 @@ private function getFieldRules(string $fieldName, array $field): string
return implode('|', $rules);
}
}

1 change: 0 additions & 1 deletion src/Generators/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,3 @@ protected function getPath(string $className): string
return database_path('factories/' . $className . '.php');
}
}

1 change: 0 additions & 1 deletion src/Generators/FormRequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ protected function getPath(string $className): string
return $this->getBasePath() . '/Http/Requests/' . $className . '.php';
}
}

1 change: 0 additions & 1 deletion src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,3 @@ public static function resetOrder(): void
self::$migrationOrder = 0;
}
}

7 changes: 3 additions & 4 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function generateContent(array $entity): string
}

sort($uses);
$useStatements = implode("\n", array_map(fn($use) => "use {$use};", $uses));
$useStatements = implode("\n", array_map(fn ($use) => "use {$use};", $uses));

$content = <<<PHP
<?php
Expand Down Expand Up @@ -89,14 +89,14 @@ private function generateFillable(array $fields): string
{
$fillableFields = array_filter(
array_keys($fields),
fn($name) => $name !== 'id' && !in_array($name, ['created_at', 'updated_at'])
fn ($name) => $name !== 'id' && !in_array($name, ['created_at', 'updated_at'])
);

if (empty($fillableFields)) {
return " protected \$fillable = [];";
}

$items = array_map(fn($field) => " '{$field}',", $fillableFields);
$items = array_map(fn ($field) => " '{$field}',", $fillableFields);
$itemsString = implode("\n", $items);

return <<<PHP
Expand Down Expand Up @@ -190,4 +190,3 @@ public function {$method}(): BelongsTo
PHP;
}
}

1 change: 0 additions & 1 deletion src/Generators/PolicyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,3 @@ private function generateOwnershipCheck(string $modelVar): string
return "\$user->id === \${$modelVar}->user_id";
}
}

1 change: 0 additions & 1 deletion src/Generators/ResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@ private function generateFieldsArray(array $entity): string
return "[\n{$fieldsString}\n ]";
}
}

3 changes: 1 addition & 2 deletions src/Generators/RouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function generateAll(array $entities, bool $force = false): array
*/
private function generateRouteBlock(array $entities, array $routes): string
{
$modelNames = implode(', ', array_map(fn($e) => $e['name'], $entities));
$modelNames = implode(', ', array_map(fn ($e) => $e['name'], $entities));
$timestamp = date('Y-m-d H:i:s');

$block = "\n\n// ReverseKit Generated Routes ({$timestamp})";
Expand Down Expand Up @@ -129,4 +129,3 @@ private function createApiRouteFile(string $path, string $routeContent): void
file_put_contents($path, $content);
}
}

1 change: 0 additions & 1 deletion src/Generators/SeederGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ public function run(): void
PHP;
}
}

3 changes: 1 addition & 2 deletions src/Generators/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private function generateAssertFields(array $fields): string
{
$fieldNames = array_filter(
array_keys($fields),
fn($name) => !in_array($name, ['created_at', 'updated_at'])
fn ($name) => !in_array($name, ['created_at', 'updated_at'])
);

return "'" . implode("', '", $fieldNames) . "'";
Expand Down Expand Up @@ -241,4 +241,3 @@ private function getUpdatedValue(string $fieldName, array $field): string
};
}
}

4 changes: 2 additions & 2 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

abstract class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
use AuthorizesRequests;
use ValidatesRequests;
}

4 changes: 2 additions & 2 deletions src/Parsers/ApiUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ApiUrlParser implements ParserInterface

public function __construct(
private JsonParser $jsonParser
) {}
) {
}

/**
* Parse JSON from a URL.
Expand Down Expand Up @@ -112,4 +113,3 @@ public function getEntities(): array
return $this->entities;
}
}

5 changes: 3 additions & 2 deletions src/Parsers/DatabaseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class DatabaseParser implements ParserInterface

public function __construct(
private RelationshipDetector $relationshipDetector
) {}
) {
}

/**
* Parse database tables.
Expand Down Expand Up @@ -60,7 +61,7 @@ private function getTables(string $input): array

if ($input === '*') {
$allTables = Schema::getTableListing();
return array_filter($allTables, fn($table) => !in_array($table, $excludedTables));
return array_filter($allTables, fn ($table) => !in_array($table, $excludedTables));
}

$requestedTables = array_map('trim', explode(',', $input));
Expand Down
4 changes: 2 additions & 2 deletions src/Parsers/JsonParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class JsonParser
public function __construct(
private TypeInferrer $typeInferrer,
private RelationshipDetector $relationshipDetector
) {}
) {
}

/**
* Parse JSON content and extract entities.
Expand Down Expand Up @@ -219,4 +220,3 @@ public function getEntities(): array
return $this->entities;
}
}

3 changes: 2 additions & 1 deletion src/Parsers/OpenApiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class OpenApiParser implements ParserInterface
public function __construct(
private TypeInferrer $typeInferrer,
private RelationshipDetector $relationshipDetector
) {}
) {
}

/**
* Parse OpenAPI/Swagger specification file.
Expand Down
3 changes: 2 additions & 1 deletion src/Parsers/PostmanParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PostmanParser implements ParserInterface
public function __construct(
private TypeInferrer $typeInferrer,
private RelationshipDetector $relationshipDetector
) {}
) {
}

/**
* Parse Postman collection file.
Expand Down
1 change: 0 additions & 1 deletion src/ReverseKitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,3 @@ public function boot(): void
}
}
}

4 changes: 2 additions & 2 deletions src/Support/RelationshipDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class RelationshipDetector
{
public function __construct(
private TypeInferrer $typeInferrer
) {}
) {
}

/**
* Detect relationships from JSON structure.
Expand Down Expand Up @@ -180,4 +181,3 @@ public function toCamelCase(string $string): string
return lcfirst($this->toPascalCase($string));
}
}

1 change: 0 additions & 1 deletion src/Support/TypeInferrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,3 @@ public function isAssociativeArray(array $arr): bool
return array_keys($arr) !== range(0, count($arr) - 1);
}
}