Merge pull request #5770 from kenjis/fix-docs-comment-style

docs: change comment style in sample code
This commit is contained in:
kenjis 2022-03-04 18:50:35 +09:00 committed by GitHub
commit d38ae6010c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 261 additions and 278 deletions

View File

@ -5,7 +5,8 @@ $pad = $this->getPad($this->options, 6);
foreach ($this->options as $option => $description) {
CLI::write($tab . CLI::color(str_pad($option, $pad), 'green') . $description, 'yellow');
}
// Output will be
// -n Set migration namespace
// -r override file
/*
* Output will be:
* -n Set migration namespace
* -r override file
*/

View File

@ -1,10 +1,11 @@
<?php
$fruit = CLI::promptByKey('These are your choices:', ['The red apple', 'The plump orange', 'The ripe banana']);
//These are your choices:
// [0] The red apple
// [1] The plump orange
// [2] The ripe banana
//
//[0, 1, 2]:
/*
* These are your choices:
* [0] The red apple
* [1] The plump orange
* [2] The ripe banana
*
* [0, 1, 2]:
*/

View File

@ -5,10 +5,11 @@ $fruit = CLI::promptByKey(['These are your choices:', 'Which would you like?'],
'orange' => 'The plump orange',
'banana' => 'The ripe banana'
]);
//These are your choices:
// [apple] The red apple
// [orange] The plump orange
// [banana] The ripe banana
//
//Which would you like? [apple, orange, banana]:
/*
* These are your choices:
* [apple] The red apple
* [orange] The plump orange
* [banana] The ripe banana
*
* Which would you like? [apple, orange, banana]:
*/

View File

@ -1,6 +1,7 @@
<?php
$query = $builder->get(10, 20);
// Executes: SELECT * FROM mytable LIMIT 20, 10
// (in MySQL. Other databases have slightly different syntax)
/*
* Executes: SELECT * FROM mytable LIMIT 20, 10
* (in MySQL. Other databases have slightly different syntax)
*/

View File

@ -1,10 +1,12 @@
<?php
echo $builder->limit(10,20)->getCompiledSelect(false);
// Prints string: SELECT * FROM mytable LIMIT 20, 10
// (in MySQL. Other databases have slightly different syntax)
/*
* Prints string: SELECT * FROM mytable LIMIT 20, 10
* (in MySQL. Other databases have slightly different syntax)
*/
echo $builder->select('title, content, date')->getCompiledSelect();
// Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10
/*
* Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10
*/

View File

@ -4,6 +4,7 @@ $builder = $db->table('blogs');
$builder->select('*');
$builder->join('comments', 'comments.id = blogs.id');
$query = $builder->get();
// Produces:
// SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
/*
* Produces:
* SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
*/

View File

@ -10,6 +10,7 @@ $builder->select('*')->from('my_table')
->groupEnd()
->where('d', 'd')
->get();
// Generates:
// SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
/*
* Generates:
* SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
*/

View File

