Skip to content

Latest commit

 

History

146 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sudo apt update sudo apt upgrade -y

PHP 8.3 (или 8.4, если нужно)

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

Composer

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Nginx (или Apache)

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

Отредактируйте .env: APP_ENV=production, APP_DEBUG=false, DB_*, JWT_SECRET=...

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

  1. Дополнительные инструменты Для расширенного анализа:

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
  1. Детальный анализ (больше информации)
vendor/bin/psalm --show-info=true --stats --output-format=console --no-progress --report=psalm-report.json
  1. Для CI/CD (компактный вывод)
vendor/bin/psalm --show-info=true --stats --output-format=github --no-cache --threads=2
  1. Установи плагин для Laravel (существенно улучшает анализ)
composer require --dev psalm/plugin-laravel
./vendor/bin/psalm-plugin enable psalm/plugin-laravel
  1. Мой рекомендованный вариант
./vendor/bin/psalm --stats --output-format=console --no-cache --threads=4 --find-unused-code
  1. Полезные флаги: --threads=4 - использовать 4 ядра процессора --no-cache - отключить кеш (актуально в CI) --no-progress - убрать индикатор прогресса --find-dead-code - поиск неиспользуемого кода --set-baseline=file.xml - создать базовую линию ошибок

  2. Для самого быстрого анализа:

./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-progress

Стандартный вывод (цветной)

vendor/bin/rector process

Без цветов (для CI)

vendor/bin/rector process --no-ansi

JSON вывод

vendor/bin/rector process --output-format=json

GitHub Actions формат

vendor/bin/rector process --output-format=github

Только имена файлов

vendor/bin/rector process --output-format=files

Запуск всех тестов группы "post"

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 проекта

  1. 📁 Структура и организация Расположение: Все тесты в директории tests/

tests/Unit/ - для юнит-тестов (Модели, Сервисы, Джобы, Реквесты).

tests/Feature/ - для функциональных тестов (Контроллеры, API-роуты, Команды).

tests/Integration/ - для интеграционных тестов (взаимодействие с внешними сервисами, опционально).

Именование файлов: Соответствует именам классов. {ModelName}Test.php, {ServiceName}Test.php, {ControllerName}Test.php.

Именование классов: Соответствует именам файлов. class UserTest extends TestCase.

Именование методов: На русском языке, в формате [субъект][действие]условия_результат. Допускается использование префикса test_ или атрибута #[Test] (предпочтительно).

About

API Нокиа на Laravel

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages