sudo apt update sudo apt upgrade -y
sudo add-apt-repository ppa:ondrej/php -y sudo apt install php8.3-cli php8.3-fpm php8.3-mbstring php8.3-xml php8.3-curl php8.3-pgsql php8.3-sqlite3 php8.3-redis php8.3-bcmath php8.3-zip php8.3-intl
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
sudo apt install nginx
sudo apt install postgresql postgresql-contrib # или mysql-server, или sqlite3
cd /var/www git clone sweebe-api cd sweebe-api cp .env.example .env
composer install --no-dev --optimize-autoloader php artisan key:generate php artisan jwt:secret
sudo chown -R www-data:www-data storage bootstrap/cache sudo chmod -R 775 storage bootstrap/cache
server { listen 80; server_name api.your-domain.com; root /var/www/sweebe-api/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/sweebe-api /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx
sudo apt install supervisor sudo nano /etc/supervisor/conf.d/sweebe-queue.conf
[program:sweebe-queue] process_name=%(program_name)s_%(process_num)02d command=php /var/www/sweebe-api/artisan queue:work --sleep=3 --tries=3 --max-time=3600 autostart=true autorestart=true stopasgroup=true killasgroup=true user=www-data numprocs=1 redirect_stderr=true stdout_logfile=/var/www/sweebe-api/storage/logs/queue.log stopwaitsecs=3600
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start sweebe-queue:*
-
-
-
-
- cd /var/www/sweebe-api && php artisan schedule:run >> /dev/null 2>&1
-
-
-
sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d api.your-domain.com
// Примеры использования $person = Person::with(['tags', 'meetings', 'notes'])->find(1); $meeting = Meeting::where('date', today())->first(); $tags = Tag::ofGroup('category')->orderByTitle()->get();
php artisan key:generate php artisan jwt:secret
vendor/bin/phpstan analyse --level=8 --generate-baseline | grep -oE "[0-9]+%"
vendor/bin/phpstan analyse app/Http/Controllers/ --level=max
vendor/bin/phpstan analyse --error-format=json > phpstan-report.json
- Дополнительные инструменты Для расширенного анализа:
bash composer require phpstan/phpstan-strict-rules --dev composer require phpstan/phpstan-deprecation-rules --dev 7. Конфигурация с strict rules phpstan.neon:
neon includes: - ./vendor/nunomaduro/larastan/extension.neon - ./vendor/phpstan/phpstan-strict-rules/rules.neon - ./vendor/phpstan/phpstan-deprecation-rules/rules.neon
parameters: level: 7 checkMissingIterableValueType: true checkGenericClassInNonGenericObjectType: true reportUnmatchedIgnoredErrors: false
Быстрый анализ (скорость + базовая информация)
vendor/bin/psalm --no-cache --threads=4 --stats --output-format=console --find-dead-code- Детальный анализ (больше информации)
vendor/bin/psalm --show-info=true --stats --output-format=console --no-progress --report=psalm-report.json- Для CI/CD (компактный вывод)
vendor/bin/psalm --show-info=true --stats --output-format=github --no-cache --threads=2- Установи плагин для Laravel (существенно улучшает анализ)
composer require --dev psalm/plugin-laravel
./vendor/bin/psalm-plugin enable psalm/plugin-laravel- Мой рекомендованный вариант
./vendor/bin/psalm --stats --output-format=console --no-cache --threads=4 --find-unused-code-
Полезные флаги: --threads=4 - использовать 4 ядра процессора --no-cache - отключить кеш (актуально в CI) --no-progress - убрать индикатор прогресса --find-dead-code - поиск неиспользуемого кода --set-baseline=file.xml - создать базовую линию ошибок
-
Для самого быстрого анализа:
./vendor/bin/psalm --no-cache --threads=$(nproc) --output-format=console --stats 2>/dev/null./vendor/bin/psalm --stats --output-format=console --threads=4 --find-dead-code --no-progressvendor/bin/rector process
vendor/bin/rector process --no-ansi
vendor/bin/rector process --output-format=json
vendor/bin/rector process --output-format=github
vendor/bin/rector process --output-format=files
php artisan test --group=post
php artisan test --group=post --group=crud
php artisan test --exclude-group=slow
php artisan test --group=post --verbose
php artisan test --list-groups
🎯 Требования к тестам для Laravel проекта
- 📁 Структура и организация Расположение: Все тесты в директории tests/
tests/Unit/ - для юнит-тестов (Модели, Сервисы, Джобы, Реквесты).
tests/Feature/ - для функциональных тестов (Контроллеры, API-роуты, Команды).
tests/Integration/ - для интеграционных тестов (взаимодействие с внешними сервисами, опционально).
Именование файлов: Соответствует именам классов. {ModelName}Test.php, {ServiceName}Test.php, {ControllerName}Test.php.
Именование классов: Соответствует именам файлов. class UserTest extends TestCase.
Именование методов: На русском языке, в формате [субъект][действие]условия_результат. Допускается использование префикса test_ или атрибута #[Test] (предпочтительно).