Browse Source

Style fixes

master
J. King 4 years ago
parent
commit
096cf6ce3f
  1. 1
      lib/Parser/Construct.php
  2. 2
      lib/Parser/HTTP/Message.php
  3. 2
      lib/Parser/Parser.php
  4. 7
      tests/cases/Util/Date/DateTest.php

1
lib/Parser/Construct.php

@ -7,7 +7,6 @@ declare(strict_types=1);
namespace MensBeam\Lax\Parser; namespace MensBeam\Lax\Parser;
use MensBeam\Lax\Collection; use MensBeam\Lax\Collection;
use MensBeam\Lax\Date;
trait Construct { trait Construct {
/** Trims plain text and collapses whitespace */ /** Trims plain text and collapses whitespace */

2
lib/Parser/HTTP/Message.php

@ -119,7 +119,7 @@ class Message {
} }
public function getMaxAge(): ?\DateInterval { public function getMaxAge(): ?\DateInterval {
$out = 0; $out = 0;
$maxAge = 0; $maxAge = 0;
$sharedMaxAge = 0; $sharedMaxAge = 0;
foreach ($this->parseHeader("Cache-Control", self::CCON_PATTERN, true) ?? [] as $t) { foreach ($this->parseHeader("Cache-Control", self::CCON_PATTERN, true) ?? [] as $t) {

2
lib/Parser/Parser.php

@ -34,7 +34,7 @@ abstract class Parser {
} elseif (preg_match('/^\s*</s', $data)) { } elseif (preg_match('/^\s*</s', $data)) {
// distinguish between XML feeds and HTML; first skip any comments before the root element // distinguish between XML feeds and HTML; first skip any comments before the root element
$offset = preg_match('/^\s*(?:<!--(?:[^\-]|-(?!->)*-->\s*)*/s', $data, $match) ? strlen($match[0]) : 0; $offset = preg_match('/^\s*(?:<!--(?:[^\-]|-(?!->)*-->\s*)*/s', $data, $match) ? strlen($match[0]) : 0;
$prefix = substr($data, $offset, 100); // $prefix = substr($data, $offset, 100);
if (preg_match('/^<(?:!DOCTYPE\s+html|html|body|head|table|div|title|p|link|meta)[\s>]/si', $prefix)) { if (preg_match('/^<(?:!DOCTYPE\s+html|html|body|head|table|div|title|p|link|meta)[\s>]/si', $prefix)) {
return "text/html"; return "text/html";
} elseif (preg_match('/^<rss[\s>\/]/', $prefix)) { } elseif (preg_match('/^<rss[\s>\/]/', $prefix)) {

7
tests/cases/Util/Date/DateTest.php

@ -58,7 +58,7 @@ class DateTest extends \PHPUnit\Framework\TestCase {
/** @dataProvider provideParsableStrings */ /** @dataProvider provideParsableStrings */
public function testCreateADateFromAString(string $input, ?string $exp): void { public function testCreateADateFromAString(string $input, ?string $exp): void {
$act = Date::createFromString($input); $act = Date::createFromString($input);
if (!$exp) { if (!$exp) {
$this->assertNull($act); $this->assertNull($act);
} else { } else {
$this->assertSame($exp, (string) $act); $this->assertSame($exp, (string) $act);
@ -68,14 +68,13 @@ class DateTest extends \PHPUnit\Framework\TestCase {
public function provideParsableStrings(): iterable { public function provideParsableStrings(): iterable {
foreach (new \GlobIterator(__DIR__."/test-*.yaml", \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::KEY_AS_FILENAME) as $file => $path) { foreach (new \GlobIterator(__DIR__."/test-*.yaml", \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::KEY_AS_FILENAME) as $file => $path) {
foreach ((new YamlParser)->parseFile($path, Yaml::PARSE_OBJECT_FOR_MAP) as $description => $test) { foreach ((new YamlParser)->parseFile($path, Yaml::PARSE_OBJECT_FOR_MAP) as $description => $test) {
if (!is_null($test->output) && substr($test->output, -6) === "-00:00") { if (!is_null($test->output) && substr($test->output, -6) === "-00:00") {
// PHP does not preserve the -0000 timezone // PHP does not preserve the -0000 timezone
$test->output[-6] = "+"; $test->output[-6] = "+";
} }
if (is_array($test->input)) { if (is_array($test->input)) {
foreach($test->input as $input) { foreach ($test->input as $input) {
yield "$description ($input)" => [$input, $test->output]; yield "$description ($input)" => [$input, $test->output];
} }
} else { } else {
yield "$description" => [$test->input, $test->output]; yield "$description" => [$test->input, $test->output];

Loading…
Cancel
Save