Skip to content

Commit

Permalink
Added phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Jan 19, 2019
1 parent e246421 commit a865ab4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
27 changes: 27 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="API Skeletons" namespace="API-Skeletons\CS\Standard">
<description>v1.0 Coding Standard for API Skeletons</description>
<file>src</file>
<file>test</file>
<exclude-pattern type="relative">Bootstrap.php</exclude-pattern>
<exclude-pattern type="relative">*/data/*</exclude-pattern>
<arg name="colors"/>
<rule ref="PSR1"/>
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.ArrayIndent"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Commenting.Fixme"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Formatting.SpaceAfterNot"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.CamelCapsFunctionName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.DisallowAlternativePHPTags"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="./vendor/api-skeletons/coding-standard/phpcs/Sniffs/Strings/ConcatenationSpacingSniff.php"/>
</ruleset>
7 changes: 3 additions & 4 deletions src/CorrectUtf8Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/Utf8/CorrectUtf8EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ public function testInvalidUtf8()
$this->assertNotEquals("\xe2\x80\x0c", $resultString);
}
}


0 comments on commit a865ab4

Please sign in to comment.