PHP code example of otatechie / laravel-spotlight

1. Go to this page and download the library: Download otatechie/laravel-spotlight library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

otatechie / laravel-spotlight example snippets


use Otatechie\Spotlight\Spotlight;

$spotlight = app(Spotlight::class);
$results = $spotlight->scan(['performance', 'security']);

// Access results
$summary = $results['summary'];
$categories = $results['categories'];



namespace App\Spotlight\Rules\Performance; // Category auto-detected from namespace!

use Otatechie\Spotlight\Rules\AbstractRule;

class MyCustomRule extends AbstractRule
{
    // Only define what's different - everything else is auto-detected!
    protected ?string $severity = 'medium'; // Or leave null for category-based default
    protected string $description = 'Checks for a specific issue';
    protected ?string $documentationUrl = 'https://example.com/docs/my-rule';
    
    // id: auto-generated as 'performance.my-custom'
    // category: auto-detected as 'performance' from namespace
    // name: auto-generated as 'My Custom' from class name
    // severity: defaults to 'medium' (performance category default)

    public function scan(): array
    {
        if ($issueFound) {
            return $this->suggest(
                'Issue description',
                ['recommendation' => 'How to fix it']
            );
        }

        return $this->pass('Everything looks good!');
    }
}

return [
    'custom_rules' => [
        \App\Spotlight\Rules\MyCustomRule::class,
    ],
];
bash
php artisan vendor:publish --tag="spotlight-config"
bash
php artisan spotlight:scan
bash
php artisan spotlight:scan --category=performance
bash
php artisan spotlight:scan --category=performance --category=security
bash
php artisan spotlight:scan --format=json
bash
php artisan spotlight:scan --severity=critical
bash
php artisan spotlight:rules
bash
php artisan spotlight:rules --rule=performance.config-cache
bash
php artisan spotlight:make-rule MyCustomRule --category=performance --type=objective
bash
php artisan vendor:publish --tag="spotlight-config"