PHPackages                             nadirlc/comment-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nadirlc/comment-manager

AbandonedLibrary

nadirlc/comment-manager
=======================

Doc Block comment parser and method validator

v1.0.0(7y ago)25971GPL-3.0-or-laterPHPPHP ^7.2

Since Mar 20Pushed 7y agoCompare

[ Source](https://github.com/pakjiddat/comment-manager)[ Packagist](https://packagist.org/packages/nadirlc/comment-manager)[ Docs](https://www.pakjiddat.pk/articles/view/254/comment-parser)[ RSS](/packages/nadirlc-comment-manager/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

### Introduction

[](#introduction)

The Comment Manager is a Php script that allows parsing method [Doc Block comments](https://en.wikipedia.org/wiki/PHPDoc). It also allows validating parameter values and return values using information in the Doc Block comments.

### Features

[](#features)

1. ##### **Method parameter validation**

    [](#method-parameter-validation)

    If you have added the following comment to a menthod:

    ```
    @param string $my_param [val1,val2,val3]
    ```

    Then the Comment Manager script can be used to check if the value given for the parameter, $my\_param is in the list val1,val2,val3.

    The script can validate range of numbers, parameter types, lists, emails, json and arrays. Method return values can also be validated based on information in DocBlock comments
2. ##### **Extracting method description**

    [](#extracting-method-description)

    The Comment Manager script can be used to extract the description text given in method Doc Bloc comments. Long and short method description can be extracted
3. ##### **Validating method context**

    [](#validating-method-context)

    The Comment Manager script can be used to check if a class method is being called from the command line, from browser, as an API function or test function etc, based on information in the [@internal tag](http://docs.phpdoc.org/references/phpdoc/tags/internal.html)
4. ##### **Custom Validation**

    [](#custom-validation)

    The Comment Manager script allows validating parameter values using custom validation functions
5. ##### **Supported tags**

    [](#supported-tags)

    Currently the Comment Manager script can be used to extract the following tags from DocBloc comments: [@param](http://docs.phpdoc.org/references/phpdoc/tags/param.html), [@version&gt;](http://docs.phpdoc.org/references/phpdoc/tags/version.html), [@internal](http://docs.phpdoc.org/references/phpdoc/tags/internal.html), [@return](http://docs.phpdoc.org/references/phpdoc/tags/return.html) and the [long and short method description](http://docs.phpdoc.org/guides/docblocks.html#description).

    The Comment Manager script can be easily extended to extract other tags from method comments
6. ##### **Use in MVC frameworks**

    [](#use-in-mvc-frameworks)

    The Comment Manager package can be used in MVC (Model View Controller) frameworks for performing automatic validation of method parameters based on information in the method Doc Block comments
7. ##### **PSR Standard**

    [](#psr-standard)

    The Comment Manager package code is compliant with the [PSR-2 coding style](https://www.php-fig.org/psr/psr-2/)

### Example Use

[](#example-use)

##### **Example 1**

[](#example-1)

The following example shows how to call a function safely with parameter and return value validation:

```

/** The safe_function_caller closure is fetched from the CommentManager class */
$safe_function_caller       = CommentManager::GetClosure();
/** The parameters for the test function */
$parameters                 = array(
                                  "number1" => 30,
                                  "number2" => 10,
                                  "number3" => 10,
                                   "data" => array(
                                                 "type" => "integer",
                                                  "random_string" => "The result of adding the three integers is: ";
                                            )
                              );

/** The function that provides custom validation for the test function parameters */
$validation_callback        = array($this, "CustomValidation");

/** The callback */
$callback                   = array(
                                  "class_name" => get_class(),
                                  "class_object" => $this,
                                  "function_name" => "AddNumbers",
                                  "parameters" => $parameters,
                                  "context" => "cli"
                              );
try {
   /** The test function is called through the safe function caller */
   $result                  = $safe_function_caller($callback, $validation_callback);
}
catch (\Error $e) {
    /** The error message is displayed and the script ends */
    die($e->getMessage());
}

/** The result of adding the numbers is displayed */
echo $result['random_string'] . $result['sum'];

```

In the above exampe, **CustomValidation** is a user defined function that performs custom validation. **AddNumbers** is the function to validate. It takes 3 numbers and a random string as parameters. It returns the random string as it is and also the sum of the three numbers. The custom validation function validates the return value by checking if the length of the random string is within range. The type and value of the parameters is checked by the Comment Manager classes. See the example file **CommentManagerTest.php** for the complete example.

##### **Example 2**

[](#example-2)

The following example shows how to extract method DocBlock comments:

```

/** The Parser class is included */
require("Parser.php");
/** An object of the parser class is created */
$parser = new Parser();
/** The method doc block comments are parsed */
$parsed_comments          = $parser->ParseMethodDocBlockComments($class_name, $function_name);
print_R($parsed_comments);

```

In the above example, $class name and $function\_name is the method to check. The following output is produced:

```

Array
(
    [description] => Array
        (
            [short] => This function adds the three numbers given as parameters.
                       It returns the sum of the numbers and a random string.
                       The random string is given as the last parameter
            [long] =>
        )

    [version] => Array
        (
            [since] =>
            [version] =>
        )

    [internal] => Array
        (
            [context] => cli
        )

    [parameters] => Array
        (
            [0] => Array
                (
                    [type] => int
                    [variable_name] => number1
                    [rule] => range
                    [description] => the first number
                    [rule_data] => 1-100
                )

            [1] => Array
                (
                    [type] => int
                    [variable_name] => number2
                    [rule] => range
                    [description] => the second number
                    [rule_data] => 1-100
                )

            [2] => Array
                (
                    [type] => int
                    [variable_name] => number3
                    [rule] => range
                    [description] => the third number
                    [rule_data] => 1-100
                )

            [3] => Array
                (
                    [type] => array
                    [variable_name] => data
                    [rule] =>
                    [description] => contains the type of the numbers and a string
                    [rule_data] =>
                    [values] => Array
                        (
                            [0] => Array
                                (
                                    [variable_name] => type
                                    [type] => string
                                    [rule] => list
                                    [rule_data] => integer,float
                                    [description] => the type of number to be added
                                )

                            [1] => Array
                                (
                                    [variable_name] => random_string
                                    [type] => string
                                    [rule] => custom
                                    [rule_data] =>
                                    [description] => a random string that is returned by the function
                                )

                        )

                )

        )

    [return_value] => Array
        (
            [type] => array
            [variable_name] => result
            [rule] =>
            [description] => the result of the function
            [rule_data] =>
            [values] => Array
                (
                    [0] => Array
                        (
                            [variable_name] => sum
                            [type] => int
                            [rule] => range
                            [rule_data] => 1-50
                            [description] => the sum of the three numbers
                        )

                    [1] => Array
                        (
                            [variable_name] => random_string
                            [type] => string
                            [rule] =>
                            [rule_data] =>
                            [description] => the random string
                        )

                )

        )

    [function_name] => AddNumbers
)

```

### List of files

[](#list-of-files)

The Comment Manager package consists of the following files:

- **CommentManager.php**. It provides a closure function for safe calling of class methods. It also provides functions for parsing and validating method parameters and return value
- **Parser.php**. It provides a single function for parsing all method DocBlock comments
- **DescriptionParser.php**. It provides functions for extracting long and short method description as well as the internal and version tags
- **ParameterParser.php**. It provides functions for parsing the **@param** tag
- **Validator.php**. It provides functions for validating method parameters and method return value using information in DocBloc comments
- **VariableValidator.php**. It provides functions for validating different types of variables. For example integer, string, boolean and arrays

### Installation

[](#installation)

1. ##### Install using composer:

    [](#install-using-composer)

    Run the command: **composer require nadirlc/comment-manager**

    **OR**
2. ##### Download from the [Comment Manager GitHub Repository](https://github.com/nadirlc/comment-manager)

    [](#download-from-the-comment-manager-github-repository)

    Run the command: **git clone **

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2609d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30418eda85a77af01f3f4ec162aa40f95a5f182fb6e70db2c8af8c0812d840ed?d=identicon)[pakjiddat](/maintainers/pakjiddat)

---

Tags

comment-parserdocblock-parserphpreflectionvalidation-librarycommentsdoc blocparameter validation

### Embed Badge

![Health badge](/badges/nadirlc-comment-manager/health.svg)

```
[![Health](https://phpackages.com/badges/nadirlc-comment-manager/health.svg)](https://phpackages.com/packages/nadirlc-comment-manager)
```

###  Alternatives

[beyondcode/laravel-comments

Add comments to your Laravel application

605414.2k2](/packages/beyondcode-laravel-comments)[laravelista/comments

Comments for Laravel.

744192.4k1](/packages/laravelista-comments)[staabm/phpstan-todo-by

1991.8M55](/packages/staabm-phpstan-todo-by)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[lakm/laravel-comments

Integrate seamless commenting functionality into your Laravel project.

40012.9k1](/packages/lakm-laravel-comments)[laktak/hjson

JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments.

86233.7k12](/packages/laktak-hjson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
