-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commenting/FileComment: allow for namespaced procedural files
The `Yoast.Commenting.FileComment` sniff would previously demand a file docblock for non-namespaced files and recommend a file docblock be removed for namespaced files. This is all well and good for namespaced files containing an OO declaration, where the OO structure will generally have a docblock, but for namespaced procedural files, this might mean the file will end up having no documentation whatsoever, which could be counter-productive. While namespaced procedural files are not that common in the Yoast codebases, typically a PHPUnit bootstrap file may be a namespaced procedural file. This commit updates the sniff to only recommend removing the file docblock if the file _also_ contains a named OO declaration. For namespaced files which don't contain an OO declaration, the file docblock will still be allowed (but not required) and will no longer be flagged as unnecessary. If a docblock is found in such a file, it will be checked for compliance with file docblock rules like any other file docblock. Includes ample tests. Includes updated XML documentation.
- Loading branch information
Showing
27 changed files
with
324 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
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
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,20 @@ | ||
<?php | ||
/** | ||
* File Comment for a file without a namespace. | ||
* | ||
* For the purposes of the unit test, the docblock here needs to comply with the | ||
* complete Squiz file comment rules as the ruleset is not taken into account | ||
* when unit testing sniffs. | ||
* | ||
* @package Some\Package | ||
* @subpackage Something\Else | ||
* @author Squiz Pty Ltd <[email protected]> | ||
* @copyright 2018 Squiz Pty Ltd (ABN 77 084 670 600) | ||
*/ | ||
|
||
/** | ||
* Interface docblock. | ||
*/ | ||
interface Testing { | ||
public function test(); | ||
} |
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,9 @@ | ||
<?php | ||
|
||
/** | ||
* Interface docblock. No namespace, file comment is needed, but missing. | ||
*/ | ||
interface Testing { | ||
public function test(); | ||
} | ||
|
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 Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Interface docblock. A file docblock is not needed in a namespaced file containing an OO structure. | ||
*/ | ||
interface Testing { | ||
public function test(); | ||
} | ||
|
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,15 @@ | ||
<?php | ||
/** | ||
* File Comment for a file WITH a namespace and containing an OO structure. This should be flagged as unnecessary. | ||
* | ||
* @package Some\Package | ||
*/ | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Interface docblock. | ||
*/ | ||
interface Testing { | ||
public function test(); | ||
} |
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,22 @@ | ||
<?php | ||
/** | ||
* File Comment for a file without a namespace. | ||
* | ||
* For the purposes of the unit test, the docblock here needs to comply with the | ||
* complete Squiz file comment rules as the ruleset is not taken into account | ||
* when unit testing sniffs. | ||
* | ||
* @package Some\Package | ||
* @subpackage Something\Else | ||
* @author Squiz Pty Ltd <[email protected]> | ||
* @copyright 2018 Squiz Pty Ltd (ABN 77 084 670 600) | ||
*/ | ||
|
||
/** | ||
* Trait docblock. | ||
*/ | ||
trait Testing { | ||
public function test() { | ||
echo namespace\SomeClass::$static_property; // This is not a namespace declaration, but use of the namespace operator. | ||
} | ||
} |
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,6 @@ | ||
<?php | ||
|
||
/** | ||
* Trait docblock. No namespace, file comment is needed, but missing. | ||
*/ | ||
trait Testing {} |
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,8 @@ | ||
<?php | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Trait docblock. A file docblock is not needed in a namespaced file containing an OO structure. | ||
*/ | ||
trait Testing {} |
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
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,13 @@ | ||
<?php | ||
/** | ||
* File Comment for a file WITH a namespace and containing an OO structure. This should be flagged as unnecessary. | ||
* | ||
* @package Some\Package | ||
*/ | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Trait docblock. | ||
*/ | ||
trait Testing {} |
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,22 @@ | ||
<?php | ||
/** | ||
* File Comment for a file without a namespace. | ||
* | ||
* For the purposes of the unit test, the docblock here needs to comply with the | ||
* complete Squiz file comment rules as the ruleset is not taken into account | ||
* when unit testing sniffs. | ||
* | ||
* @package Some\Package | ||
* @subpackage Something\Else | ||
* @author Squiz Pty Ltd <[email protected]> | ||
* @copyright 2018 Squiz Pty Ltd (ABN 77 084 670 600) | ||
*/ | ||
|
||
/** | ||
* Enum docblock. | ||
*/ | ||
enum Testing { | ||
public function test() { | ||
echo namespace\SomeClass::$static_property; // This is not a namespace declaration, but use of the namespace operator. | ||
} | ||
} |
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,6 @@ | ||
<?php | ||
|
||
/** | ||
* Enum docblock. No namespace, file comment is needed, but missing. | ||
*/ | ||
enum Testing {} |
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,8 @@ | ||
<?php | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Enum docblock. A file docblock is not needed in a namespaced file containing an OO structure. | ||
*/ | ||
enum Testing {} |
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,13 @@ | ||
<?php | ||
/** | ||
* File Comment for a file WITH a namespace and containing an OO structure. This should be flagged as unnecessary. | ||
* | ||
* @package Some\Package | ||
*/ | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
/** | ||
* Enum docblock. | ||
*/ | ||
enum Testing {} |
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,22 @@ | ||
<?php | ||
/** | ||
* File Comment for a file without a namespace and without OO structure. | ||
* | ||
* For the purposes of the unit test, the docblock here needs to comply with the | ||
* complete Squiz file comment rules as the ruleset is not taken into account | ||
* when unit testing sniffs. | ||
* | ||
* @package Some\Package | ||
* @subpackage Something\Else | ||
* @author Squiz Pty Ltd <[email protected]> | ||
* @copyright 2018 Squiz Pty Ltd (ABN 77 084 670 600) | ||
*/ | ||
|
||
do_something(); | ||
|
||
/** | ||
* Function docblock. | ||
*/ | ||
function test() { | ||
echo namespace\SomeClass::$static_property; // This is not a namespace declaration, but use of the namespace operator. | ||
} |
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,8 @@ | ||
<?php | ||
|
||
/** | ||
* Function docblock. No namespace, file comment is needed, but missing. | ||
*/ | ||
function test() {} | ||
|
||
do_something(); |
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,10 @@ | ||
<?php | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
do_something(); | ||
|
||
/** | ||
* Function docblock. A file docblock is not needed in a namespaced file, but also not forbidden if the file doesn't contain an OO structure. | ||
*/ | ||
function testing() {} |
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,22 @@ | ||
<?php | ||
/** | ||
* File Comment for a file WITH a namespace, but NOT containing an OO structure. This should NOT be flagged as unnecessary. | ||
* | ||
* For the purposes of the unit test, the docblock here needs to comply with the | ||
* complete Squiz file comment rules as the ruleset is not taken into account | ||
* when unit testing sniffs. | ||
* | ||
* @package Some\Package | ||
* @subpackage Something\Else | ||
* @author Squiz Pty Ltd <[email protected]> | ||
* @copyright 2018 Squiz Pty Ltd (ABN 77 084 670 600) | ||
*/ | ||
|
||
namespace Yoast\Plugin\Sub; | ||
|
||
use Ab\C; | ||
|
||
/** | ||
* Function docblock. | ||
*/ | ||
function test() {} |
Oops, something went wrong.