From 4e5c2bfb5e5f16a0a9cfc0d6a912ae4c5e35af66 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 21 Apr 2020 19:21:47 -0400 Subject: [PATCH] Style fixes --- .php_cs.dist | 7 +++++-- lib/MimeType.php | 4 ++-- lib/Parser/Construct.php | 2 -- lib/Parser/XML/Entry.php | 2 +- tests/cases/Util/MimeTypeTest.php | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 8bef6af..865f0e6 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,4 +1,5 @@ ['=>' => "align_single_space"], ], 'cast_spaces' => ['space' => "single"], - 'concat_space' => ['spacing' => "none"], 'list_syntax' => ['syntax' => "short"], 'magic_constant_casing' => true, 'magic_method_casing' => true, @@ -48,11 +48,13 @@ $rules = [ // PSR standard to apply '@PSR2' => true, // PSR-12 rules; php-cs-fixer does not yet support PSR-12 natively + 'blank_line_after_opening_tag' => true, 'compact_nullable_typehint' => true, 'declare_equal_normalize' => ['space' => "none"], 'function_typehint_space' => true, 'lowercase_cast' => true, 'lowercase_static_reference' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'no_alternative_syntax' => true, 'no_empty_statement' => true, 'no_leading_import_slash' => true, @@ -65,8 +67,9 @@ $rules = [ // house exceptions to PSR rules 'braces' => ['position_after_functions_and_oop_constructs' => "same"], 'function_declaration' => ['closure_function_spacing' => "none"], + 'concat_space' => ['spacing' => "none"], 'new_with_braces' => false, // no option to specify absence of braces - ]; +]; $finder = \PhpCsFixer\Finder::create(); foreach ($paths as $path) { diff --git a/lib/MimeType.php b/lib/MimeType.php index b18683e..bdc48a6 100644 --- a/lib/MimeType.php +++ b/lib/MimeType.php @@ -12,7 +12,7 @@ class MimeType extends \MensBeam\Mime\MimeType { protected const ATOM_TYPE_PATTERN = '<^\s*(|text|x?html)\s*$>i'; protected static $mime; - + /** Parses a MIME type, accepting types without a subtype */ public static function parseLoose(string $type, ?Url $url = null): ?self { if ($normalized = self::parse($type)) { @@ -52,7 +52,7 @@ class MimeType extends \MensBeam\Mime\MimeType { } return self::parse($type) ?? self::parse("unknown/unknown"); } - + protected function essence(): string { return $this->type.(strlen($this->subtype ?? "") ? "/".$this->subtype : ""); } diff --git a/lib/Parser/Construct.php b/lib/Parser/Construct.php index bb83cc7..4d44306 100644 --- a/lib/Parser/Construct.php +++ b/lib/Parser/Construct.php @@ -8,8 +8,6 @@ namespace MensBeam\Lax\Parser; use MensBeam\Lax\Collection; use MensBeam\Lax\Date; -use MensBeam\Lax\MimeType; -use MensBeam\Lax\Url; trait Construct { /** Trims plain text and collapses whitespace */ diff --git a/lib/Parser/XML/Entry.php b/lib/Parser/XML/Entry.php index 0464ea6..83aaeb4 100644 --- a/lib/Parser/XML/Entry.php +++ b/lib/Parser/XML/Entry.php @@ -303,7 +303,7 @@ class Entry extends Construct implements \MensBeam\Lax\Parser\Entry { if ($url) { $out = new Enclosure; $out->url = $url; - $out->type = MimeType::parseLoose($this->fetchString("@type", ".+", false, $node) ?? "") + $out->type = MimeType::parseLoose($this->fetchString("@type", ".+", false, $node) ?? "") ?? MimeType::parseLoose($this->fetchString("@medium", ".+", false, $node) ?? "") ?? MimeType::parseLoose("", $url); $out->title = $this->fetchTitleMediaRss($node); diff --git a/tests/cases/Util/MimeTypeTest.php b/tests/cases/Util/MimeTypeTest.php index 348731a..5b976e3 100644 --- a/tests/cases/Util/MimeTypeTest.php +++ b/tests/cases/Util/MimeTypeTest.php @@ -61,7 +61,7 @@ class MimeTypeTest extends \PHPUnit\Framework\TestCase { ]; } - public function testManipulateAnIncompleteType():void { + public function testManipulateAnIncompleteType(): void { $t = MimeType::parseLoose("text; charset=utf-8"); $this->assertSame("text", $t->type); $this->assertSame("", $t->subtype);