trip-planner/bin/phpstan
2025-09-28 00:39:30 +02:00

51 lines
No EOL
1.5 KiB
Bash
Executable file

#!/bin/bash
# PHPStan runner script for Docker environment
# Usage: ./bin/phpstan [options]
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get the directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
# Change to project root
cd "$PROJECT_ROOT"
# Check if docker compose is running
if ! docker compose -f docker-compose.dev.yml ps --services --filter "status=running" | grep -q "backend"; then
echo -e "${RED}Error: Backend container is not running${NC}"
echo -e "${YELLOW}Starting containers...${NC}"
docker compose -f docker-compose.dev.yml up -d
# Wait a moment for containers to be ready
sleep 3
fi
# Run PHPStan with default memory limit if not specified
echo -e "${GREEN}Running PHPStan analysis...${NC}"
# Pass all arguments to phpstan, with default memory limit
if [[ "$*" == *"--memory-limit"* ]]; then
# User specified memory limit, use their arguments
docker compose -f docker-compose.dev.yml exec backend vendor/bin/phpstan analyse "$@"
else
# Add default memory limit
docker compose -f docker-compose.dev.yml exec backend vendor/bin/phpstan analyse --memory-limit=256M "$@"
fi
# Capture exit code
EXIT_CODE=$?
# Display result
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}✓ PHPStan analysis completed successfully${NC}"
else
echo -e "${RED}✗ PHPStan found issues${NC}"
fi
exit $EXIT_CODE