@ -8,8 +8,9 @@ $data = [
$builder->where('id', $id);
$builder->update($data);
// Produces:
//
// UPDATE mytable
// SET title = '{$title}', name = '{$name}', date = '{$date}'
// WHERE id = $id
/*
* Produces:
* UPDATE mytable
* SET title = '{$title}', name = '{$name}', date = '{$date}'
* WHERE id = $id
*/

View File

@ -10,8 +10,9 @@ class Myclass
$object = new Myclass;
$builder->where('id', $id);
$builder->update($object);
// Produces:
//
// UPDATE `mytable`
// SET `title` = '{$title}', `name` = '{$name}', `date` = '{$date}'
// WHERE id = `$id`
/*
* Produces:
* UPDATE `mytable`
* SET `title` = '{$title}', `name` = '{$name}', `date` = '{$date}'
* WHERE id = `$id`
*/

View File

@ -14,14 +14,15 @@ $data = [
];
$builder->updateBatch($data, 'title');
// Produces:
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title')
/*
* Produces:
* UPDATE `mytable` SET `name` = CASE
* WHEN `title` = 'My title' THEN 'My Name 2'
* WHEN `title` = 'Another title' THEN 'Another Name 2'
* ELSE `name` END,
* `date` = CASE
* WHEN `title` = 'My title' THEN 'My date 2'
* WHEN `title` = 'Another title' THEN 'Another date 2'
* ELSE `date` END
* WHERE `title` IN ('My title','Another title')
*/

View File

@ -1,4 +1,4 @@
<?php
$builder->delete(['id' => $id]);
// Produces: // DELETE FROM mytable // WHERE id = $id
// Produces: DELETE FROM mytable WHERE id = $id

View File

@ -2,7 +2,8 @@
$builder->where('id', $id);
$builder->delete();
// Produces:
// DELETE FROM mytable
// WHERE id = $id
/*
* Produces:
* DELETE FROM mytable
* WHERE id = $id
*/

View File

@ -1,6 +1,7 @@
<?php
$builder->truncate();
// Produce:
// TRUNCATE mytable
/*
* Produce:
* TRUNCATE mytable
*/

View File

@ -11,6 +11,7 @@ $sql = $builder->select(['field1','field2'])
// ...
$data = $builder->get()->getResultArray();
// Would execute and return an array of results of the following query:
// SELECT field1, field1 from mytable where field3 = 5;
/*
* Would execute and return an array of results of the following query:
* SELECT field1, field1 from mytable where field3 = 5;
*/

View File

@ -1,5 +1,7 @@
<?php
$forge->createDatabase('my_db', true);
// gives CREATE DATABASE IF NOT EXISTS `my_db`
// or will check if a database exists
/*
* gives CREATE DATABASE IF NOT EXISTS `my_db`
* or will check if a database exists
*/

View File

@ -2,12 +2,13 @@
// using the same data from above
$flattened = array_flatten_with_dots($arrayToFlatten, 'foo_');
// $flattened is now:
[
'foo_personal.first_name' => 'john',
'foo_personal.last_name' => 'smith',
'foo_personal.age' => '26',
'foo_personal.address' => 'US',
'foo_other_details' => 'marines officer',
];
/*
* $flattened is now:
* [
* 'foo_personal.first_name' => 'john',
* 'foo_personal.last_name' => 'smith',
* 'foo_personal.age' => '26',
* 'foo_personal.address' => 'US',
* 'foo_other_details' => 'marines officer',
* ]
*/

View File

@ -7,11 +7,9 @@ $data = [
];
echo form_hidden($data);
/*
Would produce:
<input type="hidden" name="name" value="John Doe" />
<input type="hidden" name="email" value="john@example.com" />
<input type="hidden" name="url" value="http://example.com" />
*/
* Would produce:
* <input type="hidden" name="name" value="John Doe" />
* <input type="hidden" name="email" value="john@example.com" />
* <input type="hidden" name="url" value="http://example.com" />
*/

View File

@ -7,11 +7,9 @@ $data = [
];
echo form_hidden('my_array', $data);
/*
Would produce:
<input type="hidden" name="my_array[name]" value="John Doe" />
<input type="hidden" name="my_array[email]" value="john@example.com" />
<input type="hidden" name="my_array[url]" value="http://example.com" />
*/
* Would produce:
* <input type="hidden" name="my_array[name]" value="John Doe" />
* <input type="hidden" name="my_array[email]" value="john@example.com" />
* <input type="hidden" name="my_array[url]" value="http://example.com" />
*/

View File

@ -9,9 +9,7 @@ $data = [
];
echo form_input($data);
/*
Would produce:
<input type="hidden" name="email" value="john@example.com" id="hiddenemail" class="hiddenemail" />
*/
* Would produce:
* <input type="hidden" name="email" value="john@example.com" id="hiddenemail" class="hiddenemail" />
*/

View File

@ -10,9 +10,7 @@ $data = [
];
echo form_input($data);
/*
Would produce:
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
*/
* Would produce:
* <input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
*/

View File

@ -1,9 +1,7 @@
<?php
echo form_input('email', 'joe@example.com', ['placeholder' => 'Email Address...'], 'email');
/*
Would produce:
<input type="email" name="email" value="joe@example.com" placeholder="Email Address..." />
*/
* Would produce:
* <input type="email" name="email" value="joe@example.com" placeholder="Email Address..." />
*/

View File

@ -9,27 +9,23 @@ $options = [
$shirts_on_sale = ['small', 'large'];
echo form_dropdown('shirts', $options, 'large');
/*
Would produce:
<select name="shirts">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
*/
* Would produce:
* <select name="shirts">
* <option value="small">Small Shirt</option>
* <option value="med">Medium Shirt</option>
* <option value="large" selected="selected">Large Shirt</option>
* <option value="xlarge">Extra Large Shirt</option>
* </select>
*/
echo form_dropdown('shirts', $options, $shirts_on_sale);
/*
Would produce:
<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
*/
* Would produce:
* <select name="shirts" multiple="multiple">
* <option value="small" selected="selected">Small Shirt</option>
* <option value="med">Medium Shirt</option>
* <option value="large" selected="selected">Large Shirt</option>
* <option value="xlarge">Extra Large Shirt</option>
* </select>
*/

View File

@ -2,14 +2,12 @@
$string = "Here is a simple string of text that will help us demonstrate this function.";
echo word_wrap($string, 25);
/*
Would produce:
Here is a simple string
of text that will help us
demonstrate this
function.
Excessively long words will be split, but URLs will not be.
*/
* Would produce:
* Here is a simple string
* of text that will help us
* demonstrate this
* function.
*
* Excessively long words will be split, but URLs will not be.
*/

View File

@ -1,9 +1,8 @@
<?php
/*
Folder and file structure:
\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
* Folder and file structure:
* \<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
*/
$routes->get('helloworld', '\App\Controllers\HelloWorld::index');

View File

@ -1,14 +1,14 @@
<?php
/*
With a request body of:
{
"foo": "bar",
"fizz": {
"buzz": "baz"
}
}
*/
* With a request body of:
* {
* "foo": "bar",
* "fizz": {
* "buzz": "baz"
* }
* }
*/
$data = $request->getVar('foo');
// $data = "bar"

View File

@ -3,10 +3,9 @@
var_dump($request->getRawInput());
/*
Outputs:
[
'Param1' => 'Value1',
'Param2' => 'Value2',
]
*/
* Outputs:
* [
* 'Param1' => 'Value1',
* 'Param2' => 'Value2',
* ]
*/

View File

@ -3,11 +3,10 @@
var_dump($request->headers());
/*
Outputs:
[
'Host' => CodeIgniter\HTTP\Header,
'Cache-Control' => CodeIgniter\HTTP\Header,
'Accept' => CodeIgniter\HTTP\Header,
]
*/
* Outputs:
* [
* 'Host' => CodeIgniter\HTTP\Header,
* 'Cache-Control' => CodeIgniter\HTTP\Header,
* 'Accept' => CodeIgniter\HTTP\Header,
* ]
*/

View File

@ -1,25 +1,22 @@
<?php
echo $message->header('Accept-Language');
/*
Outputs something like:
'Accept-Language: en,en-US'
*/
* Outputs something like:
* 'Accept-Language: en,en-US'
*/
echo $message->header('Accept-Language')->getValue();
/*
Outputs something like:
[
'en',
'en-US'
]
*/
* Outputs something like:
* [
* 'en',
* 'en-US',
* ]
*/
echo $message->header('Accept-Language')->getValueLine();
/*
Outputs something like:
'en,en-US'
*/
* Outputs something like:
* en,en-US'
*/

View File

@ -1,8 +1,7 @@
<?php
echo $message->getHeaderLine('Accept-Language');
/*
Outputs:
'en,en-US'
*/
* Outputs:
* 'en,en-US'
*/

View File

@ -1,11 +1,9 @@
<?php
$client->request('GET', 'http://example.com', ['allow_redirects' => true]);
/*
Sets the following defaults:
'max' => 5, // Maximum number of redirects to follow before stopping
'strict' => true, // Ensure POST requests stay POST requests through redirects
'protocols' => ['http', 'https'] // Restrict redirects to one or more protocols
*/
* Sets the following defaults:
* 'max' => 5, // Maximum number of redirects to follow before stopping
* 'strict' => true, // Ensure POST requests stay POST requests through redirects
* 'protocols' => ['http', 'https'] // Restrict redirects to one or more protocols
*/

View File

@ -3,11 +3,10 @@
$segments = $uri->getSegments();
/*
Produces:
[
0 => 'users',
1 => '15',
2 => 'profile',
]
*/
* Produces:
* [
* 0 => 'users',
* 1 => '15',
* 2 => 'profile',
* ]
*/

View File

@ -1,22 +1,21 @@
<?php
/*
The data to test:
[
'contacts' => [
'name' => 'Joe Smith',
'friends' => [
[
'name' => 'Fred Flinstone',
],
[
'name' => 'Wilma',
],
]
]
]
*/
* The data to test:
* [
* 'contacts' => [
* 'name' => 'Joe Smith',
* 'friends' => [
* [
* 'name' => 'Fred Flinstone',
* ],
* [
* 'name' => 'Wilma',
* ],
* ]
* ]
* ]
*/
// Joe Smith
$validation->setRules([

View File

@ -1,16 +1,15 @@
<?php
/*
The data to test:
[
'user_ids' => [
1,
2,
3,
]
]
*/
* The data to test:
* [
* 'user_ids' => [
* 1,
* 2,
* 3,
* ]
* ]
*/
// Rule
$validation->setRules([

View File

@ -1,12 +1,10 @@
<?php
$errors = $validation->getErrors();
/*
Produces:
[
'field1' => 'error message',
'field2' => 'error message',
]
*/
* Produces:
* [
* 'field1' => 'error message',
* 'field2' => 'error message',
* ]
*/

View File

@ -1,13 +1,12 @@
<?php
/*
For errors:
[
'foo.0.bar' => 'Error',
'foo.baz.bar' => 'Error',
]
*/
* For errors:
* [
* 'foo.0.bar' => 'Error',
* 'foo.baz.bar' => 'Error',
* ]
*/
// returns true
$validation->hasError('foo.*.bar');

View File

@ -10,16 +10,15 @@ class SomeHandler extends BaseCast
{
var_dump($params);
/*
Output:
array(3) {
[0]=>
string(13) "App\SomeClass"
[1]=>
string(6) "param2"
[2]=>
string(6) "param3"
}
*/
* Output:
* array(3) {
* [0]=>
* string(13) "App\SomeClass"
* [1]=>
* string(6) "param2"
* [2]=>
* string(6) "param3"
* }
*/
}
}

View File

@ -1,6 +1,7 @@
<?php
$response->noCache();
// Sets the following header:
// Cache-Control: no-store, max-age=0, no-cache
/*
* Sets the following header:
* Cache-Control: no-store, max-age=0, no-cache
*/

View File

@ -9,8 +9,11 @@ class View extends BaseView
public $plugins = [
'foo' => '\Some\Class::methodName',
];
// ...
}
// Tag is replaced by the return value of Some\Class::methodName static function.
// {+ foo +}
/*
* Tag is replaced by the return value of Some\Class::methodName() static function.
* {+ foo +}
*/

View File

@ -1,15 +1,13 @@
<?php
$timers = $benchmark->getTimers();
/*
Produces:
[
'render view' => [
'start' => 1234567890,
'end' => 1345678920,
'duration' => 15.4315, // number of seconds
]
]
*/
* Produces:
* [
* 'render view' => [
* 'start' => 1234567890,
* 'end' => 1345678920,
* 'duration' => 15.4315, // number of seconds
* ]
* ]
*/

View File

@ -1,17 +1,14 @@
<?php
/*
Response body is this:
['foo' => 'bar']
*/
* Response body is this:
* ['foo' => 'bar']
*/
$json = $result->getJSON();
/*
$json is this:
{
"foo": "bar"
}
* $json is this:
* {
* "foo": "bar"
* }
`*/

View File

@ -1,12 +1,11 @@
<?php
/*
Response body is this:
[
'config' => ['key-a', 'key-b'],
]
*/
* Response body is this:
* [
* 'config' => ['key-a', 'key-b'],
* ]
*/
// Is true
$result->assertJSONFragment(['config' => ['key-a']]);