25 lines
575 B
PHP
25 lines
575 B
PHP
<?php
|
|
|
|
class Tree
|
|
{
|
|
public $height;
|
|
|
|
|
|
public function __construct(int $height)
|
|
{
|
|
if ($height <= 3) {
|
|
throw new InvalidArgumentException("Your christmas tree is too small, try again!");
|
|
}
|
|
$this->height = $height;
|
|
}
|
|
|
|
public function drawTree(): void
|
|
{
|
|
$width = 2 * $this->height - 1;
|
|
for ($i = 1; $i <= $this->height; $i++) {
|
|
$stars = 2 * $i - 1;
|
|
$spaces = ($width - $stars);
|
|
echo str_repeat(" ", $spaces) . str_repeat("*", $stars) . "</br>";
|
|
}
|
|
}
|
|
} |