Skip to content

Commit

Permalink
php-gettext#282 Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Jul 23, 2022
1 parent d656353 commit 647cdfc
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Loader/StrictPoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function loadString(string $string, Translations $translations = null): T
$this->saveEntry();
}
$this->processHeader();

return $this->translations;
}

Expand Down Expand Up @@ -88,6 +89,7 @@ private function readWhiteSpace(): bool
while ((ctype_space($this->getChar() ?? '') && $this->nextChar())
|| $this->readDisabledComment()
|| $this->readPreviousTranslationComment());

return $position !== $this->position;
}

Expand All @@ -97,7 +99,7 @@ private function readWhiteSpace(): bool
private function readString(string $word): bool
{
return substr($this->data, $this->position, strlen($word)) === $word
? !!($this->position += strlen($word))
? (bool) ($this->position += strlen($word))
: false;
}

Expand All @@ -106,7 +108,7 @@ private function readString(string $word): bool
*/
private function readChar(string $char): bool
{
return $this->getChar() === $char ? !!++$this->position : false;
return $this->getChar() === $char ? (bool) ++$this->position : false;
}

/**
Expand All @@ -118,6 +120,7 @@ private function nextChar(): ?string
if ($char !== null) {
++$this->position;
}

return $char;
}

Expand All @@ -135,6 +138,7 @@ private function getChar(): ?string
private function readNumber(): string
{
for ($data = ''; ctype_digit($this->getChar() ?? ''); $data .= $this->nextChar());

return $data;
}

Expand All @@ -143,10 +147,13 @@ private function readNumber(): string
*/
private function readCharset(string $charset, int $maxLength): string
{
for ($data = ''; ($char = $this->getChar()) !== null && is_int(strpos($charset, $char)) && --$maxLength >= 0; $data .= $this->nextChar());
for ($data = ''; ($char = $this->getChar()) !== null
&& is_int(strpos($charset, $char))
&& --$maxLength >= 0; $data .= $this->nextChar());
if ($data === '') {
throw new Exception("Expected at least one occurrence of the characters \"{$charset}\" at byte {$this->position}");
throw new Exception("Expected at least one occurrence of \"{$charset}\" at byte {$this->position}");
}

return $data;
}

Expand All @@ -156,6 +163,7 @@ private function readCharset(string $charset, int $maxLength): string
private function readCommentString(): string
{
for ($data = ''; ($char = $this->getChar() ?? "\n") !== "\n" && $char !== "\r"; $data .= $this->nextChar());

return $data;
}

Expand Down Expand Up @@ -221,6 +229,7 @@ private function readQuotedString(): string
}
$this->readWhiteSpace();
}

return $data;
}

Expand Down Expand Up @@ -278,6 +287,7 @@ private function readComment(): bool
$this->translation->getExtractedComments()->add($data);
break;
}

return true;
}

Expand All @@ -291,9 +301,11 @@ private function readIdentifier(string $identifier, bool $throwIfNotFound = fals
if ($throwIfNotFound) {
throw new Exception("Expected identifier $identifier at byte {$this->position}");
}

return null;
}
$this->readWhiteSpace();

return $this->readQuotedString();
}

Expand All @@ -306,6 +318,7 @@ private function readContext(): bool
return false;
}
$this->translation = $this->translation->withContext($data);

return true;
}

Expand All @@ -327,6 +340,7 @@ private function readPlural(): bool
return false;
}
$this->translation->setPlural($data);

return true;
}

Expand Down Expand Up @@ -354,6 +368,7 @@ private function readPluralTranslation(bool $throwIfNotFound = false): bool
if ($throwIfNotFound) {
throw new Exception("Expected indexed msgstr at byte {$this->position}");
}

return false;
}
$this->readWhiteSpace();
Expand All @@ -379,6 +394,7 @@ private function readPluralTranslation(bool $throwIfNotFound = false): bool
$translations[] = $data;
$this->translation->translate(array_shift($translations));
$this->translation->translatePlural(...$translations);

return true;
}

Expand Down Expand Up @@ -433,6 +449,7 @@ private function readHeaders(?string $string): array
}
$headers[$name] .= $line;
}

return $headers;
}
}

0 comments on commit 647cdfc

Please sign in to comment.