From 02b655f5f6d3096fd158229189f9a51e6552481d Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 17 Jun 2023 10:25:30 -0400 Subject: [PATCH] Style fixes --- .php-cs-fixer.dist.php | 5 ++++- lib/Parser.php | 19 +++++++++---------- lib/Url.php | 9 +++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 376834a..1fb5529 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -57,7 +57,10 @@ $rules = [ // PSR standard to apply '@PSR12' => true, // house exceptions to PSR rules - 'braces' => ['position_after_functions_and_oop_constructs' => "same"], + 'curly_braces_position' => [ + 'functions_opening_brace' => "same_line", + 'classes_opening_brace' => "same_line", + ], 'function_declaration' => ['closure_function_spacing' => "none"], 'new_with_braces' => false, // no option to specify absence of braces ]; diff --git a/lib/Parser.php b/lib/Parser.php index 8eb6c51..11ade19 100644 --- a/lib/Parser.php +++ b/lib/Parser.php @@ -106,7 +106,7 @@ class Parser { 'author' => ['h-entry' => ["u", "author", [], null, true]], ]; /** @var array The list of (global) attributes which contain URLs and apply to any element */ - protected const URL_ATTRS_GLOBAL= ["itemid", "itemprop", "itemtype"]; + protected const URL_ATTRS_GLOBAL = ["itemid", "itemprop", "itemtype"]; /** @var array The list of (non-global) attributes which contain URLs and their host elements */ protected const URL_ATTRS = [ 'a' => ["href", "ping"], @@ -197,7 +197,7 @@ class Parser { protected $xpath; /** Parses a DOMElement for microformats - * + * * @param \DOMElement $node The DOMElement to parse * @param string $baseURL The base URL against which to resolve relative URLs in the output */ @@ -465,7 +465,7 @@ class Parser { $out['properties'][$key] = [$value]; } } - # imply properties for the found microformat + # imply properties for the found microformat if (!$backcompat) { # if no explicit "name" property, and no other p-* or e-* properties, and no nested microformats, if (!isset($out['properties']['name']) && !$hasChild && !$hasP && !$hasE) { @@ -663,10 +663,9 @@ class Parser { } elseif (in_array($node->localName, ["img", "area"]) && $node->hasAttribute("alt")) { # else if img.p-x[alt] or area.p-x[alt], then return the alt attribute return $node->getAttribute("alt"); - } else { - # else return the textContent of the element after [cleaning] - return $this->getCleanText($node, $prefix); } + # else return the textContent of the element after [cleaning] + return $this->getCleanText($node, $prefix); case "u": # To parse an element for a u-x property value (whether explicit u-* or backcompat equivalent): if (in_array($node->localName, ["a", "area", "link"]) && $node->hasAttribute("href")) { @@ -745,7 +744,7 @@ class Parser { } // return the result return [ - 'html' => trim(Serializer::serializeInner($copy)), + 'html' => trim(Serializer::serializeInner($copy)), 'value' => $this->getCleanText($node, $prefix), ]; default: @@ -870,7 +869,7 @@ class Parser { ]; } foreach (self::ZONE_INPUT_FORMATS as $zf => $zp) { - if ($out = $this->testDate($input, "!$df $tf$zf", "!$df\T$tf$zf","!$df $tf $zf", "!$df\T$tf $zf")) { + if ($out = $this->testDate($input, "!$df $tf$zf", "!$df\T$tf$zf", "!$df $tf $zf", "!$df\T$tf $zf")) { return [ 'date' => $out->format(self::DATE_OUTPUT_FORMATS[$dp]), 'time' => $out->format(self::DATE_OUTPUT_FORMATS[$tp]), @@ -998,7 +997,7 @@ class Parser { } /** Finds the next element in tree order after $node, if any - * + * * @param \DOMNode $node The context node * @param \DOMElement $root The element to consider the contextual root of the tree * @param bool $considerChildren Whether or not child nodes are valid next nodes @@ -1024,4 +1023,4 @@ class Parser { } return $next; } -} \ No newline at end of file +} diff --git a/lib/Url.php b/lib/Url.php index aa7e64e..1f57e94 100644 --- a/lib/Url.php +++ b/lib/Url.php @@ -4,6 +4,7 @@ * See LICENSE and AUTHORS files for details */ declare(strict_types=1); + namespace MensBeam\Microformats; use Psr\Http\Message\UriInterface; @@ -44,7 +45,7 @@ class Url implements UriInterface { (\#.*)? # fragment part $>six PCRE; - protected const STRICT_URI_PATTERN = <<<'PCRE' + protected const STRICT_URI_PATTERN = <<<'PCRE' <^ (?: (?: @@ -381,14 +382,14 @@ PCRE; protected function setPass(string $value): void { $this->pass = $this->percentEncode($value, "userinfo"); } - + protected function setHost(?string $value): void { if ($this->scheme === "file" && strtolower($value) === "localhost") { $this->host = ""; } else { $this->host = $this->parseHost($value); } - + } protected function setPort(string $value): void { @@ -595,7 +596,7 @@ PCRE; $out[] = $ipv4 % 256; $ipv4 = floor($ipv4 / 256); } - return implode(".", array_reverse($out)); + return implode(".", array_reverse($out)); } protected function parseIPv4Number(string $n): ?int {