Skip to content
On this page

param-tag

Validate and format @param tag

Examples

  • Examples of correct code for this rule using default options

Function with docblock

php
<?php

/**
 * Calculate sum of three numbers
 *
 * @param int $first First number
 * @param int $second Second number
 * @param int $third Third number
 * @return int Sum of three numbers
 */
function calc($first, $second, $third) {
	return $first + $second + $third;
}

/**
 * Calculate sum of three numbers
 *
 * @param int $first First number
 * @param int|string $second Second number
 * @param FirstType&SecondType $third Third number
 * @return int Sum of three numbers
 */
function functionWithIntersectionType(int $first, int|string $second, FirstType&SecondType $third) {
	return $first + $second + $third;
}

/**
 * Calculate sum of three numbers
 *
 * @param int $first First number
 * @param int|string $second Second number
 * @param FirstType|SecondType $third Third number
 * @return int Sum of three numbers
 */
function functionWithUnionType(int $first, int|string $second, FirstType|SecondType $third) {
	return $first + $second + $third;
}

/**
 * Summary of the function.
 *
 * Description of the function.
 *
 * @param array $numbers Array of numbers
 * @param PiArray[] $data Array of Pi objects
 */
function functionWithArrayType(array $numbers, array $data) {
	echo "Hello world!";
}
  • Examples of incorrect code for this rule using default options

Docblocks with various errors

php
<?php

/**
 * Calculate sum of three numbers.
 *
 * @param int $first
 * @param int $second Second number
 * @return int Sum of three numbers
 */
function calc($first, $second, $third) {
    return $first + $second + $third;
}

/**
 * Calculate sum of three numbers.
 * 
 * @param int $first
 * @param $second Second number
 * @return int Sum of three numbers
 */
function calc2($first, $second, $third) {
    return $first + $second + $third;
}


/**
 * Calculate sum of three numbers.
 *
 * @param string $first
 * @param string $second Second number
 * @return int Sum of three numbers
 */
function calc3(string $first, $second, $third) {
    return $first + $second + $third;
}

/**
 * Calculate sum of three numbers.
 *
 * @param string $first
 * @param string $second Second number
 * @param string $third third number
 * @param string $fourth fourth number
 *
 * @return int Sum of three numbers
 */
function calc4(string $first, int $second, $third) {
    return $first + $second + $third;
}

/**
 * Calculate sum
 *
 * @param string $first First number
 * @param string $second Second number
 *
 * @return int Sum of numbers
 */
function calc5(string $first, int|string $second) {
    return $first + $second + $third;
}

/**
 * Multiply numbers
 *
 * @param string $first First number
 * @param string $second Second number
 *
 * @return int Result
 */
function calc6(string $first, ReturnValue&AnotherValue $second) {
    return $first * $second;
}

function functionWithNoParamsOrBody(){
    
}

Released under the MIT License.