Browse Source

Style fixes

master
J. King 11 months ago
parent
commit
02b655f5f6
  1. 5
      .php-cs-fixer.dist.php
  2. 19
      lib/Parser.php
  3. 9
      lib/Url.php

5
.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
];

19
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;
}
}
}

9
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 {

Loading…
Cancel
Save