<?php
class Container {
private $data = [];
public function add(string $name, int $count) {
if (isset($this->data[$name])) {
$this->data[$name] += $count;
} else {
$this->data[$name] = $count;
}
}
public function remove(string $name) {
if (!isset($this->data[$name])) {
return;
}
unset($this->data[$name]);
}
}
class CollectStatistics {
// TODO: ...
// Do not hardcore methods from above (add, remove) use magical methods instead.
}
// Do not modify code bellow this line.
// Expected output, utilize var_dump:
// array(2) {
// ["add"]=>
// int(3)
// ["remove"]=>
// int(1)
// }
// Basic version.
$instance = CollectStatistics::wrap(new Container());
$instance->add('tomato', 1);
$instance->add('tomato', 1);
$instance->add('orange', 1);
$instance->remove('bread');
$instance->printStatistics();