-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirus.php
More file actions
30 lines (26 loc) · 872 Bytes
/
Copy pathVirus.php
File metadata and controls
30 lines (26 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
class Virus {
public array $children = [];
public function __construct(
public float $weight,
public int $age,
public string $name,
public string $type
) {}
public function addChild(Virus $virus): void {
$this->children[] = $virus;
}
public function __clone() {
foreach ($this->children as $key => $child) {
$this->children[$key] = clone $child;
}
}
public function getTreeHtml(int $level = 0): string {
$indent = str_repeat(" ", $level);
$html = "{$indent}🦠 <strong>{$this->name}</strong> [Вид: {$this->type}, Вага: {$this->weight} мг, Вік: {$this->age} год]<br>";
foreach ($this->children as $child) {
$html .= $child->getTreeHtml($level + 1);
}
return $html;
}
}