summaryrefslogtreecommitdiffstats
path: root/sample-commands
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-04-20 11:37:35 +0200
committerJoas Schilling <coding@schilljs.com>2020-04-20 11:37:35 +0200
commit4413ed15c02568974e491d9404ce59758f6ce052 (patch)
treec8d56207663efbcd23ed1987166b1b95f349d322 /sample-commands
parent1607c68f5378569dcde7466c60761fc1026620d0 (diff)
Fix command samples
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'sample-commands')
-rw-r--r--sample-commands/hackernews.php2
-rw-r--r--sample-commands/wikipedia.php7
2 files changed, 5 insertions, 4 deletions
diff --git a/sample-commands/hackernews.php b/sample-commands/hackernews.php
index eea886829..aae000202 100644
--- a/sample-commands/hackernews.php
+++ b/sample-commands/hackernews.php
@@ -45,7 +45,7 @@ $content = file_get_contents($endpoint);
$results = json_decode($content, true);
$stories = array_slice($results, 0, 5);
-$response = 'Hackernews ' . ucfirst($mode) . ' 5:' . "\n";
+$response = 'Hackernews ' . ucfirst($mode) . ' 5:' . "\n";
$length = 120;
foreach ($stories as $storyId) {
diff --git a/sample-commands/wikipedia.php b/sample-commands/wikipedia.php
index 646582330..398f9d1a5 100644
--- a/sample-commands/wikipedia.php
+++ b/sample-commands/wikipedia.php
@@ -52,14 +52,15 @@ $parameters = [
];
$content = file_get_contents($endpoint . '?' . http_build_query($parameters));
$results = json_decode($content, true);
-$pages = $results['query']['pages'];
-$numArticles = count($pages);
-if ($numArticles === 0) {
+if (empty($results['query']['pages'])) {
echo 'Wikipedia did not have any results for "' . $searchTerm . '" :(' . "\n";
return;
}
+$pages = $results['query']['pages'];
+$numArticles = count($pages);
+
$response = 'Wikipedia search results for "' . $searchTerm . '":' . "\n";
$maxArticles = $numArticles > 7 ? 5 : $numArticles;
$length = (int) ((800 - strlen($response)) / $maxArticles);