Skip to content

Commit d41b677

Browse files
committed
refactor: make code param optional
1 parent a7a0ca2 commit d41b677

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Highlighter.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Ahc\CliSyntax;
46

57
class Highlighter
@@ -10,9 +12,9 @@ class Highlighter
1012
/** @var bool Indicates if it has been already configured. */
1113
protected static $configured;
1214

13-
public function __construct(string $code)
15+
public function __construct(string $code = null)
1416
{
15-
$this->code = $code;
17+
$this->code = $code ?? '';
1618
}
1719

1820
public function __toString(): string
@@ -29,11 +31,11 @@ public static function for(string $file): self
2931
return new static(\file_get_contents($file));
3032
}
3133

32-
public function highlight(): string
34+
public function highlight(string $code = null): string
3335
{
3436
static::configure();
3537

36-
$html = \highlight_string($this->code, true);
38+
$html = \highlight_string($code ?? $this->code, true);
3739
$html = \str_replace(['<br />', '<br/>', '<br>'], "\n", $html);
3840

3941
return $this->parse($html);

0 commit comments

Comments
 (0)