File tree Expand file tree Collapse file tree 4 files changed +105
-0
lines changed
src/ZenifyCodingStandard/Sniffs/Commenting Expand file tree Collapse file tree 4 files changed +105
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This file is part of Zenify
5+ * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
6+ */
7+
8+ namespace ZenifyCodingStandard \Sniffs \Commenting ;
9+
10+ use PHP_CodeSniffer_File ;
11+ use PHP_CodeSniffer_Standards_AbstractVariableSniff ;
12+
13+
14+ /**
15+ * Rules:
16+ * - Property should have docblock comment.
17+ */
18+ class VarPropertyCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
19+ {
20+
21+ /**
22+ * {@inheritdoc}
23+ */
24+ protected function processMemberVar (PHP_CodeSniffer_File $ file , $ position )
25+ {
26+ $ commentToken = [T_COMMENT , T_DOC_COMMENT_CLOSE_TAG ];
27+ $ commentEnd = $ file ->findPrevious ($ commentToken , $ position );
28+ if ($ commentEnd === FALSE ) {
29+ $ file ->addError ('Property should have docblock comment ' , $ position );
30+ return ;
31+ }
32+ }
33+
34+
35+ /**
36+ * {@inheritdoc}
37+ */
38+ protected function processVariable (PHP_CodeSniffer_File $ file , $ position )
39+ {
40+ }
41+
42+
43+ /**
44+ * {@inheritdoc}
45+ */
46+ protected function processVariableInString (PHP_CodeSniffer_File $ file , $ position )
47+ {
48+ }
49+
50+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Zenify \CodingStandard \Tests \Sniffs \Commenting \VarPropertyComment ;
4+
5+ use PHPUnit_Framework_TestCase ;
6+ use Zenify \CodingStandard \Tests \CodeSnifferRunner ;
7+
8+
9+ class VarPropertyCommentSniffTest extends PHPUnit_Framework_TestCase
10+ {
11+
12+ /**
13+ * @var CodeSnifferRunner
14+ */
15+ private $ codeSnifferRunner ;
16+
17+
18+ protected function setUp ()
19+ {
20+ $ this ->codeSnifferRunner = new CodeSnifferRunner ('ZenifyCodingStandard.Commenting.VarPropertyComment ' );
21+ }
22+
23+
24+ public function testDetection ()
25+ {
26+ $ this ->assertSame (1 , $ this ->codeSnifferRunner ->getErrorCountInFile (__DIR__ . '/wrong.php ' ));
27+ $ this ->assertSame (0 , $ this ->codeSnifferRunner ->getErrorCountInFile (__DIR__ . '/correct.php ' ));
28+ }
29+
30+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace SomeNamespace ;
4+
5+
6+ class SomeClass
7+ {
8+
9+ /**
10+ * @var int
11+ */
12+ public $ count ;
13+
14+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace SomeOtherNamespace ;
4+
5+
6+ class SomeClass
7+ {
8+
9+ public $ count ;
10+
11+ }
You can’t perform that action at this time.
0 commit comments