Skip to content

Commit

Permalink
check for empty needle when calling strpos, fixes #78
Browse files Browse the repository at this point in the history
  • Loading branch information
xalopp committed May 17, 2018
1 parent c133b45 commit 05eae77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.1.1] - 2018-05-17
### Changed
- Check for empty needle when calling str_pos, fixes #78

## [2.1.0] - 2018-04-06
### Changed
- PHPCS version 3.2.3 or later is required.
Expand Down
2 changes: 1 addition & 1 deletion MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private function checkShorthandPossible(
);

$replaceClassName = true;
} else if (strpos($fullClassName, $namespace) === 0) {
} else if ($namespace !== "" && strpos($fullClassName, $namespace) === 0) {
$replacement = substr($fullClassName, strlen($namespace));

$data = [
Expand Down
12 changes: 12 additions & 0 deletions MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.pass.5.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
// bug #78

class C
{
/**
* @return void
*/
public function f()
{
}
}
1 change: 1 addition & 0 deletions MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected function getWarningList($testFile='')
case 'UnnecessaryNamespaceUsageUnitTest.pass.2.inc':
case 'UnnecessaryNamespaceUsageUnitTest.pass.3.inc':
case 'UnnecessaryNamespaceUsageUnitTest.pass.4.inc':
case 'UnnecessaryNamespaceUsageUnitTest.pass.5.inc':
return [];
case 'UnnecessaryNamespaceUsageUnitTest.fail.1.inc':
return [
Expand Down

0 comments on commit 05eae77

Please sign in to comment.