Skip to content

Commit

Permalink
use constant for constant variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 18, 2021
1 parent 6b467d7 commit 4c8fbea
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions packages/FileFormatter/Formatter/XmlFileFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
*/
final class XmlFileFormatter implements FileFormatterInterface
{
/**
* @see https://regex101.com/r/uTmMcr/1
* @var string
*/
private const XML_PARTS_REGEX = '#(>)(<)(\/*)#';

/**
* @see https://regex101.com/r/hSG1JT/1
* @var string
*/
private const IS_OPENING_TAG_REGEX = '#^<[^\/]*>$#';

/**
* @see https://regex101.com/r/ywS62K/1
* @var string
*/
private const IS_CLOSING_TAG_REGEX = '#^\s*<\/#';

private ?int $depth = null;

private int $indent = 4;
Expand Down Expand Up @@ -75,9 +93,7 @@ private function formatXml(string $xml): string
*/
private function getXmlParts(string $xml): array
{
$xmlParts = '#(>)(<)(\/*)#';

$withNewLines = Strings::replace(trim($xml), $xmlParts, "$1\n$2$3");
$withNewLines = Strings::replace(trim($xml), self::XML_PARTS_REGEX, "$1\n$2$3");
return explode("\n", $withNewLines);
}

Expand Down Expand Up @@ -125,16 +141,12 @@ private function getPaddedString(string $part): string

private function isOpeningTag(string $part): bool
{
$isOpeningTag = '#^<[^\/]*>$#';

return (bool) Strings::match($part, $isOpeningTag);
return (bool) Strings::match($part, self::IS_OPENING_TAG_REGEX);
}

private function isClosingTag(string $part): bool
{
$isClosingTag = '#^\s*<\/#';

return (bool) Strings::match($part, $isClosingTag);
return (bool) Strings::match($part, self::IS_CLOSING_TAG_REGEX);
}

private function isOpeningCdataTag(string $part): bool
Expand Down

0 comments on commit 4c8fbea

Please sign in to comment.