talhag3 / string-analyzer
A simple PHP package that analyzes string composition
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2026-05-28 16:39:58 UTC
README
๐ String Analyzer
A minimal PHP library that analyzes a given string and returns counts for characters, words, spaces, and special characters.
Built as a hands-on learning project to master modern PHP development workflows: Docker, PHPUnit, Xdebug, GitHub Actions, and CI/CD.
๐ Quick Start
# 1. Clone the repository git clone <your-repo-url> cd string-analyzer # 2. Build the Docker environment make build # 3. Run tests make test
๐ฆ Features
- โ
Single, pure method:
analyze(string $text): array - โ
UTF-8 safe (
mb_*&preg_*functions) - โ PHPUnit test suite with assertions
- โ Xdebug integration for step-debugging & code coverage
- โ Fully containerized with Docker & Docker Compose
- โ Automated CI via GitHub Actions
๐ ๏ธ Prerequisites
- Docker & Docker Compose
make(pre-installed on macOS/Linux; Windows users can rundocker composecommands directly)- VS Code + PHP Debug Extension (for debugging)
๐งช Testing & Coverage
| Command | Description |
|---|---|
make test |
Run PHPUnit tests in an isolated container |
make test-coverage |
Generate HTML coverage report in coverage/ |
make shell |
Drop into an interactive container shell |
๐ก Code coverage requires Xdebug. Run
make test-coverageand opencoverage/index.htmlin your browser.
๐ Debugging with VS Code
- Install the PHP Debug extension by
felixfbecker - Open the Debug panel (
Ctrl+Shift+D), select Docker: Listen for Xdebug, and click โถ๏ธ - Set a breakpoint in
src/StringAnalyzer.php - Run
make testin the terminal - VS Code will pause at your breakpoint. Step, inspect variables, and continue.
Configuration is pre-loaded in .vscode/launch.json and Dockerfile.
๐ณ Docker Explained (Learning Focus)
This project uses Docker to guarantee a consistent, reproducible environment across machines and CI.
Dockerfileโ Bakes PHP 8.2 + extensions (Xdebug, intl, mbstring, Composer) into an imagedocker-compose.ymlโ Orchestrates the container, mounts your code live (volumes), and configures Xdebug routingmakecommands โ Wrap longdocker compose run ...calls for convenience
๐ Key Concept: Code changes sync instantly via
volumes. You only rebuild (make build) when modifying theDockerfileor PHP extensions.
๐ GitHub Actions CI
Pushing to main or opening a PR automatically triggers:
- โ PHP 8.2 setup with Xdebug
- โ Dependency installation
- โ PHPUnit execution with coverage
- โ Coverage artifact upload
Workflow file: .github/workflows/ci.yml
๐ Project Structure
string-analyzer/
โโโ src/
โ โโโ StringAnalyzer.php # Core logic
โโโ tests/
โ โโโ StringAnalyzerTest.php # PHPUnit tests
โโโ .github/workflows/ci.yml # GitHub Actions CI
โโโ .vscode/launch.json # VS Code debug config
โโโ Dockerfile # PHP environment + Xdebug
โโโ docker-compose.yml # Container orchestration
โโโ Makefile # Developer shortcuts
โโโ composer.json # Dependencies & autoloading
โโโ phpunit.xml # Test configuration
๐ Learning Objectives
This project demonstrates:
- How Composer autoloading &
composer.jsonwork - Writing & running PHPUnit tests
- Configuring Xdebug for CLI debugging & coverage
- Containerizing PHP apps without local dependency conflicts
- Automating tests with GitHub Actions
- Using
volumesvsCOPYin Docker (dev vs prod)
๐ License
MIT License. Free to use, modify, and learn from.