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 |
||
27 | class TokenReader |
||
28 | { |
||
29 | /** |
||
30 | * Validate and decode a JSON Web Token string |
||
31 | * |
||
32 | * @param string $keyName name of the key to used to sign the token |
||
33 | * @param string $token the token string to validate and decode |
||
34 | * @param array|\Traversable $assertClaims traversable set of claims, claim => value, to assert |
||
35 | * |
||
36 | * @return object|false payload as stdClass, or false if token was invalid |
||
37 | */ |
||
38 | 1 | public static function fromString($keyName, $token, $assertClaims = array()) |
|
43 | |||
44 | /** |
||
45 | * Validate and decode a JSON Web Token string from a cookie |
||
46 | * |
||
47 | * @param string $keyName name of the key to used to sign the token |
||
48 | * @param string $cookieName name of cookie that sources the token |
||
49 | * @param array|\Traversable $assertClaims traversable set of claims, claim => value, to assert |
||
50 | * |
||
51 | * @return object|false payload as stdClass, or false if token was invalid |
||
52 | */ |
||
53 | View Code Duplication | public static function fromCookie($keyName, $cookieName, $assertClaims = array()) |
|
61 | |||
62 | /** |
||
63 | * Validate and decode a JSON Web Token string from a request (i.e. POST body) |
||
64 | * |
||
65 | * @param string $keyName name of the key to used to sign the token |
||
66 | * @param string $attributeName name of cookie that sources the token |
||
67 | * @param array|\Traversable $assertClaims traversable set of claims, claim => value, to assert |
||
68 | * |
||
69 | * @return object|false payload as stdClass, or false if token was invalid |
||
70 | */ |
||
71 | View Code Duplication | public static function fromRequest($keyName, $attributeName, $assertClaims = array()) |
|
79 | |||
80 | /** |
||
81 | * Validate and decode a JSON Web Token string from a header |
||
82 | * |
||
83 | * @param string $keyName name of the key to used to sign the token |
||
84 | * @param array|\Traversable $assertClaims traversable set of claims, claim => value, to assert |
||
85 | * @param string $headerName name of header that sources the token |
||
86 | * |
||
87 | * @return object|false payload as stdClass, or false if token was invalid |
||
88 | */ |
||
89 | public static function fromHeader($keyName, $assertClaims = array(), $headerName = 'Authorization') |
||
103 | } |
||
104 |