Skip to main content

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โ€‹

  1. Automated Checks - CI/CD runs automatically
  2. Code Review - Maintainers review the code
  3. Feedback - Make corrections as needed
  4. 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โ€‹

  1. Create resources/lang/{locale} directory
  2. Copy and translate existing language files
  3. 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โ€‹

๐Ÿ† 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. ๐ŸŽ‰