arm-cm / task-memory
Manage a task list in memory
v1.0.1
2026-08-10 22:42 UTC
Requires
- php: ^8.3
Requires (Dev)
- phpunit/phpunit: ^12.0
README
An in-memory library to create tasks and query them by attribute. No framework, no database.
Requirements
- PHP 8.3+
Installation
You can install the package via composer:
composer require armcm/task-memory
Usage
Install the package in your project:
mkdir demo-task-app cd demo-task-app composer init # Follow prompts composer require arm-cm/task-memory
Create file index php
demo-task-app/
├── vendor/
├── composer.json
└── index.php
Index.php
<?php require 'vendor/autoload.php'; use ArmCm\TaskMemory\Task; use ArmCm\TaskMemory\TaskCollection; $task = new Task('Write demo', 'Create a usage example'); $collection = new TaskCollection(); $collection->add($task); print_r($collection->toArray()); echo $collection->toJson();
Run script
php index.php
API Reference
Methods that can be used in Task class
use ArmCm\TaskMemory\Task; $task = new Task('Title', 'Description'); $task->complete(); $task->start(); $task->currentStatus() $task->update('New title', 'New description'); $task->update('New title');
Methods that can be used in TaskCollection class
use ArmCm\TaskMemory\TaskCollection; $collection = new TaskCollection(); $collection->add(Task|array $tasks) — Adds one or more Task objects to the collection $collection->all(): array — Returns all tasks as an array of Task objects $collection->count(): int — Returns the total number of tasks in the collection $collection->findBy(string $attribute, string|int $value): array — Returns all tasks that match the given parameters $collection->toArray(): array — Converts the task collection to an associative array $collection->toJson(): string — Converts the task collection to a JSON string
Design decisions
I deliberately renamed part of the API described in the brief. Each change was a considered choice, not an oversight:
| The brief asked for | Shipped | Rationale |
|---|---|---|
TaskManager |
TaskCollection |
"Manager" is an agent noun: it names behavior, not identity. The class is a container of tasks, so Collection names the concept directly. |
addTask(), getAllTasks() |
add(), all() |
The Task suffix is redundant — the type already lives in the receiver ($tasks->add(...)). |
markDone(), markInProgress() |
complete(), start() |
mark is noise; the verb alone expresses the state transition. |
getTasksByStatus() + findTaskById() |
findBy() + findById() |
Split by cardinality: findBy for multi-match lookups (returns array), findById for the unique-by-id lookup (returns ?Task, honoring the original contract). |
__toString() |
__toString() + toArray()/toJson() |
__toString() gives a human-readable line for logs/debug; toArray()/toJson() are the structured serialization surface. |
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.