Skip to content

Commit

Permalink
added docs and other fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jgniecki committed Jun 24, 2024
1 parent 46cc700 commit c3ff8c6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Parser/TextParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function parse($data, MotdItemCollection $collection): MotdItemCollection

$s = $this->symbol;
$regex = "/[^" . $s . "].(?=" . $s . ")|" . $s . "([0-9a-fklmnor])(.*?)(?=" . $s . "[0-9a-fklmnor]|$)/";
$lines = \preg_split('/\\n/', $data);
$lines = (array) \preg_split('/\\n/', $data);
for ($i = 0; $i < \count($lines); $i++) {
$motdItem = new MotdItem();
$line = $lines[$i];
$line = (string) $lines[$i];
\preg_match_all($regex, $line, $output);

if (!isset($output[1]) || !isset($output[2]))
Expand All @@ -67,7 +67,11 @@ public function parse($data, MotdItemCollection $collection): MotdItemCollection
if ($this->colorCollection->get($key)) {
$motdItem->setColor($key);
} else {
$method = 'set' . \ucfirst($this->formatCollection->get($key)->getName());
$formatter = $this->formatCollection->get($key);
if (!$formatter)
continue; //todo nie rozpoznany format

$method = 'set' . \ucfirst($formatter->getName());
\call_user_func([$motdItem, $method], true);
}

Expand All @@ -88,6 +92,10 @@ public function parse($data, MotdItemCollection $collection): MotdItemCollection
return $collection;
}

/**
* @param string $data
* @return bool
*/
public function supports($data): bool
{
return \is_string($data) && !empty($data);
Expand Down

0 comments on commit c3ff8c6

Please sign in to comment.