Skip to content

About

PHP 8.3 CLI that streams a JSON file and classifies messages into inspections and failure reports. Symfony Console, PHPUnit, Docker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Message Processor CLI

Reads a list of messages from a JSON file, classifies each one as an inspection or a failure report, and writes the results back out as JSON.

Requirements

  • PHP 8.1+ (built and tested on 8.3)
  • Composer
composer install

Usage

php bin/console app:process recruitment-task-source.json --out-dir=./out

--out-dir defaults to ./out. Three files are written:

  • inspections.json - inspection entities
  • failure_reports.json - failure report entities
  • failed_messages.json - messages that could not be processed

A failed entry is { "message": <object>, "error": <reason> }. message holds the original message, or {} when the input was not an object, so every entry has the same shape.

The command prints a summary at the end: total processed, inspections, failure reports, duplicates skipped, and messages not processed.

Tests

vendor/bin/phpunit

Docker

docker-compose run --rm processor

Only out/ is mounted back to the host. Mounting the whole project would hide the vendor/ installed in the image and break the autoloader on a fresh checkout.

Notes

  • The task uses Polish keywords (przegląd, pilne, bardzo pilne) but the sample data is English, so the rules match both: przegląd or inspection for inspections; bardzo pilne / very urgent for critical priority, pilne / urgent for high. Matching is case-insensitive.
  • dueDate is matched against a fixed list of formats (date, date + time, ISO 8601). I avoid new DateTimeImmutable($value) because it also accepts strings like "tomorrow". Anything that does not match is treated as no date.
  • weekOfYear is the ISO-8601 week number.
  • A message with no description is written to failed_messages.json. An empty or unparsable dueDate is not a failure; the date is left empty and the status is set to new.
  • Duplicates are matched on the trimmed, lower-cased description. The first one wins.
  • clientPhone is reduced to digits, dropping separators and a leading +. Values with fewer than 7 digits are treated as noise and left empty. The raw input is kept in clientPhoneOriginal.
  • createdAt is the time the entity was produced, set through an injected clock so the tests stay deterministic.

Structure

  • src/Command - the app:process command
  • src/IO - JSON reader (json-machine) and writer
  • src/Processor - classifier, duplicate checker, phone normalizer, mappers and MessageProcessor
  • src/Support - DateParser and Clock
  • src/Entity - Inspection and FailureReport

Services are wired in bin/console. Adding a new entity type means a new entity, a mapper, and a branch in the classifier.

About

PHP 8.3 CLI that streams a JSON file and classifies messages into inspections and failure reports. Symfony Console, PHPUnit, Docker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages