Professional development environment for KaririCode Framework components
Fully automated installation, standardized tooling, and production-ready setup for PHP 8.4+ projects
- Overview
- Features
- Requirements
- Quick Start
- Usage
- Available Commands
- Configuration
- Best Practices
- Troubleshooting
- Contributing
- License
KaririCode DevKit é um ambiente de desenvolvimento profissional e padronizado para todos os componentes do KaririCode Framework. Ele fornece:
- Ambiente containerizado usando Docker com imagem centralizada
- Ferramentas de qualidade de código pré-configuradas (PHPStan, PHP CS Fixer, PHPMD)
- Makefile profissional com mais de 50 comandos úteis
- Configurações consistentes para garantir qualidade e manutenibilidade
- Integração CI/CD pronta para GitHub Actions
- ✅ SOLID - Segregação de responsabilidades e inversão de dependência
- ✅ Clean Code - Código limpo, legível e manutenível
- ✅ PSR Compliant - Segue PSR-4, PSR-12 e PSR-6/16
- ✅ Strong Typing - Tipagem forte em PHP 8.1+
- ✅ Test-Driven - Estrutura completa para TDD
- ✅ Performance-First - Otimizado para produção
- Usa imagem centralizada:
kariricode/php-api-stack - Redis 7 Alpine para caching
- Memcached 1.6 Alpine para caching distribuído
- Xdebug 3 para debugging (ativação sob demanda)
- Configuração otimizada para desenvolvimento
| Tool | Version | Purpose | Config File |
|---|---|---|---|
| PHPUnit | 11.4 | Unit & Integration Testing | phpunit.xml |
| PHPStan | 2.0 | Static Analysis (Level Max) | phpstan.neon |
| PHP CS Fixer | 3.64 | Code Style (PSR-12+) | .php-cs-fixer.php |
| PHPMD | 2.15 | Mess Detection | devkit/.config/phpmd/ruleset.xml |
| Rector | 1.2 | Automated Refactoring | rector.php |
| PHPBench | 1.3 | Performance Benchmarking | N/A |
- HTML Coverage Report - Visual coverage analysis
- Clover XML - For CI integration
- JUnit XML - For CI integration
- TestDox - Human-readable test documentation
- EditorConfig - Consistent formatting across editors
- PHPStorm/VSCode - Pre-configured settings
- Git Hooks - Pre-commit quality checks (optional)
- Docker >= 20.10
- Docker Compose >= 2.0
- Make (usually pre-installed on Unix systems)
- PHP >= 8.3
- Composer >= 2.5
- Redis (for cache testing)
- Memcached (for cache testing)
# Clone the DevKit
git clone https://github.com/KaririCode-Framework/kariricode-devkit.git my-component
cd my-component
# Remove DevKit Git history
rm -rf .git
# Initialize new repository
git init# Edit composer.json with your component information
nano composer.json
# Create directory structure
mkdir -p src tests/{Unit,Integration}# Starts containers, installs dependencies
make init# Access container shell
make shell
# Run tests
make test
# Check code quality
make check# 1. Start environment
make up
# 2. Install dependencies
make install
# 3. Develop and test continuously
make test # Run all tests
make test-filter FILTER=MyTest # Test specific
# 4. Check quality before commit
make qa # Fix code style + Run tests + Static analysis
# 5. Stop environment
make down# Recommended: run before each commit
make qa
# Or configure pre-commit hook (optional)
cat << 'EOF' > .git/hooks/pre-commit
#!/bin/bash
make qa || exit 1
EOF
chmod +x .git/hooks/pre-commitmake up # Start all containers
make down # Stop all containers
make restart # Restart containers
make status # Show container status
make logs # Show all logs
make logs-php # Show PHP container logs
make shell # Access PHP container shell
make shell-root # Access container as rootmake install # Install dependencies
make update # Update dependencies
make require PKG=vendor/package # Add package
make require-dev PKG=vendor/package # Add dev package
make autoload # Dump autoload
make validate # Validate composer.json
make outdated # Show outdated packagesmake test # Run all tests
make test-coverage # Generate HTML coverage
make test-coverage-text # Show coverage in terminal
make test-unit # Run unit tests only
make test-integration # Run integration tests
make test-filter FILTER=TestName # Run specific testmake cs-check # Check code style (dry-run)
make cs-fix # Fix code style
make analyse # Run PHPStan (level max)
make analyse-baseline # Generate PHPStan baseline
make phpmd # Run PHP Mess Detector
make rector # Run Rector (dry-run)
make rector-fix # Apply Rector changesmake check # Run CS check + PHPStan + PHPMD
make fix # Fix all auto-fixable issues
make qa # Complete pipeline: fix + test + checkmake security # Check for vulnerabilities (composer audit)make redis-cli # Access Redis CLI
make redis-flush # Flush Redis cache
make redis-info # Show Redis information
make memcached-stats # Show Memcached statistics
make memcached-flush # Flush Memcachedmake clean # Clean generated files
make reset # Clean + remove containers
make rebuild # Complete rebuild from scratch
make permissions # Fix file permissionsmake xdebug-on # Enable Xdebug
make xdebug-off # Disable Xdebug
make xdebug-status # Show Xdebug statusmake php-version # Show PHP version
make php-info # Show PHP configuration
make php-extensions # List PHP extensions
make composer-version # Show Composer version
make env # Show environment variablesmake ci # Simulate complete CI pipelinemake watch-tests # Watch and run tests on changes
make init # Initialize new component (up + install)Create a .env file in the project root (optional):
# Project name (affects container names)
COMPOSE_PROJECT_NAME=kariricode_cache
# Xdebug
XDEBUG_MODE=off
# Redis
REDIS_PORT=6379
# Memcached
MEMCACHED_PORT=11211Edit phpunit.xml to adjust:
- Test suites
- Coverage settings
- Environment variables
Edit phpstan.neon to:
- Adjust analysis level (not recommended to lower from
max) - Add excluded paths
- Ignore specific errors (use sparingly)
Edit .php-cs-fixer.php to:
- Customize style rules
- Add exceptions
Edit devkit/.config/phpmd/ruleset.xml to:
- Adjust complexity limits
- Disable specific rules
your-component/
├── devkit/ # DevKit files (do not commit to component)
│ └── .config/
│ ├── php/
│ │ ├── xdebug.ini
│ │ └── error-reporting.ini
│ └── phpmd/
│ └── ruleset.xml
├── src/ # Component source code
│ ├── Adapter/
│ ├── Contract/
│ ├── Exception/
│ └── ...
├── tests/ # Tests
│ ├── Unit/
│ ├── Integration/
│ └── bootstrap.php
├── .editorconfig
├── .gitignore
├── .php-cs-fixer.php
├── composer.json
├── docker-compose.yml
├── Makefile
├── phpstan.neon
├── phpunit.xml
├── README.md
└── LICENSE
<?php
declare(strict_types=1);
namespace KaririCode\Component;
final class Example
{
public function __construct(
private readonly string $name,
private readonly int $age
) {
}
public function getName(): string
{
return $this->name;
}
}// ✅ Good: Dependency Injection
public function __construct(
private readonly CacheInterface $cache
) {
}
// ❌ Bad: Direct instantiation
public function __construct()
{
$this->cache = new RedisCache();
}// tests/Unit/ExampleTest.php
final class ExampleTest extends TestCase
{
public function testItWorks(): void
{
$example = new Example('John', 30);
$this->assertSame('John', $example->getName());
}
}/**
* Processa dados usando estratégia de cache multinível.
*
* Este método implementa cache em camadas com fallback automático.
* Primeiro tenta L1 (memória), depois L2 (Redis), e finalmente
* busca da fonte original.
*
* Performance characteristics:
* - Time complexity: O(1) para cache hit
* - Space complexity: O(n) onde n é o tamanho dos dados
*
* @param array<string, mixed> $data Dados a processar
* @param positive-int $ttl Tempo de vida em segundos
*
* @return array<string, mixed> Dados processados e cacheados
*
* @throws CacheException Se cache falhar
* @throws InvalidArgumentException Se dados inválidos
*
* @example
* ```php
* $result = $cache->process(['key' => 'value'], 3600);
* ```
*
* @see https://kariricode.org/docs/cache/multilayer
* @since 1.0.0
*/
public function process(array $data, int $ttl): array
{
// Implementation
}Padrão de Documentação:
- ✅ Descrição clara e concisa
- ✅ Explicação detalhada quando necessário
- ✅ Performance characteristics (opcional)
- ✅ Todos os @param com tipos precisos
- ✅ @return com tipo de retorno
- ✅ @throws para todas as exceções
- ✅ @example com código funcional
- ✅ @see para referências externas
- ✅ @since para versionamento
PHP CS Fixer está configurado para MANTER toda a documentação!
Diferente de configurações padrão, nossa setup preserva @author, @package,
@category, e todos os outros tags importantes.
# Antes de cada commit
make qa
# Durante desenvolvimento
make test-filter FILTER=MyNewFeature# Check if ports are in use
docker ps -a
# Remove old containers
make clean
docker system prune -a
# Rebuild
make rebuild# Fix permissions
make permissions
# Or manually
docker-compose exec -u root php chown -R app:app /var/www# Clear Composer cache
docker-compose exec php composer clear-cache
# Reinstall
make clean
make install# Check if enabled
make xdebug-status
# Enable
make xdebug-on
# Configure IDE for port 9003
# host: localhost
# port: 9003# Simulate CI environment
make ci
# Check environment differences
docker-compose exec php php -v
docker-compose exec php php -m# View all logs
make logs
# Specific logs
make logs-php
# Access shell for debugging
make shellContributions are welcome! To contribute:
- Fork the repository
- Create a branch for your feature (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow SOLID principles and Clean Code
- Maintain test coverage >= 80%
- Run
make qabefore committing - Document changes in README if necessary
- Use Conventional Commits
This project is licensed under the MIT License. See the LICENSE file for details.
- KaririCode Framework: https://kariricode.org
- Documentation: https://kariricode.org/docs
- GitHub Organization: https://github.com/KaririCode-Framework
- Packagist: https://packagist.org/packages/kariricode/
- Walmir Silva - walmir.silva@kariricode.org
- PHP-FIG for PSR standards
- Symfony Cache Component for inspiration
- Docker community for containerization best practices
- All contributors to the KaririCode Framework
Built with ❤️ by the KaririCode Team
Empowering developers to build robust, maintainable, and professional PHP applications