Skip to content

Commit ef79b22

Browse files
committed
preparing package
1 parent d72732f commit ef79b22

File tree

11 files changed

+220
-5
lines changed

11 files changed

+220
-5
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/tests export-ignore
2+
/config export-ignore
3+
/.github export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
README.md export-ignore

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
composer.phar
22
/vendor/
3-
4-
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
3+
.idea

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
# codebuddy
1+
# CodeBuddy
2+
3+
## All-in-One Code Quality Tool for Laravel
4+
5+
> **Note:** This package is currently compatible only with the Laravel framework.
6+
7+
## About
8+
CodeBuddy is a wrapper around essential development tools that help maintain code quality in your Laravel projects. It integrates:
9+
10+
- **Rector** (automated code refactoring)
11+
- **Pint** (code styling)
12+
- **PHPStan** (static analysis)
13+
- **PestPHP** (testing framework)
14+
15+
## Features
16+
- One command setup for essential tools.
17+
- CI/CD optimized validation.
18+
- Automated fixes for coding standards.
19+
- Code health reporting with email support.
20+
21+
## Commands
22+
23+
### Configure Code Quality Tools
24+
```sh
25+
php artisan codebuddy:configure
26+
```
27+
This command sets up **Rector, PestPHP, Pint, and PHPStan** with standard configurations.
28+
29+
### Run CI Checks
30+
```sh
31+
php artisan codebuddy:ci [--fix]
32+
```
33+
Runs tests, performs static analysis, and checks code style in a **dry-run mode** (does not modify files). Optimized for CI/CD pipelines.
34+
35+
- `--fix`: Automatically applies fixes for Rector and Pint where possible.
36+
37+
### Generate Code Quality Report
38+
```sh
39+
php artisan codebuddy:report [--show|--send-to=<email>]
40+
```
41+
- `--show`: Displays the overall code health report in the console.
42+
- `--send-to=<email>`: Sends the report to the specified email address.
43+
44+
---
45+
46+
This package simplifies code quality enforcement, making it easier to maintain a high standard across your Laravel projects.

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "codebuddyphp/codebuddy",
3+
"description": "All-in-one tool for your codebase",
4+
"type": "library",
5+
"require": {
6+
"php": "^8.2",
7+
"laravel/framework": "^11.0",
8+
"nunomaduro/termwind": "^2.3",
9+
"laravel/pint": "^1.20",
10+
"larastan/larastan": "^3.0",
11+
"rector/rector": "^2.0"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"Codebuddyphp\\Codebuddy\\": "src/"
16+
}
17+
},
18+
"scripts": {
19+
},
20+
"extra": {
21+
"laravel": {
22+
"providers": [
23+
"Codebuddyphp\\Codebuddy\\CodebuddyServiceProvider"
24+
],
25+
"aliases": {
26+
}
27+
}
28+
},
29+
"config": {
30+
"preferred-install": "dist"
31+
},
32+
"minimum-stability": "dev",
33+
"prefer-stable": true
34+
}

config/codebuddy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

config/laravel/phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- vendor/larastan/larastan/extension.neon
3+
4+
parameters:
5+
6+
paths:
7+
- app/
8+
9+
level: max

config/laravel/pint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"declare_strict_types": true,
5+
"strict_comparison": true
6+
}
7+
}

config/laravel/rector.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__.'/app',
10+
__DIR__.'/bootstrap/app.php',
11+
__DIR__.'/bootstrap/providers.php',
12+
__DIR__.'/config',
13+
__DIR__.'/public',
14+
__DIR__.'/resources',
15+
__DIR__.'/routes',
16+
__DIR__.'/tests',
17+
])
18+
->withPhpSets()
19+
->withPreparedSets(
20+
deadCode: true,
21+
codeQuality: true,
22+
typeDeclarations: true,
23+
privatization: true,
24+
earlyReturn: true,
25+
strictBooleans: true,
26+
);

src/CodebuddyServiceProvider.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Codebuddyphp\Codebuddy;
4+
5+
use Codebuddyphp\Codebuddy\Commands\Configure;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class CodebuddyServiceProvider extends ServiceProvider
9+
{
10+
public function register()
11+
{
12+
// Register bindings if any
13+
}
14+
15+
public function boot()
16+
{
17+
if ($this->app->runningInConsole()) {
18+
$this->commands([
19+
Configure::class,
20+
]);
21+
22+
$this->publishes([
23+
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
24+
]);
25+
}
26+
}
27+
28+
public function provides()
29+
{
30+
return [
31+
Configure::class,
32+
];
33+
}
34+
}

src/Commands/Configure.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Codebuddyphp\Codebuddy\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Filesystem\Filesystem;
7+
use function Termwind\render;
8+
9+
class Configure extends Command
10+
{
11+
protected $signature = 'codebuddy:configure';
12+
13+
protected $description = 'Configure Rector, Larastan (PHPStan) & Pint';
14+
15+
public function handle(): void
16+
{
17+
$filesystem = new Filesystem();
18+
19+
$configs = [
20+
'rector.php',
21+
'phpstan.neon',
22+
'pint.json',
23+
];
24+
25+
foreach ($configs as $file) {
26+
$sourceFile = __DIR__ . "/../../config/laravel/{$file}";
27+
$destinationFile = base_path($file);
28+
29+
if (!$filesystem->exists($sourceFile)) {
30+
$this->error("Source file not found: {$sourceFile}");
31+
continue;
32+
}
33+
34+
if ($filesystem->exists($destinationFile)) {
35+
$overwrite = $this->confirmOverwrite($destinationFile);
36+
if (!$overwrite) {
37+
$this->warn("Skipped: {$destinationFile} already exists");
38+
continue;
39+
}
40+
}
41+
42+
$filesystem->copy($sourceFile, $destinationFile);
43+
$this->info("Copied: {$file} to project root");
44+
$this->newLine();
45+
}
46+
}
47+
48+
private function confirmOverwrite(string $file): bool
49+
{
50+
$this->info(
51+
sprintf('%s already exists. Do you want to overwrite it?', $file)
52+
);
53+
54+
return $this->ask('Overwrite?', false);
55+
}
56+
}

0 commit comments

Comments
 (0)