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.
- PHP 8.1+ (built and tested on 8.3)
- Composer
composer installphp bin/console app:process recruitment-task-source.json --out-dir=./out--out-dir defaults to ./out. Three files are written:
inspections.json- inspection entitiesfailure_reports.json- failure report entitiesfailed_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.
vendor/bin/phpunitdocker-compose run --rm processorOnly 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.
- The task uses Polish keywords (
przegląd,pilne,bardzo pilne) but the sample data is English, so the rules match both:przeglądorinspectionfor inspections;bardzo pilne/very urgentfor critical priority,pilne/urgentfor high. Matching is case-insensitive. dueDateis matched against a fixed list of formats (date, date + time, ISO 8601). I avoidnew DateTimeImmutable($value)because it also accepts strings like "tomorrow". Anything that does not match is treated as no date.weekOfYearis the ISO-8601 week number.- A message with no description is written to
failed_messages.json. An empty or unparsabledueDateis not a failure; the date is left empty and the status is set tonew. - Duplicates are matched on the trimmed, lower-cased description. The first one wins.
clientPhoneis 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 inclientPhoneOriginal.createdAtis the time the entity was produced, set through an injected clock so the tests stay deterministic.
src/Command- theapp:processcommandsrc/IO- JSON reader (json-machine) and writersrc/Processor- classifier, duplicate checker, phone normalizer, mappers andMessageProcessorsrc/Support-DateParserandClocksrc/Entity-InspectionandFailureReport
Services are wired in bin/console. Adding a new entity type means a new entity,
a mapper, and a branch in the classifier.