Contributing Guide
We welcome contributions to Laravel Spectrum! This guide explains how to contribute to the project.
๐ค Ways to Contributeโ
Areas You Can Contribute Toโ
- ๐ Bug Fixes - Fix known issues
- โจ New Features - Propose and implement new features
- ๐ Documentation - Improve documentation or translations
- ๐งช Testing - Improve test coverage
- ๐จ Refactoring - Improve code quality
- ๐ Translation - Multilingual support
๐ Setting Up Development Environmentโ
1. Fork the Repositoryโ
# After forking on GitHub
git clone https://github.com/YOUR_USERNAME/laravel-spectrum.git
cd laravel-spectrum
2. Install Dependenciesโ
composer install
npm install
3. Configure Test Environmentโ
# Create .env file for testing
cp .env.testing.example .env.testing
# Set up test DB (using SQLite)
touch database/testing.sqlite
4. Set Up pre-commit Hooksโ
# Install Husky
npm run prepare
# Or manually set up Git hooks
cp .github/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
๐ Coding Standardsโ
PHP Coding Standardsโ
Laravel Spectrum follows PSR-12.
<?php
namespace LaravelSpectrum\Analyzers;
use Illuminate\Support\Collection;
use LaravelSpectrum\Contracts\Analyzer;
class ExampleAnalyzer implements Analyzer
{
/**
* Constructor dependency injection
*/
public function __construct(
private readonly Collection $config,
private readonly LoggerInterface $logger
) {
}
/**
* Execute analysis
*
* @param mixed $target Analysis target
* @return array Analysis results
* @throws AnalysisException
*/
public function analyze($target): array
{
try {
// Implementation
return $this->performAnalysis($target);
} catch (\Exception $e) {
$this->logger->error('Analysis failed', [
'target' => $target,
'error' => $e->getMessage(),
]);
throw new AnalysisException(
'Failed to analyze target',
previous: $e
);
}
}
}
Automatic Code Style Fixesโ
# Using Laravel Pint
composer format
# Or specific files only
vendor/bin/pint path/to/file.php
# Dry run (check changes)
vendor/bin/pint --test
Static Analysisโ
# Run PHPStan
composer analyze
# Specify level
vendor/bin/phpstan analyze --level=8
๐งช Writing Testsโ
Unit Testsโ
namespace LaravelSpectrum\Tests\Unit\Analyzers;
use LaravelSpectrum\Analyzers\ExampleAnalyzer;
use LaravelSpectrum\Tests\TestCase;
class ExampleAnalyzerTest extends TestCase
{
private ExampleAnalyzer $analyzer;
protected function setUp(): void
{
parent::setUp();
$this->analyzer = new ExampleAnalyzer();
}
/** @test */
public function it_analyzes_simple_case(): void
{
// Arrange
$input = ['key' => 'value'];
// Act
$result = $this->analyzer->analyze($input);
// Assert
$this->assertArrayHasKey('processed', $result);
$this->assertEquals('value', $result['processed']['key']);
}
/** @test */
public function it_throws_exception_for_invalid_input(): void
{
$this->expectException(AnalysisException::class);
$this->expectExceptionMessage('Invalid input');
$this->analyzer->analyze(null);
}
}
Feature Testsโ
namespace LaravelSpectrum\Tests\Feature;
use LaravelSpectrum\Tests\TestCase;
class DocumentGenerationTest extends TestCase
{
/** @test */
public function it_generates_documentation_for_simple_api(): void
{
// Define route
Route::get('/api/test', fn() => ['status' => 'ok']);
// Execute command
$this->artisan('spectrum:generate')
->assertExitCode(0)
->assertSee('Documentation generated successfully');
// Check generated file
$this->assertFileExists(storage_path('app/spectrum/openapi.json'));
$openapi = json_decode(
file_get_contents(storage_path('app/spectrum/openapi.json')),
true
);
$this->assertArrayHasKey('/api/test', $openapi['paths']);
}
}
Running Testsโ
# Run all tests
composer test
# Run specific test
composer test -- --filter=ExampleAnalyzerTest
# With coverage report
composer test-coverage
๐ Pull Request Processโ
1. Create a Branchโ
# Feature addition
git checkout -b feature/amazing-feature
# Bug fix
git checkout -b fix/issue-123
# Documentation
git checkout -b docs/improve-readme
2. Commit Messagesโ
Follow Conventional Commits:
# Feature addition
git commit -m "feat: add support for GraphQL schema generation"
# Bug fix
git commit -m "fix: correctly detect nested array validation rules"
# Documentation
git commit -m "docs: add Japanese translation"
# Breaking change
git commit -m "feat!: change default output format to YAML
BREAKING CHANGE: The default output format has been changed from JSON to YAML."
3. Pull Request Templateโ
## Summary
Brief description of the problem this PR solves or the feature it adds
## Changes
- [ ] Specific change 1
- [ ] Specific change 2
## Tests
- [ ] Added/updated unit tests
- [ ] Added/updated feature tests
- [ ] Manually tested
## Related Issues
Fixes #123
## Screenshots (if UI changes)
Before and after screenshots
## Checklist
- [ ] Follows code style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes (or clearly documented if present)
4. Review Processโ
- Automated Checks - CI/CD runs automatically
- Code Review - Maintainers review the code
- Feedback - Make corrections as needed
- Merge - Merged after approval
๐ Contributor License Agreement (CLA)โ
You will need to agree to the CLA on your first contribution. This is handled automatically.
๐๏ธ Project Structureโ
laravel-spectrum/
โโโ src/
โ โโโ Analyzers/ # Code analysis classes
โ โโโ Cache/ # Cache related
โ โโโ Console/ # Artisan commands
โ โโโ Contracts/ # Interfaces
โ โโโ Events/ # Event classes
โ โโโ Exceptions/ # Exception classes
โ โโโ Exporters/ # Export functionality
โ โโโ Facades/ # Laravel facades
โ โโโ Formatters/ # Formatters
โ โโโ Generators/ # Generators
โ โโโ MockServer/ # Mock server
โ โโโ Services/ # Service classes
โ โโโ Support/ # Helper classes
โโโ tests/
โ โโโ Unit/ # Unit tests
โ โโโ Feature/ # Feature tests
โ โโโ Fixtures/ # Test fixtures
โโโ config/ # Configuration files
โโโ docs/ # Documentation
๐ฏ Focus Areasโ
We are currently seeking contributions in the following areas:
1. Performance Improvementsโ
- Optimization for large projects
- Memory usage reduction
- Parallel processing improvements
2. New Featuresโ
- GraphQL support
- gRPC support
- WebSocket API support
3. Ecosystemโ
- IDE extensions
- CI tool integrations
- Porting to other frameworks
๐ Translationโ
Adding a New Languageโ
- Create
resources/lang/{locale}
directory - Copy and translate existing language files
- Translate documentation (
docs/{locale}/
)
Translation Guidelinesโ
- Don't force translation of technical terms
- Prioritize readability
- Accurately convey the original intent
๐ Communicationโ
GitHub Issuesโ
- Bug reports
- Feature requests
- Questions
GitHub Discussionsโ
- Idea discussions
- RFCs (Request for Comments)
- Community support
Otherโ
- Twitter: @LaravelSpectrum
- Email: contribute@laravel-spectrum.dev
๐ Contributorsโ
Contributors are listed in README.md.
๐ Licenseโ
Contributed code is released under the same MIT license as the project.
Thank you! Your contributions make Laravel Spectrum better. ๐