• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JBZoo / Utils / 29807313165

20 Jul 2026 06:55PM UTC coverage: 92.619%. Remained the same
29807313165

push

github

web-flow
Merge pull request #57 from JBZoo/release/8.0

8.0.0 — PHP 8.3+ floor & lock-step major

15 of 16 new or added lines in 7 files covered. (93.75%)

23 existing lines in 3 files now uncovered.

1669 of 1802 relevant lines covered (92.62%)

41.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/src/PhpDocs.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Utils.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Utils
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Utils;
18

19
/**
20
 * @psalm-suppress UnusedClass
21
 */
22
final class PhpDocs
23
{
24
    /**
25
     * Simple parse of PHPDocs.
26
     * Example or return value
27
     *  [
28
     *      'description' => 'Simple parse of PHPDocs. Example or return value',
29
     *      'params'      => [
30
     *          'param'  => ['string $phpDoc'],
31
     *          'return' => ['array']
32
     *      ]
33
     *  ].
34
     */
35
    public static function parse(string $phpDoc): array
36
    {
37
        $result = [
6✔
38
            'description' => '',
6✔
39
            'params'      => [],
6✔
40
        ];
6✔
41

42
        // split at each line
43
        $lines = (array)\preg_split("/(\r?\n)/", $phpDoc);
6✔
44

45
        foreach ($lines as $line) {
6✔
46
            // if starts with an asterisk
47
            if (\preg_match('/^(?=\s+?\*[^\/])(.+)/', (string)$line, $matches) > 0) {
6✔
48
                // remove wrapping whitespace
49
                $info = \trim($matches[1]);
6✔
50

51
                // remove leading asterisk
52
                $info = (string)\preg_replace('/^(\*\s+?)/', '', $info);
6✔
53

54
                // if it doesn't start with an "@" symbol
55
                // then add to the description
56

57
                $firstChar = $info[0] ?? null;
6✔
58
                if ($firstChar !== '@') {
6✔
59
                    $result['description'] .= "\n{$info}";
6✔
60
                    continue;
6✔
61
                }
62

63
                // get the name of the param
64
                if (\preg_match('/@(\w+)/', $info, $matches) !== 1) {
6✔
NEW
65
                    continue;
×
66
                }
67
                $paramName = $matches[1];
6✔
68

69
                // remove the param from the string
70
                $value = \str_replace("@{$paramName} ", '', $info);
6✔
71

72
                // if the param hasn't been added yet, create a key for it
73
                if (!isset($result['params'][$paramName])) {
6✔
74
                    $result['params'][$paramName] = [];
6✔
75
                }
76

77
                // push the param value into place
78
                $result['params'][$paramName][] = \trim($value);
6✔
79
            }
80
        }
81

82
        $result['description'] = \trim($result['description']);
6✔
83

84
        return $result;
6✔
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc