Skip to content

Commit

Permalink
Merge branch 'hotfix/57'
Browse files Browse the repository at this point in the history
Close #57
  • Loading branch information
michalbundyra committed Nov 11, 2019
2 parents f97e8df + e0b4882 commit 9e93639
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ All notable changes to this project will be documented in this file, in reverse
- `Commenting\MethodAnnotation` sniff - `final` methods.
- `Commenting\PropertyAnnotation` sniff - properties defined with `var`.

- [#57](https://github.com/webimpress/coding-standard/pull/57) fixes parsing content of `@param` and `@var` tags with multiple spaces before variable name. Affects the following sniffs:
- `Commenting\TagWithType`,
- `Functions\Param`.

## 1.0.5 - 2019-10-06

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function processParamTag(File $phpcsFile, int $tagPtr) : bool
{
$tokens = $phpcsFile->getTokens();

$split = preg_split('/\s/', $tokens[$tagPtr + 2]['content'], 3);
$split = preg_split('/\s+/', $tokens[$tagPtr + 2]['content'], 3);

if (! isset($split[1])) {
if ($this->isVariable($split[0])) {
Expand Down Expand Up @@ -238,7 +238,7 @@ private function processVarTag(File $phpcsFile, int $tagPtr) : bool
$condition = end($tokens[$tagPtr]['conditions']);
$isMemberVar = isset(Tokens::$ooScopeTokens[$condition]);

$split = preg_split('/\s/', $tokens[$tagPtr + 2]['content'], 3);
$split = preg_split('/\s+/', $tokens[$tagPtr + 2]['content'], 3);
if ($nested > 0 || ! $isMemberVar) {
if (! isset($split[1])) {
if ($this->isVariable($split[0])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function processParamDoc(File $phpcsFile, int $commentStart) : void
continue;
}

$split = preg_split('/\s/', $tokens[$tag + 2]['content'], 3);
$split = preg_split('/\s+/', $tokens[$tag + 2]['content'], 3);
if (! isset($split[1]) || ! $this->isVariable($split[1])) {
// Missing param type or it's not a variable
continue;
Expand Down
7 changes: 7 additions & 0 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,11 @@ interface MyInterface extends MyOne, MyTwo
* @param null|mixed[] $mixedArray
*/
public function method5($mixed, array $mixedArray = null);

/**
* @param int $p1 Description
* @return iterable Description
* @throws Exception Description
*/
public function moreThanOneSpace(int $p1) : iterable;
}
7 changes: 7 additions & 0 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,11 @@ interface MyInterface extends MyOne, MyTwo
* @param null|mixed[] $mixedArray
*/
public function method5($mixed, array $mixedArray = null);

/**
* @param int $p1 Description
* @return iterable Description
* @throws Exception Description
*/
public function moreThanOneSpace(int $p1) : iterable;
}
5 changes: 5 additions & 0 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,9 @@ class VarTag extends VarTagParent {
* @var \RuntimeException\Hello Description.
*/
public $a;

/**
* @var int $moreThanOneSpace Some long description
*/
public $moreThanOneSpace;
}
5 changes: 5 additions & 0 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.3.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,9 @@ class VarTag extends VarTagParent {
* @var Exception\Hello Description.
*/
public $a;

/**
* @var int Some long description
*/
public $moreThanOneSpace;
}
1 change: 1 addition & 0 deletions test/Sniffs/Commenting/TagWithTypeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ protected function getErrorList(string $testFile = '') : array
295 => 1,
299 => 1,
304 => 1,
309 => 1,
];
}

Expand Down
5 changes: 5 additions & 0 deletions test/Sniffs/Functions/ParamUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,9 @@ interface MyInterface extends MyOne, MyTwo
?iterable $i2,
?iterable $i3
) : void;

/**
* @param int $p1
*/
public function moreThanOneSpace(int $p1) : void;
}
5 changes: 5 additions & 0 deletions test/Sniffs/Functions/ParamUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,9 @@ interface MyInterface extends MyOne, MyTwo
?iterable $i2,
?iterable $i3
) : void;

/**
*
*/
public function moreThanOneSpace(int $p1) : void;
}
1 change: 1 addition & 0 deletions test/Sniffs/Functions/ParamUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function getErrorList(string $testFile = '') : array
334 => 1,
335 => 1,
336 => 1,
351 => 1,
];
}

Expand Down
5 changes: 5 additions & 0 deletions test/Sniffs/Functions/ReturnTypeUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,9 @@ interface MyInterface extends MyOne, MyTwo
* @return null|Foo|object Description
*/
public function typeSpecifiedWithDescriptionObject() : ?object;

/**
* @return null|int
*/
public function moreThanOneSpace() : ?int;
}
5 changes: 5 additions & 0 deletions test/Sniffs/Functions/ReturnTypeUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,9 @@ interface MyInterface extends MyOne, MyTwo
* @return null|Foo Description
*/
public function typeSpecifiedWithDescriptionObject() : ?object;

/**
*
*/
public function moreThanOneSpace() : ?int;
}
1 change: 1 addition & 0 deletions test/Sniffs/Functions/ReturnTypeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected function getErrorList(string $testFile = '') : array
371 => 1,
376 => 1,
381 => 1,
386 => 1,
];
case 'ReturnTypeUnitTest.2.inc':
return [
Expand Down
8 changes: 8 additions & 0 deletions test/Sniffs/Functions/ThrowsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,12 @@ class ThrowUnitTest
throw new Exception();
});
}

/**
* @throws Exception Description
*/
public function moreThanOneSpace()
{
throw new Exception();
}
}
8 changes: 8 additions & 0 deletions test/Sniffs/Functions/ThrowsUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,12 @@ class ThrowUnitTest
throw new Exception();
});
}

/**
* @throws Exception Description
*/
public function moreThanOneSpace()
{
throw new Exception();
}
}

0 comments on commit 9e93639

Please sign in to comment.