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 |
||
| 5 | class XgPusher |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The XingeApp instance. |
||
| 9 | * |
||
| 10 | * @var \XingeApp |
||
| 11 | */ |
||
| 12 | protected $service; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create a new instance. |
||
| 16 | */ |
||
| 17 | public function __construct() |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Get the XingeApp instance. |
||
| 24 | * |
||
| 25 | * @return \XingeApp |
||
| 26 | */ |
||
| 27 | public function getService() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Create a XingeApp instance. |
||
| 34 | * |
||
| 35 | * @return \XingeApp |
||
| 36 | */ |
||
| 37 | public static function createService() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get the app key. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public static function appKey() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the app secret. |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public static function appSecret() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get the custom key. |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | public static function customKey() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the environment. |
||
| 74 | * |
||
| 75 | * environment: 向iOS设备推送时必填,1表示推送生产环境;2表示推送开发环境。推送Android平台不填或填0. |
||
| 76 | * |
||
| 77 | * @return int |
||
| 78 | */ |
||
| 79 | public static function environment() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * 解析信鸽返回的结果。 |
||
| 88 | * |
||
| 89 | * @see http://developer.qq.com/wiki/xg/%E6%9C%8D%E5%8A%A1%E7%AB%AFAPI%E6%8E%A5%E5%85%A5/Rest%20API%20%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/Rest%20API%20%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.html |
||
| 90 | * |
||
| 91 | * @param mixed $xgResult 信鸽的请求结果 |
||
| 92 | * @param int &$code 返回码,0 为成功 |
||
| 93 | * @param string &$message 请求出错时的错误信息 |
||
| 94 | * @param mixed &$result 请求正确时的额外数据 |
||
| 95 | * @return bool |
||
| 96 | */ |
||
| 97 | public static function parseResult($xgResult = null, &$code = null, &$message = null, &$result = null) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Encode the custom data. |
||
| 114 | * |
||
| 115 | * @param mixed $data |
||
| 116 | * @return array|null |
||
| 117 | */ |
||
| 118 | public static function encodeCustomData($data) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Get Xinge account for the given user. |
||
| 125 | * |
||
| 126 | * @param mixed $user |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | public static function accountForUser($user) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Creates a MessageIOS instance. |
||
| 148 | * |
||
| 149 | * @param string $alert |
||
| 150 | * @param mixed $custom |
||
| 151 | * @param int $badge |
||
| 152 | * @param string $sound |
||
| 153 | * @return MessageIOS |
||
| 154 | */ |
||
| 155 | public static function createIOSMessage($alert = '', $custom = null, $badge = 1, $sound = 'default') |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Create a Message instance. |
||
| 174 | * |
||
| 175 | * @param string $content |
||
| 176 | * @param mixed $custom |
||
| 177 | * @param string $title |
||
| 178 | * @param int $type |
||
| 179 | * @return Message |
||
| 180 | */ |
||
| 181 | public static function createAndroidMessage($content = '', $custom = null, $title = null, $type = Message::TYPE_NOTIFICATION) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Query all device tokens for the given user. |
||
| 201 | * |
||
| 202 | * @param mixed $user |
||
| 203 | * @return string[]|null |
||
| 204 | */ |
||
| 205 | View Code Duplication | public static function queryDeviceTokensForUser($user) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * Query all tags for the given device token. |
||
| 216 | * |
||
| 217 | * @param string $deviceToken |
||
| 218 | * @return string[]|null |
||
| 219 | */ |
||
| 220 | View Code Duplication | public static function queryTagsForDeviceToken($deviceToken) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Query all tags for the given user. |
||
| 231 | * |
||
| 232 | * @param mixed $user |
||
| 233 | * @param array &$deviceTokens |
||
| 234 | * @return array|null |
||
| 235 | */ |
||
| 236 | public static function queryTagsForUser($user, &$deviceTokens = null) |
||
| 249 | } |
||
| 250 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..