BaseMax / BaseMax/GooglePlayWebServiceAPI

Consistency in return values

未關閉
#15 15 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
42
分支
9
PR 合併指標
30 天內沒有已合併 PR

描述

During my recent implementations and rewrites, I've introduced some "error reporting" to make it easier for the caller to figure if and what might have gone wrong. On error, several methods now return an array like

```php
[success:0, message:"reason"]
```

But not all of them – for example, most of the search/browse methods supposed to return a simple array of package names don't have this. There would be two options to reach (a sort of) consistency:

* returning `[success:0, message:reason]` instead (and if so, include `success:1` with a "good result) also for those methods that currently do not, moving the "real results" into a "sub-array" (which then, on error, could be empty or just not present at all)
* simply returning an empty array, and have a `getLastError()` method for obtaining the reason ***for all search/browse methods*** while keeping the current behavior for the others.

I'd prefer the first approach (so it's completely consistent) with the "empty real result". This combines the best of two worlds, e.g.

```php
$apps = $google->parseWhatever();
if ( empty($apps['data']) ) { // this could simply mean nothing found matching the criteria
if ( $apps['success'] ) { log('nothing found'); }
else { log ('ERROR occured: '.$apps['message']); }
} else { // do something with the data
```

I'd even go as far as to always include the `message` key, just leaving its value empty on success. That would make things most consistent.

What's your stance? If you agree, I'd go over the entire class another time and make it consistent:

* `success:0` only on *errors* – not generally on "no results" for a user-specified search (I vaguely remember I accidentally made it such in one case). `message` then holds the reason (e.g. the HTTP response, or parse error when an expected pattern didn't match, etc)
* `success:1` on success. `message` then is present but usually empty, but might eg hold a hint on why the result set is empty (like "no hits").

If we want to fix it, we want to do that as early as possible – before there are users whose code would otherwise break on some update.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

檢視整個類別,尤其是搜尋和瀏覽方法,並將它們目前的回傳值與 issue 中描述的錯誤回報方法進行比較。首先就一個回應契約達成共識;完成表示所有受影響的方法都一致地遵循該契約,且不讓相容性決策處於未解決狀態。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
php
領域
api, backend-api-design
Issue 類型
重構
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
20/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。