Open lenaorobei opened 5 years ago
<?php
namespace Foo\Bar;
interface TestInterface
{
/**
* Test Function with nice Doc
*
* @param $int
* @param $string
* @return string
*/
public function test($int, $string);
}
class Test implements TestInterface
{
/**
* @inheritDoc
*/
public function test($int, $string)
{
return '';
}
/**
* Test Function with nice Doc.
*
* @param $string
* @return string
*/
public function test2($string)
{
return '';
}
}
class TestExtend extends Test implements TestInterface
{
/**
* Test Function with a better Function.
*
* {@inheritDoc}
*/
public function test($int, $string)
{
return '';
}
/**
* Sniff will find doc error there because you define inherit wrong.
* @inheritDoc
*/
public function test2($string)
{
return '';
}
}
@larsroettig, few comments to your example:
The
@inheritdoc
tag SHOULD NOT be used.The declaration of the return type using the
@return
tag must only be added if the method return type signature does not supply all necessary information (see below for more information on return types).Declaration of possibly thrown exception using @throws tag, if the actual body of function triggers throwing an exception. All occurrences of @throws in a DocBlock must be after any @param and @return annotations.
Test should NOT fail. This example contains negative scenarios:
<?php
class EverythingIsGoodHere
{
/**
* @param string $arg1
* @param bool $arg2
*/
private function missingArgumentTypeSoParamsNeedToBeAdded($arg1, $arg2): bool
{
}
/**
* @return bool
*/
private function presentArgumentTypeSoAnnotationNotNeededButMissingReturnType(string $arg1, bool $arg2)
{
}
private function presentArgumentAndReturnTypes(string $arg1, bool $arg2): bool
{
}
/**
* @throws Exception
*/
private function throwsAnException(): void
{
throw new \Exception();
}
/**
* We have an additional wonderful message here.
*
* @return void
*/
private function presentGoodDescription(string $arg1, bool $arg2)
{
}
}
Test should fail: This example contains positive scenarios:
<?php
class EverythingIsBadHere
{
/**
* @param bool $arg2
* @param string $arg1
*/
private function wrongParamOrder($arg1, $arg2): bool
{
}
/**
* @param bool $arg2
*/
private function missingParamAnnotation($arg1, $arg2): bool
{
}
private function missingArgumentAnnotations($arg1, $arg2): bool
{
}
/**
* @param string $arg1
* @param bool $arg2
* @param bool $arg2
*/
private function paramDuplication($arg1, $arg2): bool
{
}
/**
* @inheritdoc
*/
private function inheritDocShouldNotBeUsed(string $arg1, bool $arg2)
{
}
/**
* @param $arg1
* @param $arg2
*/
private function missingParamType($arg1, $arg2): bool
{
}
/**
* Useless description
*/
private function uselessDescription(string $arg1, bool $arg2): bool
{
}
/**
*
*/
private function dockBlockIsEmpty(string $arg1, bool $arg2): bool
{
}
/**
*
*
* @param string $arg1
* @param bool $arg2
*
*/
private function redundantLines($arg1, $arg2): bool
{
}
}
@Vinai would appreciate much if you could review these examples.
Rule
PHPDoc formatting for functions and methods.
Acceptance Criteria: