Skip to content

Commit

Permalink
Merge pull request #42 from Zenify/fixes
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
Tomáš Votruba authored Nov 1, 2016
2 parents e19264a + 93e41f3 commit 2ec4ffb
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 63 deletions.
26 changes: 2 additions & 24 deletions docs/en/zenify-rules-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class SomeClass
final class SomeClass implements SomeInterface
{

/**
* {@inheritdoc}
*/
public function run()
{

Expand All @@ -76,9 +73,6 @@ final class SomeClass implements SomeInterface
class SomeClass implements SomeInterface
{

/**
* {@inheritdoc}
*/
public function run()
{

Expand Down Expand Up @@ -152,7 +146,7 @@ protected function createComponentDisplay()

### VarPropertyCommentSniff

- Property should have docblock comment (except for {@inheritdoc}).
- Property should have docblock comment.

*Correct*

Expand Down Expand Up @@ -229,7 +223,7 @@ class SomeClass

### MethodCommentReturnTagSniff

- Getters should have @return tag (except for {@inheritdoc}).
- Getters should have @return tag or return type.

*Correct*

Expand All @@ -249,22 +243,6 @@ class SomeClass
```


```php
class SomeClass
{

/**
* {@inheritdoc}
*/
public function getResult()
{
// ...
}

}
```


*Wrong*

```php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use ZenifyCodingStandard\Helper\Commenting\FunctionHelper;


/**
Expand Down Expand Up @@ -38,17 +39,15 @@ final class ComponentFactoryCommentSniff implements PHP_CodeSniffer_Sniff
private $tokens;


/**
* {@inheritdoc}
*/
public function register()
public function register() : array
{
return [T_FUNCTION];
}


/**
* {@inheritdoc}
* @param PHP_CodeSniffer_File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position)
{
Expand All @@ -60,9 +59,14 @@ public function process(PHP_CodeSniffer_File $file, $position)
return;
}

$returnTypeHint = FunctionHelper::findReturnTypeHint($file, $position);
if ($returnTypeHint) {
return;
}

$commentEnd = $this->getCommentEnd();
if ( ! $this->hasMethodComment($commentEnd)) {
$file->addError('CreateComponent* method should have a doc comment', $position);
$file->addError('createComponent<name> method should have a doc comment or return type.', $position);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* Rules:
* - Getters should have @return tag (except for {@inheritdoc}).
* - Getters should have @return tag or return type.
*/
final class MethodCommentReturnTagSniff implements PHP_CodeSniffer_Sniff
{
Expand All @@ -35,7 +35,8 @@ public function register() : array


/**
* {@inheritdoc}
* @param PHP_CodeSniffer_File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position)
{
Expand All @@ -55,7 +56,7 @@ public function process(PHP_CodeSniffer_File $file, $position)
return;
}

$file->addError('Getters should have @return tag or return typehint', $position);
$file->addError('Getters should have @return tag or return type.', $position);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ final class VarPropertyCommentSniff extends PHP_CodeSniffer_Standards_AbstractVa
{

/**
* {@inheritdoc}
* @param PHP_CodeSniffer_File $file
* @param int $position
*/
protected function processMemberVar(PHP_CodeSniffer_File $file, $position)
{
$commentString = $this->getPropertyComment($file, $position);

if (strpos($commentString, '{@inheritdoc}') !== FALSE) {
return;
}

if (strpos($commentString, '@var') !== FALSE) {
return;
}
Expand All @@ -43,15 +40,17 @@ protected function processMemberVar(PHP_CodeSniffer_File $file, $position)


/**
* {@inheritdoc}
* @param PHP_CodeSniffer_File $file
* @param int $position
*/
protected function processVariable(PHP_CodeSniffer_File $file, $position)
{
}


/**
* {@inheritdoc}
* @param PHP_CodeSniffer_File $file
* @param int $position
*/
protected function processVariableInString(PHP_CodeSniffer_File $file, $position)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testDetection()
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong2.php'));
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong3.php'));
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct.php'));
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct2.php'));
}

}
15 changes: 15 additions & 0 deletions tests/Sniffs/Commenting/ComponentFactoryComment/correct2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace SomeNamespace;

use SplFileInfo;


class SomeClass
{

protected function createComponentStuffs() : SplFileInfo
{
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function testDetection()
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong4.php'));
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct.php'));
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct2.php'));
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct3.php'));
}

}
9 changes: 8 additions & 1 deletion tests/Sniffs/Commenting/VarPropertyComment/correct2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ class SomeClass
{

/**
* {@inheritdoc}
* @var int
*/
public $count;


public function getSome($count)
{
$count;
$this->count;
}

}
21 changes: 0 additions & 21 deletions tests/Sniffs/Commenting/VarPropertyComment/correct3.php

This file was deleted.

0 comments on commit 2ec4ffb

Please sign in to comment.