|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Docblock package. |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @license MIT License |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gossi\docblock\tags; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Represents the `@author` tag. |
|
14
|
|
|
* |
|
15
|
|
|
* @see https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/author.html |
|
16
|
|
|
*/ |
|
17
|
|
|
class AuthorTag extends AbstractTag { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* PCRE regular expression matching any valid value for the name component. |
|
21
|
|
|
*/ |
|
22
|
|
|
const REGEX_AUTHOR_NAME = '[^\<]*'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* PCRE regular expression matching any valid value for the email component. |
|
26
|
|
|
*/ |
|
27
|
|
|
const REGEX_AUTHOR_EMAIL = '[^\>]*'; |
|
28
|
|
|
|
|
29
|
|
|
protected string $name = ''; |
|
|
|
|
|
|
30
|
|
|
protected string $email = ''; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @see https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php Original Method: setContent() |
|
34
|
|
|
* @see \gossi\docblock\tags\AbstractTag::parse() |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $content |
|
37
|
|
|
*/ |
|
38
|
8 |
|
protected function parse(string $content): void { |
|
39
|
8 |
|
$matches = []; |
|
40
|
8 |
|
if (preg_match('/^(' . self::REGEX_AUTHOR_NAME . ')(\<(' . self::REGEX_AUTHOR_EMAIL . ')\>)?$/u', |
|
41
|
|
|
$content, $matches)) { |
|
42
|
8 |
|
$this->name = trim($matches[1]); |
|
43
|
8 |
|
if (isset($matches[3])) { |
|
44
|
1 |
|
$this->email = trim($matches[3]); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
8 |
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
public function toString(): string { |
|
50
|
3 |
|
$email = $this->email !== '' ? '<' . $this->email . '>' : ''; |
|
51
|
|
|
|
|
52
|
3 |
|
return trim(sprintf('@author %s %s', $this->name, $email)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns the authors name |
|
57
|
|
|
* |
|
58
|
|
|
* @return string the authors name |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function getName(): string { |
|
61
|
3 |
|
return $this->name; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets the authors name |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $name the new name |
|
68
|
|
|
* |
|
69
|
|
|
* @return $this |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function setName(string $name): self { |
|
72
|
1 |
|
$this->name = $name; |
|
73
|
|
|
|
|
74
|
1 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the authors email |
|
79
|
|
|
* |
|
80
|
|
|
* @return string the authors email |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function getEmail(): string { |
|
83
|
2 |
|
return $this->email; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Sets the authors email |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $email the new email |
|
90
|
|
|
* |
|
91
|
|
|
* @return $this |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function setEmail(string $email): self { |
|
94
|
1 |
|
$this->email = $email; |
|
95
|
|
|
|
|
96
|
1 |
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|