-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VarPropertyCommentSniff added [closes #22]
- Loading branch information
1 parent
ad843f6
commit 26b6acb
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/ZenifyCodingStandard/Sniffs/Commenting/VarPropertyCommentSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Zenify | ||
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz) | ||
*/ | ||
|
||
namespace ZenifyCodingStandard\Sniffs\Commenting; | ||
|
||
use PHP_CodeSniffer_File; | ||
use PHP_CodeSniffer_Standards_AbstractVariableSniff; | ||
|
||
|
||
/** | ||
* Rules: | ||
* - Property should have docblock comment. | ||
*/ | ||
class VarPropertyCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function processMemberVar(PHP_CodeSniffer_File $file, $position) | ||
{ | ||
$commentToken = [T_COMMENT, T_DOC_COMMENT_CLOSE_TAG]; | ||
$commentEnd = $file->findPrevious($commentToken, $position); | ||
if ($commentEnd === FALSE) { | ||
$file->addError('Property should have docblock comment', $position); | ||
return; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function processVariable(PHP_CodeSniffer_File $file, $position) | ||
{ | ||
} | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function processVariableInString(PHP_CodeSniffer_File $file, $position) | ||
{ | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
tests/Sniffs/Commenting/VarPropertyComment/VarPropertyCommentSniffTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Zenify\CodingStandard\Tests\Sniffs\Commenting\VarPropertyComment; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Zenify\CodingStandard\Tests\CodeSnifferRunner; | ||
|
||
|
||
class VarPropertyCommentSniffTest extends PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @var CodeSnifferRunner | ||
*/ | ||
private $codeSnifferRunner; | ||
|
||
|
||
protected function setUp() | ||
{ | ||
$this->codeSnifferRunner = new CodeSnifferRunner('ZenifyCodingStandard.Commenting.VarPropertyComment'); | ||
} | ||
|
||
|
||
public function testDetection() | ||
{ | ||
$this->assertSame(1, $this->codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong.php')); | ||
$this->assertSame(0, $this->codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct.php')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace SomeNamespace; | ||
|
||
|
||
class SomeClass | ||
{ | ||
|
||
/** | ||
* @var int | ||
*/ | ||
public $count; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace SomeOtherNamespace; | ||
|
||
|
||
class SomeClass | ||
{ | ||
|
||
public $count; | ||
|
||
} |