Skip to content

Commit

Permalink
refactor: make code param optional
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Dec 21, 2019
1 parent a7a0ca2 commit d41b677
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Highlighter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ahc\CliSyntax;

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

public function __construct(string $code)
public function __construct(string $code = null)
{
$this->code = $code;
$this->code = $code ?? '';
}

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

public function highlight(): string
public function highlight(string $code = null): string
{
static::configure();

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

return $this->parse($html);
Expand Down

0 comments on commit d41b677

Please sign in to comment.