talhag3/string-analyzer

A simple PHP package that analyzes string composition

Maintainers

Package info

github.com/talhag3/string-analyzer

pkg:composer/talhag3/string-analyzer

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-05-28 16:38 UTC

This package is auto-updated.

Last update: 2026-05-28 16:39:58 UTC


README

CI Latest Stable Version Total Downloads

๐Ÿ“ 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 run docker compose commands 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-coverage and open coverage/index.html in your browser.

๐Ÿ› Debugging with VS Code

  1. Install the PHP Debug extension by felixfbecker
  2. Open the Debug panel (Ctrl+Shift+D), select Docker: Listen for Xdebug, and click โ–ถ๏ธ
  3. Set a breakpoint in src/StringAnalyzer.php
  4. Run make test in the terminal
  5. 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 image
  • docker-compose.yml โ†’ Orchestrates the container, mounts your code live (volumes), and configures Xdebug routing
  • make commands โ†’ Wrap long docker compose run ... calls for convenience

๐Ÿ”‘ Key Concept: Code changes sync instantly via volumes. You only rebuild (make build) when modifying the Dockerfile or 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.json work
  • Writing & running PHPUnit tests
  • Configuring Xdebug for CLI debugging & coverage
  • Containerizing PHP apps without local dependency conflicts
  • Automating tests with GitHub Actions
  • Using volumes vs COPY in Docker (dev vs prod)

๐Ÿ“„ License

MIT License. Free to use, modify, and learn from.