Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 18 | class CoverFishMessageError extends CoverFishMessage |
||
| 19 | { |
||
| 20 | // reflection problem, cover class is not available during reflection using annotation defined namespace |
||
| 21 | const PHPUNIT_REFLECTION_CLASS_NOT_FOUND = 1000; |
||
| 22 | // reflection problem, cover class method is not available / not found during reflection using annotation defined namespace |
||
| 23 | const PHPUNIT_REFLECTION_METHOD_NOT_FOUND = 2000; |
||
| 24 | // reflection problem, class exists but no public methods available |
||
| 25 | const PHPUNIT_REFLECTION_NO_PUBLIC_METHODS_FOUND = 2001; |
||
| 26 | // reflection problem, class exists but no protected methods available |
||
| 27 | const PHPUNIT_REFLECTION_NO_PROTECTED_METHODS_FOUND = 2002; |
||
| 28 | // reflection problem, class exists but no protected methods available |
||
| 29 | const PHPUNIT_REFLECTION_NO_PRIVATE_METHODS_FOUND = 2003; |
||
| 30 | // reflection problem, class exists but no not public methods available |
||
| 31 | const PHPUNIT_REFLECTION_NO_NOT_PUBLIC_METHODS_FOUND = 2004; |
||
| 32 | // reflection problem, class exists but no not protected methods available |
||
| 33 | const PHPUNIT_REFLECTION_NO_NOT_PROTECTED_METHODS_FOUND = 2005; |
||
| 34 | // reflection problem, class exists but no not private methods available |
||
| 35 | const PHPUNIT_REFLECTION_NO_NOT_PRIVATE_METHODS_FOUND = 2006; |
||
| 36 | // class does not provide any of defined methods in corresponding visibility |
||
| 37 | const PHPUNIT_REFLECTION_CLASS_NOT_DEFINED = 4000; |
||
| 38 | // annotation problem, cover class not found or class part in 'class::method' not available |
||
| 39 | const PHPUNIT_VALIDATOR_PROBLEM = 9000; |
||
| 40 | // annotation problem, defaultCoverClass not found during global method validation |
||
| 41 | const PHPUNIT_VALIDATOR_MISSING_DEFAULT_COVER_CLASS_PROBLEM = 9001; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var array |
||
| 45 | */ |
||
| 46 | public $messageTokens = array( |
||
| 47 | self::PHPUNIT_REFLECTION_CLASS_NOT_FOUND => 'Class not found!', // annotation defined coverClass is not available during reflection, may be the class is not available system wide! |
||
| 48 | self::PHPUNIT_REFLECTION_METHOD_NOT_FOUND => 'Method not found!', // annotation defined method is not available during reflection of corresponding coverClass! |
||
| 49 | self::PHPUNIT_REFLECTION_NO_PUBLIC_METHODS_FOUND => 'no public methods in class!', // method-access/-visibility problem! |
||
| 50 | self::PHPUNIT_REFLECTION_NO_PROTECTED_METHODS_FOUND => 'no protected methods in class!', // method-access/-visibility problem! |
||
| 51 | self::PHPUNIT_REFLECTION_NO_PRIVATE_METHODS_FOUND => 'no private methods in class!', // method-access/-visibility problem! |
||
| 52 | self::PHPUNIT_REFLECTION_NO_NOT_PUBLIC_METHODS_FOUND => 'no not public methods in class!', // method-access/-visibility problem! |
||
| 53 | self::PHPUNIT_REFLECTION_NO_NOT_PROTECTED_METHODS_FOUND => 'no not protected methods in class!', // method-access/-visibility problem! |
||
| 54 | self::PHPUNIT_REFLECTION_NO_NOT_PRIVATE_METHODS_FOUND => 'no not private methods in class!', // method-access/-visibility problem! |
||
| 55 | self::PHPUNIT_REFLECTION_CLASS_NOT_DEFINED => 'Class not defined!', // class not defined, not found in use statement |
||
| 56 | self::PHPUNIT_VALIDATOR_PROBLEM => 'cover Annotation problem!', // cover annotation spelling/validation error |
||
| 57 | self::PHPUNIT_VALIDATOR_MISSING_DEFAULT_COVER_CLASS_PROBLEM => 'defaultCoverClass Annotation missing!', // defaultCoverClass annotation spelling/validation error |
||
| 58 | ); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param CoverFishMapping $coverMapping |
||
| 62 | * @param bool|false $noAnsiColors |
||
| 63 | * |
||
| 64 | * @return null|string |
||
| 65 | */ |
||
| 66 | public function getErrorStreamTemplate(CoverFishMapping $coverMapping, $noAnsiColors = false) |
||
| 137 | } |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.