-
Notifications
You must be signed in to change notification settings - Fork 0
PHPDoc tags and annotations
@example
のような@
を伴った記法は「タグ」または「アノテーション」と呼ばれます。これらは似たものですが、違った特徴があります。
DocCommentはクラス・関数・メソッド・プロパティなどに記述することができる特殊なコメントです。通常のブロックコメントは /* … */
ですが、DocCommentは必ず /** … */
です。
ReflectionClass::getDocComment()
ReflectionClassConstant::getDocComment
ReflectionFunctionAbstract::getDocComment
ReflectionProperty::getDocComment
<?php
// This is NOT DocComment
class A {}
/*
* This is NOT DocComment
*/
class B {}
/**
* This is DocComment!!!!
*/
class C {}
$a = new ReflectionClass(A::class);
var_dump($a->getDocComment());
// => bool(false)
$b = new ReflectionClass(B::class);
var_dump($b->getDocComment());
// => bool(false)
$c = new ReflectionClass(C::class);
var_dump($c->getDocComment());
// => string(33) "/**
// * This is DocComment!!!!
// */"
/**
* @Annotation
* @Target("CLASS")
*/
アノテーションは主にDoctrineによって導入されました。それは括弧()
を伴った複雑な式を含むことがあります。アノテーションは典型的には大文字アルファベットとバックスラッシュ\
から構成されるので、タグとは少し違った特徴があります。
Doctrineによる定義はDoctrine Annotationsにあります。パーサーの実装はdoctrine/annotations: Annotations Docblock Parserです。
/**
* @deprecated
* @license MIT
*/
タグの文法はアノテーションに比べて比較的単純です。トークンは基本的にスペース
で分割されるので、構文解析は基本的に容易です。 (ただし、それぞれのタグに固有の癖に対処しなければいけません)
これらのタグはList of tagsとTag referenceで定義されます。
@api
@author
@category
@copyright
@deprecated
@example
@filesource
@global
@ignore
@internal
@license
@link
@method
@package
@param
@property
@property-read
@property-write
@return
@see
@since
@source
@subpackage
@throws
@todo
-
@uses
and@used-by
@var
@version
これらのタグはAnnotating Your Source Code · phan/phan Wikiで定義されます。
@var
@param
@return
@method
@deprecated
@internal
@suppress
@property
@override
@phan-closure-scope
独自実装されたこれらのタグは統一された文書がないので、完全なリストはありません。
@mixin
-
@noinspection
- Phanの
@suppress
に似ますが、書ける引数は(当然)異なります - https://gist.github.com/discordier/ed4b9cba14652e7212f5#file-gistfile1-txt-L97
- Phanの
これらのタグはPHPUnit Manual – Appendix B. Annotationsで定義されます。
@author
@after
@afterClass
@backupGlobals
@backupStaticAttributes
@before
@beforeClass
@codeCoverageIgnore*
@covers
@coversDefaultClass
@coversNothing
@dataProvider
@depends
@expectedException
@expectedExceptionCode
@expectedExceptionMessage
@expectedExceptionMessageRegExp
@group
@large
@medium
@preserveGlobalState
@requires
@runTestsInSeparateProcesses
@runInSeparateProcess
@small
@test
@testdox
@ticket
@uses
phpcsの検査から除外されるためのコメント表記です。ただし、DocCommentではなく、通常のコメントに記述します。これらの表記はAdvanced Usage · squizlabs/PHP_CodeSniffer Wikiに記載されます。
@codingStandardsIgnoreFile
-
@codingStandardsIgnoreStart
and@codingStandardsIgnoreEnd
@codingStandardsIgnoreLine