You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhpCollections/tests/test_class.php

39 lines
930 B
PHP

<?php
/** @noinspection PhpIllegalPsrClassPathInspection */
use jrosset\Collections\Collection;
require_once __DIR__ . '/../vendor/autoload.php';
class Measure {
private int $value;
private string $unit;
public function __construct (int $value, string $unit = 's') {
$this->value = $value;
$this->unit = $unit;
}
public function asString (): string {
return $this->value . $this->unit;
}
}
/**
* @return Collection<int, Measure>
*/
function getMeasures (): Collection {
$mesures_avant = new Collection();
$mesures_avant->add(new Measure(38), new Measure(29));
$measures = new Collection();
$measures->add(new Measure(27), new Measure(34));
$measures->prependCollection($mesures_avant);
return $measures;
}
echo 'Measures :' . PHP_EOL;
foreach (getMeasures() as $no => $measure) {
echo "\t#" . $no . ' = ' . $measure->asString() . PHP_EOL;
}