From a865ab46edbee27ceb9581dbd95a7f38df8ae584 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 19 Jan 2019 16:45:36 -0700 Subject: [PATCH] Added phpcs --- composer.json | 3 ++- phpcs.xml | 27 +++++++++++++++++++++++++++ src/CorrectUtf8Encoding.php | 7 +++---- test/Utf8/CorrectUtf8EncodingTest.php | 2 -- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 phpcs.xml diff --git a/composer.json b/composer.json index 66d6bd8..bd0541a 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "description": "Correct badly encoded and multiple encoded UTF8 characters by examining each byte in a string.", "type": "library", "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^7.5", + "api-skeletons/coding-standard": "^1.0" }, "license": "MIT", "authors": [ diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..330895a --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,27 @@ + + + v1.0 Coding Standard for API Skeletons + src + test + Bootstrap.php + */data/* + + + + + + + + + + + + + + + + + + + + diff --git a/src/CorrectUtf8Encoding.php b/src/CorrectUtf8Encoding.php index 5d5b2ba..ffe14fb 100644 --- a/src/CorrectUtf8Encoding.php +++ b/src/CorrectUtf8Encoding.php @@ -59,7 +59,7 @@ public function __invoke($input, $counter = 0) $character = mb_substr($workingString, 0, 1, 'UTF-8'); $characterUtf32BE= @mb_convert_encoding($character, 'UTF-32BE', 'UTF-8'); - if (!$characterUtf32BE) { + if (! $characterUtf32BE) { throw new Exception('invalid character' . "\n" . $character . "\n" . $input); } $characterCode = hexdec(bin2hex($characterUtf32BE)); @@ -72,9 +72,9 @@ public function __invoke($input, $counter = 0) // be the start of an invalid sequence. if ($characterCode >= 0xf0 && $characterCode <= 0xf7) { $bytes = 4; - } else if ($characterCode >= 0xe0 && $characterCode <= 0xef) { + } elseif ($characterCode >= 0xe0 && $characterCode <= 0xef) { $bytes = 3; - } else if ($characterCode >= 0xc0 && $characterCode <= 0xdf) { + } elseif ($characterCode >= 0xc0 && $characterCode <= 0xdf) { $bytes = 2; } @@ -138,7 +138,6 @@ public function __invoke($input, $counter = 0) // $character may be multiple characters by this point $workingString = mb_substr($workingString, $characterLength); $return .= $character; - } // Re-run to fix double or more encodings diff --git a/test/Utf8/CorrectUtf8EncodingTest.php b/test/Utf8/CorrectUtf8EncodingTest.php index d139f60..3590fff 100644 --- a/test/Utf8/CorrectUtf8EncodingTest.php +++ b/test/Utf8/CorrectUtf8EncodingTest.php @@ -37,5 +37,3 @@ public function testInvalidUtf8() $this->assertNotEquals("\xe2\x80\x0c", $resultString); } } - -