From 096cf6ce3f6428bed8aa58cd952a741c6a376e71 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 5 May 2020 18:22:13 -0400 Subject: [PATCH] Style fixes --- lib/Date.php | 18 +++++++++--------- lib/Parser/Construct.php | 1 - lib/Parser/HTTP/Message.php | 2 +- lib/Parser/Parser.php | 4 ++-- tests/cases/AbstractParserTestCase.php | 2 +- tests/cases/Util/Date/DateTest.php | 17 ++++++++--------- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/Date.php b/lib/Date.php index e89d6a2..ad32122 100644 --- a/lib/Date.php +++ b/lib/Date.php @@ -52,7 +52,7 @@ class Date extends \DateTimeImmutable implements \JsonSerializable { 'PST' => "-0800", 'PDT' => "-0700", ]; - + /* Important formats: @@ -73,25 +73,25 @@ class Date extends \DateTimeImmutable implements \JsonSerializable { } /** Returns a date parsed from a string in any of the following formats: - * + * * - RFC 3339 * - RFC 822 * - RFC 850 * - ANSI C asctime() - * - * Subsets of RFC 822 and RFC 850 formats and asctime() format are used + * + * Subsets of RFC 822 and RFC 850 formats and asctime() format are used * by RFC 7231 (HTTP), and the latter definition was consulted for * guidance. RFC 3339 and RFC 822 formats are both supported in full, and * the ambiguous century of RFC 822 and RFC 850 formats is interpreted per * RFC 7231. Timezones used for RFC 822 are also accepted for RFC 850. - * + * * All formats except asctime() are also accepted with subsecond precision, * or with minute precision. Whitespace before the timezone may be omitted - * or used in all formats as well (RFC 3339 does not normally allow - * whitespace, while other formats require it). - * + * or used in all formats as well (RFC 3339 does not normally allow + * whitespace, while other formats require it). + * * If no timezone is specified, -00:00 is used. - * + * * @see https://tools.ietf.org/html/rfc3339 * @see https://tools.ietf.org/html/rfc822#section-5 * @see https://tools.ietf.org/html/rfc850#section-2.1.4 diff --git a/lib/Parser/Construct.php b/lib/Parser/Construct.php index 68d148e..b735006 100644 --- a/lib/Parser/Construct.php +++ b/lib/Parser/Construct.php @@ -7,7 +7,6 @@ declare(strict_types=1); namespace MensBeam\Lax\Parser; use MensBeam\Lax\Collection; -use MensBeam\Lax\Date; trait Construct { /** Trims plain text and collapses whitespace */ diff --git a/lib/Parser/HTTP/Message.php b/lib/Parser/HTTP/Message.php index 8bef896..f5ec7f9 100644 --- a/lib/Parser/HTTP/Message.php +++ b/lib/Parser/HTTP/Message.php @@ -119,7 +119,7 @@ class Message { } public function getMaxAge(): ?\DateInterval { - $out = 0; + $out = 0; $maxAge = 0; $sharedMaxAge = 0; foreach ($this->parseHeader("Cache-Control", self::CCON_PATTERN, true) ?? [] as $t) { diff --git a/lib/Parser/Parser.php b/lib/Parser/Parser.php index f93ece7..39a19d5 100644 --- a/lib/Parser/Parser.php +++ b/lib/Parser/Parser.php @@ -34,7 +34,7 @@ abstract class Parser { } elseif (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)) { return "text/html"; } elseif (preg_match('/^\/]/', $prefix)) { @@ -48,7 +48,7 @@ abstract class Parser { } else { // FIIXME: Is there a better fallback that could used here? "application/xml"; - } + } } else { return "application/octet-stream"; } diff --git a/tests/cases/AbstractParserTestCase.php b/tests/cases/AbstractParserTestCase.php index dc215db..419633e 100644 --- a/tests/cases/AbstractParserTestCase.php +++ b/tests/cases/AbstractParserTestCase.php @@ -39,7 +39,7 @@ class AbstractParserTestCase extends \PHPUnit\Framework\TestCase { if (is_object($test->input)) { assert((isset($test->input->head) && $test->input->head instanceof \stdClass) || (isset($test->input->body) && is_string($test->input->body)), "Input is not in a correct format"); $test->input = new Response($test->input->status ?? 200, (array) ($test->input->head ?? []), $test->input->body ?? null); - } + } yield "$file: {$description}" => [ $test->input, $test->type ?? "", diff --git a/tests/cases/Util/Date/DateTest.php b/tests/cases/Util/Date/DateTest.php index 79d3afc..7e4a65e 100644 --- a/tests/cases/Util/Date/DateTest.php +++ b/tests/cases/Util/Date/DateTest.php @@ -17,26 +17,26 @@ class DateTest extends \PHPUnit\Framework\TestCase { $this->assertInstanceOf(\DateTimeImmutable::class, $d); $this->assertSame("2001-05-22T14:55:23.000000Z", $d->setTimezone(new \DateTimeZone("UTC"))->format("Y-m-d\TH:i:s.u\Z")); } - + public function testNormalizeADate(): void { $d = new Date("2001-05-22T14:55:23-01:00"); $this->assertSame("2001-05-22T15:55:23.000000Z", $d->normalize()); } - + public function testCastADateToString(): void { $d = new Date("2001-05-22T14:55:23-01:00"); $this->assertSame("2001-05-22T14:55:23-01:00", (string) $d); $d = new Date("2001-05-22T14:55:23.55Z"); $this->assertSame("2001-05-22T14:55:23.550000+00:00", (string) $d); } - + public function testSerializeADateToJson(): void { $d = new Date("2001-05-22T14:55:23-01:00"); $this->assertSame('"2001-05-22T14:55:23-01:00"', json_encode($d)); $d = new Date("2001-05-22T14:55:23.55Z"); $this->assertSame('"2001-05-22T14:55:23.550000+00:00"', json_encode($d)); } - + public function testCreateADateFromADatetimeInterfaceInstance(): void { $m = new \DateTime("2001-05-22T14:55:23-01:00"); $d = Date::createFromMutable($m); @@ -45,7 +45,7 @@ class DateTest extends \PHPUnit\Framework\TestCase { $d = Date::createFromImmutable($i); $this->assertSame("2001-05-22T15:55:23.000000Z", $d->normalize()); } - + public function testCreateADateFromAFormatString(): void { $f = '!Y-m-d\TH:i:sP'; $d = Date::createFromFormat($f, "2001-05-22T14:55:23-01:00"); @@ -58,7 +58,7 @@ class DateTest extends \PHPUnit\Framework\TestCase { /** @dataProvider provideParsableStrings */ public function testCreateADateFromAString(string $input, ?string $exp): void { $act = Date::createFromString($input); - if (!$exp) { + if (!$exp) { $this->assertNull($act); } else { $this->assertSame($exp, (string) $act); @@ -68,14 +68,13 @@ class DateTest extends \PHPUnit\Framework\TestCase { public function provideParsableStrings(): iterable { 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) { - 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 $test->output[-6] = "+"; } if (is_array($test->input)) { - foreach($test->input as $input) { + foreach ($test->input as $input) { yield "$description ($input)" => [$input, $test->output]; - } } else { yield "$description" => [$test->input, $test->output];