Skip to content

Commit 9bf8d30

Browse files
committed
Improve examples
1 parent 47e8fd8 commit 9bf8d30

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

examples/input-output.phpakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Input_Output;
4+
35
/**
46
* Show today's date.
57
*
@@ -20,7 +22,8 @@ function show_date($output) {
2022
* are used, to describe the parameters. These descriptions are displayed with
2123
* command-specific help.
2224
*
23-
* For example, phpake hello-human --help.
25+
* @usage Niki
26+
* @usage Niki Martin
2427
*
2528
* Notice how the in-built parameter $output was kept towards the end.
2629
*

examples/namespace.phpakefile

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace Fizzbuzz;
1010
*
1111
* @param int $n An integer.
1212
* @return string Fizz, buzz, fizzbuzz, or the number.
13-
*
14-
* @see https://en.wikipedia.org/wiki/Fizz_buzz
1513
*/
1614
function _fizzbuzz(int $n): string {
1715
$isFizz = ($n % 3 == 0);
@@ -32,6 +30,27 @@ function _fizzbuzz(int $n): string {
3230
return (string) $n;
3331
}
3432

33+
/**
34+
* Display fizz buzz for a number.
35+
*
36+
* Here's how you do Fizz Buzz.
37+
*
38+
* If the number is divisible by 3, "fizz" is displayed.
39+
* If the number is divisible by 5, "buzz" is displayed.
40+
* If the number is divisible by both, "fizzbuzz" is displayed.
41+
* If the number is divisible by neither, the number is displayed.
42+
*
43+
* See https://en.wikipedia.org/wiki/Fizz_buzz
44+
*
45+
* @usage 3
46+
* @usage 10
47+
* @usage 13
48+
* @usage 15
49+
*
50+
* @param string $n A positive integer.
51+
* @param $output
52+
* @return int|void
53+
*/
3554
function number(string $n, $output) {
3655
if (!is_numeric($n)) {
3756
$output->writeln('<error>n must be a positive integer.</error>');
@@ -48,6 +67,15 @@ function number(string $n, $output) {
4867
$output->writeln("<info>$result</info>");
4968
}
5069

70+
/**
71+
* Display fizz buzz for all numbers from 1 to n.
72+
*
73+
* @usage 20
74+
*
75+
* @param string $n A positive integer.
76+
* @param $output
77+
* @return int|void
78+
*/
5179
function range(string $n, $output) {
5280
if (!is_numeric($n) || $n < 0) {
5381
$output->writeln('<error>n must be a positive integer.</error>');

examples/shell.phpakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Shell;
4+
35
/**
46
* List the contents of the working directory.
57
*
@@ -17,7 +19,7 @@ function ls() {
1719
* Phpake sees them as invalid options/switches. To make it clear that those
1820
* switches are nothing but multiple string arguments, we put -- before them.
1921
*
20-
* @usage phpake ssh example.com john.doe -- "-o ForwardAgent=yes"
22+
* @usage example.com john.doe -- "-o ForwardAgent=yes"
2123
*
2224
* @param string $host A remote host, e.g. example.com
2325
* @param string|null $user A username. Defaults to the current user.

examples/variadic.phpakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* To make the $rest argument optional, you can assign a default value of NULL
1111
* to it. It cannot take any other default values.
1212
*
13+
* @usage India Colombia
14+
* @usage India Colombia Canada
15+
*
1316
* @param string $origin Starting location.
1417
* @param object $output
1518
* @param array $rest Other destinations.

0 commit comments

Comments
 (0)