-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParser.php
More file actions
58 lines (52 loc) · 2.52 KB
/
Parser.php
File metadata and controls
58 lines (52 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace CommentManager;
/**
* Provides functions for extracting method Doc Block comments
*
* @category UtilityClass
* @author Nadir Latif <nadir@pakjiddat.pk>
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General private License, version 2
*/
class Parser
{
/**
* Used to parse the Doc Block comments of a method
*
* It first extracts the Doc Block comments of the given object's method
* It then parses the comments into an array containing the sections inside the comments
*
* @param string $class_name the class name
* @param string $function_name the function name
*
* @return array $parsed_comments the parsed doc block comments
*/
public function ParseMethodDocBlockComments(string $class_name, string $function_name) : array
{
/** The parsed doc block comments */
$parsed_comments = array();
/** The DescriptionParser class object is created */
$description_parser = new DescriptionParser();
/** The ParameterParser class object is created */
$parameter_parser = new ParameterParser();
/** The reflection object for the class name */
$reflector = new \ReflectionClass($class_name);
/** The function doc block comments */
$comments = $reflector->getMethod($function_name)->getDocComment();
/** The description text. It is extracted using regular expression */
$parsed_comments['description'] = $description_parser->ExtractDescriptionText($comments);
/** The method version. It includes since and version tags. It is extracted using regular expression */
$parsed_comments['version'] = $description_parser->ExtractVersion($comments);
/** The internal tags. They are extracted using regular expressions */
$parsed_comments['internal'] = $description_parser->ExtractInternal($comments);
/** The method parameters */
$parsed_comments['parameters'] = $parameter_parser->ExtractParameters("param", $comments);
/** The method return value */
$parsed_comments['return_value'] = $parameter_parser->ExtractParameters("return", $comments);
/** The return value is set */
$parsed_comments['return_value'] = $parsed_comments['return_value'][0] ?? '';
/** The function name is set */
$parsed_comments['function_name'] = $function_name;
return $parsed_comments;
}
}