Skip to content

Instantly share code, notes, and snippets.

@votemike
Last active August 16, 2017 11:01
Show Gist options
  • Save votemike/04d7f5c2859a6999a5aa3915ea40c982 to your computer and use it in GitHub Desktop.
Save votemike/04d7f5c2859a6999a5aa3915ea40c982 to your computer and use it in GitHub Desktop.
This is how array params or return types should be doc-blocked. The same goes if the arrays are keyed or not.
/**
* @param int[] $theParam
* @return int[]
*/
function ints(array $theParam): array
{
return [
1,
2,
3,
];
}
/**
* @param float[] $theParam
* @return float[]
*/
function floats(array $theParam): array
{
return [
0.1,
1.2,
3.14,
];
}
/**
* @param bool[] $theParam
* @return bool[]
*/
function bools(array $theParam): array
{
return [
true,
false,
true,
];
}
/**
* @param string[] $theParam
* @return string[]
*/
function strings(array $theParam): array
{
return [
'peter',
'quagmire',
'joe',
'cleveland',
];
}
/**
* @param mixed[] $theParam
* @return mixed[]
*/
function mixed(array $theParam): array
{
return [
null,
1,
'mike',
true,
1.2,
new stdClass(),
['mike'],
];
}
/**
* @param array[] $theParam
* @return array[]
*/
function arrays(array $theParam): array
{
return [
[],
[],
[],
];
}
/**
* @param stdClass[] $theParam
* @return stdClass[]
*/
function classes(array $theParam): array
{
return [
new stdClass(),
new stdClass(),
new stdClass(),
];
}
/**
* @param mixed[][] $theParam
* @return mixed[][]
*/
function nested(array $theParam): array
{
return [
['id' => 1, 'name' => 'peter'],
['id' => 2, 'name' => 'quagmire'],
['id' => 3, 'name' => 'joe'],
['id' => 4, 'name' => 'cleveland'],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment