PhpDocumentor::fqsen()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\PhpdocParser\Set;
6
7
use Jasny\PhpdocParser\PredefinedSetInterface;
8
use Jasny\PhpdocParser\Tag\MultiTag;
9
use Jasny\PhpdocParser\Tag\PhpDocumentor\ExampleTag;
10
use Jasny\PhpdocParser\Tag\PhpDocumentor\MethodTag;
11
use Jasny\PhpdocParser\Tag\PhpDocumentor\VarTag;
12
use Jasny\PhpdocParser\Tag\PhpDocumentor\TypeTag;
13
use Jasny\PhpdocParser\TagInterface;
14
use Jasny\PhpdocParser\TagSet;
15
use Jasny\PhpdocParser\Tag\ModifyTag;
16
use Jasny\PhpdocParser\Tag\DescriptionTag;
17
use Jasny\PhpdocParser\Tag\FlagTag;
18
use Jasny\PhpdocParser\Tag\RegExpTag;
19
use Jasny\PhpdocParser\Tag\WordTag;
20
21
/**
22
 * PhpDocumentor definitions
23
 * @static
24
 */
25
class PhpDocumentor implements PredefinedSetInterface
26
{
27
    /**
28
     * Disable instantiation.
29
     * @codeCoverageIgnore
30
     */
31
    private function __construct()
32
    {
33
    }
34
35
    /**
36
     * Get the tags
37
     *
38
     * @param callable|null $fqsenConvertor  Logic to convert class to FQCN
39
     * @return TagSet
40
     */
41 1
    public static function tags(?callable $fqsenConvertor = null): TagSet
42
    {
43 1
        return new TagSet([
44 1
            new FlagTag('api'),
45 1
            new RegExpTag('author', '/^(?:(?<name>(?:[^\<]\S*\s+)*[^\<]\S*)?\s*)?(?:\<(?<email>[^\>]+)\>)?/'),
46 1
            new DescriptionTag('copyright'),
47 1
            new WordTag('deprecated', true),
48 1
            new ExampleTag('example'),
49 1
            new FlagTag('ignore'),
50 1
            new FlagTag('internal'),
51 1
            new WordTag('link'),
52 1
            new MultiTag('methods', new MethodTag('method', $fqsenConvertor), 'name'),
53 1
            new WordTag('package'),
54 1
            new MultiTag('params', new VarTag('param', $fqsenConvertor), 'name'),
55 1
            new MultiTag('properties', new VarTag('property', $fqsenConvertor), 'name'),
56 1
            new MultiTag(
57 1
                'properties',
58 1
                new VarTag('property-read', $fqsenConvertor, ['read_only' => true]),
59 1
                'name'
60 1
            ),
61 1
            new MultiTag(
62 1
                'properties',
63 1
                new VarTag('property-write', $fqsenConvertor, ['write_only' => true]),
64 1
                'name'
65 1
            ),
66 1
            new TypeTag('return', $fqsenConvertor),
67 1
            self::fqsen(new WordTag('see'), $fqsenConvertor),
68 1
            new WordTag('since'),
69 1
            new MultiTag('throws', new TypeTag('throws', $fqsenConvertor)),
70 1
            new DescriptionTag('todo'),
71 1
            new TypeTag('uses', $fqsenConvertor),
72 1
            new TypeTag('used-by', $fqsenConvertor),
73 1
            new VarTag('var', $fqsenConvertor)
74 1
        ]);
75
    }
76
77
    /**
78
     * Apply FQCN converter if available
79
     *
80
     * @param TagInterface  $tag
81
     * @param callable|null $fqsenConvertor
82
     * @return TagInterface
83
     */
84 1
    protected static function fqsen(TagInterface $tag, ?callable $fqsenConvertor): TagInterface
85
    {
86 1
        return isset($fqsenConvertor) ? new ModifyTag($tag, $fqsenConvertor) : $tag;
87
    }
88
}
89