Best PHP comment DockBlock !

 

Best PHP comment !

Hello developers,

Here is my typical php comment/header for each of my php functions. Very useful and pragmatic. They provide a clear indication what the function is doing, inputs, outputs and exceptions. This is the art of coding ! Clear readibility and full transparency on the intentions of the functions.

I would definitely make this a requirement for programmer team. Additional work but useful. And if it is an API I would use the zircote/swagger-php library to generate on the fly an amazing swagger documentation

/**
 * Throw Exception If Parameter Is Not Set
 *
 * @param object $requestObjectBody
 * @param int $httpCode
 * @param string $httpMessage
 *
 * @return void
 *
 * @throws \Exception $exception
 *
 * @author  David Raleche <david@raleche.com>
 * @since 10-09-2020
 * @version 10-09-2020
 * @internal <ticket-number>
 */
public static function throwExceptionIfParameterNotSet($param, int $httpCode, string $httpMessage)
{
    if (is_null($param) or empty($param)) {
        throw new \Exception(
            $httpMessage,
            $httpCode
        );
    }
}

CIO/Managers : When having interns in your company the first exercise to give them is to go trhough existing code and add the following blocs of PHP docs. This will help them understand the code and this will improve considerable the readability of the legacy code. By doing so we quickly pinpoint the function to refactor

I usually give them the task to refactor functions being too long. More than 50 lines

Comments

Popular posts from this blog

How to fix pgDump dbeaver ?