- How do I install the StyleCI SDK in a Laravel project?
- Run `composer require styleci/sdk:^1.5` in your project directory. The SDK requires PHP 7.2.5+ and works with Laravel 9/10. After installation, bind the SDK to Laravel’s service container in a provider (e.g., `AppServiceProvider`) for dependency injection.
- Is this SDK still maintained? What if StyleCI’s API changes?
- The SDK was last updated in 2021 and is no longer actively maintained. If StyleCI’s API evolves, the SDK may break. Test endpoints like `/api/v1/checker` and `/api/v1/fixer` manually to verify compatibility. Consider forking or replacing it with direct Guzzle HTTP calls if issues arise.
- Can I use this SDK in CI/CD pipelines like GitHub Actions?
- Yes. Create an Artisan command (e.g., `styleci:fix`) to trigger fixes, then call it in your CI workflow. Example: `php artisan styleci:fix`. Schedule checks via Laravel’s scheduler or run them on every push to enforce standards automatically.
- How do I authenticate with StyleCI’s API using this SDK?
- Store your StyleCI API token in Laravel’s `.env` (e.g., `STYLECI_TOKEN=your_token_here`). Pass it to the SDK’s constructor when binding it to the container. Avoid hardcoding tokens; use Laravel’s config or environment variables for security.
- What Laravel versions does this SDK support?
- The SDK supports PHP 7.4+ and is compatible with Laravel 9 and 10. Test thoroughly in your environment, especially if using newer Laravel features like model observers or queues, which may interact with the SDK’s API calls.
- How can I trigger a code style fix programmatically in Laravel?
- Inject the SDK into a service or command, then call methods like `$styleci->fixer()->fix()`. Example: `php artisan styleci:fix` or trigger via an event listener (e.g., after a git commit). Wrap calls in try-catch blocks to handle API errors gracefully.
- Are there alternatives if this SDK doesn’t work for my project?
- If the SDK is unstable, use Guzzle HTTP client to call StyleCI’s API directly. Example: `$client->post('https://api.styleci.io/v1/fixer', ['auth' => [token, '']])`. For audit trails, consider `spatie/laravel-activitylog`, though it’s unrelated to StyleCI.
- How do I handle rate limits or failed API requests from StyleCI?
- Implement retry logic with exponential backoff for failed requests. Cache responses (e.g., using Laravel’s cache) to reduce API calls. Log errors via Laravel’s logging system (e.g., `Log::error($e->getMessage())`) for debugging.
- Can I use this SDK to check code style before commits or deployments?
- Yes. Create an Artisan command or event listener to run StyleCI checks on `git:commit` or `deploy` events. Example: `Event::listen(Deployed::class, function () { app(StyleCI::class)->checker()->check(); })`. Integrate with Laravel’s task scheduler for periodic checks.
- How do I test my Laravel app’s integration with the StyleCI SDK?
- Mock the SDK’s API responses in PHPUnit/Pest tests. Example: `StyleCI::shouldReceive('fix')->andReturn(new FixResult())`. Test edge cases like failed requests, rate limits, and invalid tokens. Verify Artisan commands and event listeners behave as expected in isolation.