@@ -25,92 +25,92 @@ |
||
25 | 25 | */ |
26 | 26 | final class Source extends BaseTag implements Factory\StaticMethod |
27 | 27 | { |
28 | - /** @var string */ |
|
29 | - protected $name = 'source'; |
|
30 | - |
|
31 | - /** @var int The starting line, relative to the structural element's location. */ |
|
32 | - private $startingLine; |
|
33 | - |
|
34 | - /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */ |
|
35 | - private $lineCount; |
|
36 | - |
|
37 | - /** |
|
38 | - * @param int|string $startingLine should be a to int convertible value |
|
39 | - * @param int|string|null $lineCount should be a to int convertible value |
|
40 | - */ |
|
41 | - public function __construct($startingLine, $lineCount = null, ?Description $description = null) |
|
42 | - { |
|
43 | - Assert::integerish($startingLine); |
|
44 | - Assert::nullOrIntegerish($lineCount); |
|
45 | - |
|
46 | - $this->startingLine = (int) $startingLine; |
|
47 | - $this->lineCount = $lineCount !== null ? (int) $lineCount : null; |
|
48 | - $this->description = $description; |
|
49 | - } |
|
50 | - |
|
51 | - public static function create( |
|
52 | - string $body, |
|
53 | - ?DescriptionFactory $descriptionFactory = null, |
|
54 | - ?TypeContext $context = null |
|
55 | - ): self { |
|
56 | - Assert::stringNotEmpty($body); |
|
57 | - Assert::notNull($descriptionFactory); |
|
58 | - |
|
59 | - $startingLine = 1; |
|
60 | - $lineCount = null; |
|
61 | - $description = null; |
|
62 | - |
|
63 | - // Starting line / Number of lines / Description |
|
64 | - if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) { |
|
65 | - $startingLine = (int) $matches[1]; |
|
66 | - if (isset($matches[2]) && $matches[2] !== '') { |
|
67 | - $lineCount = (int) $matches[2]; |
|
68 | - } |
|
69 | - |
|
70 | - $description = $matches[3]; |
|
71 | - } |
|
72 | - |
|
73 | - return new static($startingLine, $lineCount, $descriptionFactory->create($description ?? '', $context)); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Gets the starting line. |
|
78 | - * |
|
79 | - * @return int The starting line, relative to the structural element's |
|
80 | - * location. |
|
81 | - */ |
|
82 | - public function getStartingLine(): int |
|
83 | - { |
|
84 | - return $this->startingLine; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns the number of lines. |
|
89 | - * |
|
90 | - * @return int|null The number of lines, relative to the starting line. NULL |
|
91 | - * means "to the end". |
|
92 | - */ |
|
93 | - public function getLineCount(): ?int |
|
94 | - { |
|
95 | - return $this->lineCount; |
|
96 | - } |
|
97 | - |
|
98 | - public function __toString(): string |
|
99 | - { |
|
100 | - if ($this->description) { |
|
101 | - $description = $this->description->render(); |
|
102 | - } else { |
|
103 | - $description = ''; |
|
104 | - } |
|
105 | - |
|
106 | - $startingLine = (string) $this->startingLine; |
|
107 | - |
|
108 | - $lineCount = $this->lineCount !== null ? ' ' . $this->lineCount : ''; |
|
109 | - |
|
110 | - return $startingLine |
|
111 | - . $lineCount |
|
112 | - . ($description !== '' |
|
113 | - ? ' ' . $description |
|
114 | - : ''); |
|
115 | - } |
|
28 | + /** @var string */ |
|
29 | + protected $name = 'source'; |
|
30 | + |
|
31 | + /** @var int The starting line, relative to the structural element's location. */ |
|
32 | + private $startingLine; |
|
33 | + |
|
34 | + /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */ |
|
35 | + private $lineCount; |
|
36 | + |
|
37 | + /** |
|
38 | + * @param int|string $startingLine should be a to int convertible value |
|
39 | + * @param int|string|null $lineCount should be a to int convertible value |
|
40 | + */ |
|
41 | + public function __construct($startingLine, $lineCount = null, ?Description $description = null) |
|
42 | + { |
|
43 | + Assert::integerish($startingLine); |
|
44 | + Assert::nullOrIntegerish($lineCount); |
|
45 | + |
|
46 | + $this->startingLine = (int) $startingLine; |
|
47 | + $this->lineCount = $lineCount !== null ? (int) $lineCount : null; |
|
48 | + $this->description = $description; |
|
49 | + } |
|
50 | + |
|
51 | + public static function create( |
|
52 | + string $body, |
|
53 | + ?DescriptionFactory $descriptionFactory = null, |
|
54 | + ?TypeContext $context = null |
|
55 | + ): self { |
|
56 | + Assert::stringNotEmpty($body); |
|
57 | + Assert::notNull($descriptionFactory); |
|
58 | + |
|
59 | + $startingLine = 1; |
|
60 | + $lineCount = null; |
|
61 | + $description = null; |
|
62 | + |
|
63 | + // Starting line / Number of lines / Description |
|
64 | + if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) { |
|
65 | + $startingLine = (int) $matches[1]; |
|
66 | + if (isset($matches[2]) && $matches[2] !== '') { |
|
67 | + $lineCount = (int) $matches[2]; |
|
68 | + } |
|
69 | + |
|
70 | + $description = $matches[3]; |
|
71 | + } |
|
72 | + |
|
73 | + return new static($startingLine, $lineCount, $descriptionFactory->create($description ?? '', $context)); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Gets the starting line. |
|
78 | + * |
|
79 | + * @return int The starting line, relative to the structural element's |
|
80 | + * location. |
|
81 | + */ |
|
82 | + public function getStartingLine(): int |
|
83 | + { |
|
84 | + return $this->startingLine; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns the number of lines. |
|
89 | + * |
|
90 | + * @return int|null The number of lines, relative to the starting line. NULL |
|
91 | + * means "to the end". |
|
92 | + */ |
|
93 | + public function getLineCount(): ?int |
|
94 | + { |
|
95 | + return $this->lineCount; |
|
96 | + } |
|
97 | + |
|
98 | + public function __toString(): string |
|
99 | + { |
|
100 | + if ($this->description) { |
|
101 | + $description = $this->description->render(); |
|
102 | + } else { |
|
103 | + $description = ''; |
|
104 | + } |
|
105 | + |
|
106 | + $startingLine = (string) $this->startingLine; |
|
107 | + |
|
108 | + $lineCount = $this->lineCount !== null ? ' ' . $this->lineCount : ''; |
|
109 | + |
|
110 | + return $startingLine |
|
111 | + . $lineCount |
|
112 | + . ($description !== '' |
|
113 | + ? ' ' . $description |
|
114 | + : ''); |
|
115 | + } |
|
116 | 116 | } |
@@ -105,12 +105,12 @@ |
||
105 | 105 | |
106 | 106 | $startingLine = (string) $this->startingLine; |
107 | 107 | |
108 | - $lineCount = $this->lineCount !== null ? ' ' . $this->lineCount : ''; |
|
108 | + $lineCount = $this->lineCount !== null ? ' '.$this->lineCount : ''; |
|
109 | 109 | |
110 | 110 | return $startingLine |
111 | 111 | . $lineCount |
112 | 112 | . ($description !== '' |
113 | - ? ' ' . $description |
|
113 | + ? ' '.$description |
|
114 | 114 | : ''); |
115 | 115 | } |
116 | 116 | } |
@@ -29,73 +29,73 @@ |
||
29 | 29 | */ |
30 | 30 | final class Covers extends BaseTag implements Factory\StaticMethod |
31 | 31 | { |
32 | - /** @var string */ |
|
33 | - protected $name = 'covers'; |
|
34 | - |
|
35 | - /** @var Fqsen */ |
|
36 | - private $refers; |
|
37 | - |
|
38 | - /** |
|
39 | - * Initializes this tag. |
|
40 | - */ |
|
41 | - public function __construct(Fqsen $refers, ?Description $description = null) |
|
42 | - { |
|
43 | - $this->refers = $refers; |
|
44 | - $this->description = $description; |
|
45 | - } |
|
46 | - |
|
47 | - public static function create( |
|
48 | - string $body, |
|
49 | - ?DescriptionFactory $descriptionFactory = null, |
|
50 | - ?FqsenResolver $resolver = null, |
|
51 | - ?TypeContext $context = null |
|
52 | - ): self { |
|
53 | - Assert::stringNotEmpty($body); |
|
54 | - Assert::notNull($descriptionFactory); |
|
55 | - Assert::notNull($resolver); |
|
56 | - |
|
57 | - $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
58 | - |
|
59 | - return new static( |
|
60 | - self::resolveFqsen($parts[0], $resolver, $context), |
|
61 | - $descriptionFactory->create($parts[1] ?? '', $context) |
|
62 | - ); |
|
63 | - } |
|
64 | - |
|
65 | - private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen |
|
66 | - { |
|
67 | - Assert::notNull($fqsenResolver); |
|
68 | - $fqsenParts = explode('::', $parts); |
|
69 | - $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
|
70 | - |
|
71 | - if (!array_key_exists(1, $fqsenParts)) { |
|
72 | - return $resolved; |
|
73 | - } |
|
74 | - |
|
75 | - return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns the structural element this tag refers to. |
|
80 | - */ |
|
81 | - public function getReference(): Fqsen |
|
82 | - { |
|
83 | - return $this->refers; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Returns a string representation of this tag. |
|
88 | - */ |
|
89 | - public function __toString(): string |
|
90 | - { |
|
91 | - if ($this->description) { |
|
92 | - $description = $this->description->render(); |
|
93 | - } else { |
|
94 | - $description = ''; |
|
95 | - } |
|
96 | - |
|
97 | - $refers = (string) $this->refers; |
|
98 | - |
|
99 | - return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
100 | - } |
|
32 | + /** @var string */ |
|
33 | + protected $name = 'covers'; |
|
34 | + |
|
35 | + /** @var Fqsen */ |
|
36 | + private $refers; |
|
37 | + |
|
38 | + /** |
|
39 | + * Initializes this tag. |
|
40 | + */ |
|
41 | + public function __construct(Fqsen $refers, ?Description $description = null) |
|
42 | + { |
|
43 | + $this->refers = $refers; |
|
44 | + $this->description = $description; |
|
45 | + } |
|
46 | + |
|
47 | + public static function create( |
|
48 | + string $body, |
|
49 | + ?DescriptionFactory $descriptionFactory = null, |
|
50 | + ?FqsenResolver $resolver = null, |
|
51 | + ?TypeContext $context = null |
|
52 | + ): self { |
|
53 | + Assert::stringNotEmpty($body); |
|
54 | + Assert::notNull($descriptionFactory); |
|
55 | + Assert::notNull($resolver); |
|
56 | + |
|
57 | + $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
58 | + |
|
59 | + return new static( |
|
60 | + self::resolveFqsen($parts[0], $resolver, $context), |
|
61 | + $descriptionFactory->create($parts[1] ?? '', $context) |
|
62 | + ); |
|
63 | + } |
|
64 | + |
|
65 | + private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen |
|
66 | + { |
|
67 | + Assert::notNull($fqsenResolver); |
|
68 | + $fqsenParts = explode('::', $parts); |
|
69 | + $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
|
70 | + |
|
71 | + if (!array_key_exists(1, $fqsenParts)) { |
|
72 | + return $resolved; |
|
73 | + } |
|
74 | + |
|
75 | + return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns the structural element this tag refers to. |
|
80 | + */ |
|
81 | + public function getReference(): Fqsen |
|
82 | + { |
|
83 | + return $this->refers; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Returns a string representation of this tag. |
|
88 | + */ |
|
89 | + public function __toString(): string |
|
90 | + { |
|
91 | + if ($this->description) { |
|
92 | + $description = $this->description->render(); |
|
93 | + } else { |
|
94 | + $description = ''; |
|
95 | + } |
|
96 | + |
|
97 | + $refers = (string) $this->refers; |
|
98 | + |
|
99 | + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
100 | + } |
|
101 | 101 | } |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $fqsenParts = explode('::', $parts); |
69 | 69 | $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); |
70 | 70 | |
71 | - if (!array_key_exists(1, $fqsenParts)) { |
|
71 | + if ( ! array_key_exists(1, $fqsenParts)) { |
|
72 | 72 | return $resolved; |
73 | 73 | } |
74 | 74 | |
75 | - return new Fqsen($resolved . '::' . $fqsenParts[1]); |
|
75 | + return new Fqsen($resolved.'::'.$fqsenParts[1]); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -96,6 +96,6 @@ discard block |
||
96 | 96 | |
97 | 97 | $refers = (string) $this->refers; |
98 | 98 | |
99 | - return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); |
|
99 | + return $refers.($description !== '' ? ($refers !== '' ? ' ' : '').$description : ''); |
|
100 | 100 | } |
101 | 101 | } |
@@ -34,88 +34,88 @@ |
||
34 | 34 | */ |
35 | 35 | final class PropertyRead extends TagWithType implements Factory\StaticMethod |
36 | 36 | { |
37 | - /** @var string|null */ |
|
38 | - protected $variableName; |
|
39 | - |
|
40 | - public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) |
|
41 | - { |
|
42 | - Assert::string($variableName); |
|
43 | - |
|
44 | - $this->name = 'property-read'; |
|
45 | - $this->variableName = $variableName; |
|
46 | - $this->type = $type; |
|
47 | - $this->description = $description; |
|
48 | - } |
|
49 | - |
|
50 | - public static function create( |
|
51 | - string $body, |
|
52 | - ?TypeResolver $typeResolver = null, |
|
53 | - ?DescriptionFactory $descriptionFactory = null, |
|
54 | - ?TypeContext $context = null |
|
55 | - ): self { |
|
56 | - Assert::stringNotEmpty($body); |
|
57 | - Assert::notNull($typeResolver); |
|
58 | - Assert::notNull($descriptionFactory); |
|
59 | - |
|
60 | - [$firstPart, $body] = self::extractTypeFromBody($body); |
|
61 | - $type = null; |
|
62 | - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | - $variableName = ''; |
|
64 | - |
|
65 | - // if the first item that is encountered is not a variable; it is a type |
|
66 | - if ($firstPart && $firstPart[0] !== '$') { |
|
67 | - $type = $typeResolver->resolve($firstPart, $context); |
|
68 | - } else { |
|
69 | - // first part is not a type; we should prepend it to the parts array for further processing |
|
70 | - array_unshift($parts, $firstPart); |
|
71 | - } |
|
72 | - |
|
73 | - // if the next item starts with a $ it must be the variable name |
|
74 | - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
75 | - $variableName = array_shift($parts); |
|
76 | - if ($type) { |
|
77 | - array_shift($parts); |
|
78 | - } |
|
79 | - |
|
80 | - Assert::notNull($variableName); |
|
81 | - |
|
82 | - $variableName = substr($variableName, 1); |
|
83 | - } |
|
84 | - |
|
85 | - $description = $descriptionFactory->create(implode('', $parts), $context); |
|
86 | - |
|
87 | - return new static($variableName, $type, $description); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the variable's name. |
|
92 | - */ |
|
93 | - public function getVariableName(): ?string |
|
94 | - { |
|
95 | - return $this->variableName; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns a string representation for this tag. |
|
100 | - */ |
|
101 | - public function __toString(): string |
|
102 | - { |
|
103 | - if ($this->description) { |
|
104 | - $description = $this->description->render(); |
|
105 | - } else { |
|
106 | - $description = ''; |
|
107 | - } |
|
108 | - |
|
109 | - if ($this->variableName) { |
|
110 | - $variableName = '$' . $this->variableName; |
|
111 | - } else { |
|
112 | - $variableName = ''; |
|
113 | - } |
|
114 | - |
|
115 | - $type = (string) $this->type; |
|
116 | - |
|
117 | - return $type |
|
118 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
120 | - } |
|
37 | + /** @var string|null */ |
|
38 | + protected $variableName; |
|
39 | + |
|
40 | + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) |
|
41 | + { |
|
42 | + Assert::string($variableName); |
|
43 | + |
|
44 | + $this->name = 'property-read'; |
|
45 | + $this->variableName = $variableName; |
|
46 | + $this->type = $type; |
|
47 | + $this->description = $description; |
|
48 | + } |
|
49 | + |
|
50 | + public static function create( |
|
51 | + string $body, |
|
52 | + ?TypeResolver $typeResolver = null, |
|
53 | + ?DescriptionFactory $descriptionFactory = null, |
|
54 | + ?TypeContext $context = null |
|
55 | + ): self { |
|
56 | + Assert::stringNotEmpty($body); |
|
57 | + Assert::notNull($typeResolver); |
|
58 | + Assert::notNull($descriptionFactory); |
|
59 | + |
|
60 | + [$firstPart, $body] = self::extractTypeFromBody($body); |
|
61 | + $type = null; |
|
62 | + $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | + $variableName = ''; |
|
64 | + |
|
65 | + // if the first item that is encountered is not a variable; it is a type |
|
66 | + if ($firstPart && $firstPart[0] !== '$') { |
|
67 | + $type = $typeResolver->resolve($firstPart, $context); |
|
68 | + } else { |
|
69 | + // first part is not a type; we should prepend it to the parts array for further processing |
|
70 | + array_unshift($parts, $firstPart); |
|
71 | + } |
|
72 | + |
|
73 | + // if the next item starts with a $ it must be the variable name |
|
74 | + if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
75 | + $variableName = array_shift($parts); |
|
76 | + if ($type) { |
|
77 | + array_shift($parts); |
|
78 | + } |
|
79 | + |
|
80 | + Assert::notNull($variableName); |
|
81 | + |
|
82 | + $variableName = substr($variableName, 1); |
|
83 | + } |
|
84 | + |
|
85 | + $description = $descriptionFactory->create(implode('', $parts), $context); |
|
86 | + |
|
87 | + return new static($variableName, $type, $description); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the variable's name. |
|
92 | + */ |
|
93 | + public function getVariableName(): ?string |
|
94 | + { |
|
95 | + return $this->variableName; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns a string representation for this tag. |
|
100 | + */ |
|
101 | + public function __toString(): string |
|
102 | + { |
|
103 | + if ($this->description) { |
|
104 | + $description = $this->description->render(); |
|
105 | + } else { |
|
106 | + $description = ''; |
|
107 | + } |
|
108 | + |
|
109 | + if ($this->variableName) { |
|
110 | + $variableName = '$' . $this->variableName; |
|
111 | + } else { |
|
112 | + $variableName = ''; |
|
113 | + } |
|
114 | + |
|
115 | + $type = (string) $this->type; |
|
116 | + |
|
117 | + return $type |
|
118 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
120 | + } |
|
121 | 121 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if ($this->variableName) { |
110 | - $variableName = '$' . $this->variableName; |
|
110 | + $variableName = '$'.$this->variableName; |
|
111 | 111 | } else { |
112 | 112 | $variableName = ''; |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $type = (string) $this->type; |
116 | 116 | |
117 | 117 | return $type |
118 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
118 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '').$variableName : '') |
|
119 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '').$description : ''); |
|
120 | 120 | } |
121 | 121 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | final class Version extends BaseTag implements Factory\StaticMethod |
27 | 27 | { |
28 | - /** @var string */ |
|
29 | - protected $name = 'version'; |
|
30 | - |
|
31 | - /** |
|
32 | - * PCRE regular expression matching a version vector. |
|
33 | - * Assumes the "x" modifier. |
|
34 | - */ |
|
35 | - public const REGEX_VECTOR = '(?: |
|
28 | + /** @var string */ |
|
29 | + protected $name = 'version'; |
|
30 | + |
|
31 | + /** |
|
32 | + * PCRE regular expression matching a version vector. |
|
33 | + * Assumes the "x" modifier. |
|
34 | + */ |
|
35 | + public const REGEX_VECTOR = '(?: |
|
36 | 36 | # Normal release vectors. |
37 | 37 | \d\S* |
38 | 38 | | |
@@ -44,63 +44,63 @@ discard block |
||
44 | 44 | [^\s\:]+\:\s*\$[^\$]+\$ |
45 | 45 | )'; |
46 | 46 | |
47 | - /** @var string|null The version vector. */ |
|
48 | - private $version; |
|
49 | - |
|
50 | - public function __construct(?string $version = null, ?Description $description = null) |
|
51 | - { |
|
52 | - Assert::nullOrStringNotEmpty($version); |
|
53 | - |
|
54 | - $this->version = $version; |
|
55 | - $this->description = $description; |
|
56 | - } |
|
57 | - |
|
58 | - public static function create( |
|
59 | - ?string $body, |
|
60 | - ?DescriptionFactory $descriptionFactory = null, |
|
61 | - ?TypeContext $context = null |
|
62 | - ): ?self { |
|
63 | - if (empty($body)) { |
|
64 | - return new static(); |
|
65 | - } |
|
66 | - |
|
67 | - $matches = []; |
|
68 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - $description = null; |
|
73 | - if ($descriptionFactory !== null) { |
|
74 | - $description = $descriptionFactory->create($matches[2] ?? '', $context); |
|
75 | - } |
|
76 | - |
|
77 | - return new static( |
|
78 | - $matches[1], |
|
79 | - $description |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Gets the version section of the tag. |
|
85 | - */ |
|
86 | - public function getVersion(): ?string |
|
87 | - { |
|
88 | - return $this->version; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns a string representation for this tag. |
|
93 | - */ |
|
94 | - public function __toString(): string |
|
95 | - { |
|
96 | - if ($this->description) { |
|
97 | - $description = $this->description->render(); |
|
98 | - } else { |
|
99 | - $description = ''; |
|
100 | - } |
|
101 | - |
|
102 | - $version = (string) $this->version; |
|
103 | - |
|
104 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
105 | - } |
|
47 | + /** @var string|null The version vector. */ |
|
48 | + private $version; |
|
49 | + |
|
50 | + public function __construct(?string $version = null, ?Description $description = null) |
|
51 | + { |
|
52 | + Assert::nullOrStringNotEmpty($version); |
|
53 | + |
|
54 | + $this->version = $version; |
|
55 | + $this->description = $description; |
|
56 | + } |
|
57 | + |
|
58 | + public static function create( |
|
59 | + ?string $body, |
|
60 | + ?DescriptionFactory $descriptionFactory = null, |
|
61 | + ?TypeContext $context = null |
|
62 | + ): ?self { |
|
63 | + if (empty($body)) { |
|
64 | + return new static(); |
|
65 | + } |
|
66 | + |
|
67 | + $matches = []; |
|
68 | + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + $description = null; |
|
73 | + if ($descriptionFactory !== null) { |
|
74 | + $description = $descriptionFactory->create($matches[2] ?? '', $context); |
|
75 | + } |
|
76 | + |
|
77 | + return new static( |
|
78 | + $matches[1], |
|
79 | + $description |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Gets the version section of the tag. |
|
85 | + */ |
|
86 | + public function getVersion(): ?string |
|
87 | + { |
|
88 | + return $this->version; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns a string representation for this tag. |
|
93 | + */ |
|
94 | + public function __toString(): string |
|
95 | + { |
|
96 | + if ($this->description) { |
|
97 | + $description = $this->description->render(); |
|
98 | + } else { |
|
99 | + $description = ''; |
|
100 | + } |
|
101 | + |
|
102 | + $version = (string) $this->version; |
|
103 | + |
|
104 | + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
105 | + } |
|
106 | 106 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $matches = []; |
68 | - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { |
|
68 | + if ( ! preg_match('/^('.self::REGEX_VECTOR.')\s*(.+)?$/sux', $body, $matches)) { |
|
69 | 69 | return null; |
70 | 70 | } |
71 | 71 | |
@@ -101,6 +101,6 @@ discard block |
||
101 | 101 | |
102 | 102 | $version = (string) $this->version; |
103 | 103 | |
104 | - return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); |
|
104 | + return $version.($description !== '' ? ($version !== '' ? ' ' : '').$description : ''); |
|
105 | 105 | } |
106 | 106 | } |
@@ -17,8 +17,8 @@ |
||
17 | 17 | |
18 | 18 | interface Formatter |
19 | 19 | { |
20 | - /** |
|
21 | - * Formats a tag into a string representation according to a specific format, such as Markdown. |
|
22 | - */ |
|
23 | - public function format(Tag $tag): string; |
|
20 | + /** |
|
21 | + * Formats a tag into a string representation according to a specific format, such as Markdown. |
|
22 | + */ |
|
23 | + public function format(Tag $tag): string; |
|
24 | 24 | } |
@@ -34,88 +34,88 @@ |
||
34 | 34 | */ |
35 | 35 | final class Property extends TagWithType implements Factory\StaticMethod |
36 | 36 | { |
37 | - /** @var string|null */ |
|
38 | - protected $variableName; |
|
39 | - |
|
40 | - public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) |
|
41 | - { |
|
42 | - Assert::string($variableName); |
|
43 | - |
|
44 | - $this->name = 'property'; |
|
45 | - $this->variableName = $variableName; |
|
46 | - $this->type = $type; |
|
47 | - $this->description = $description; |
|
48 | - } |
|
49 | - |
|
50 | - public static function create( |
|
51 | - string $body, |
|
52 | - ?TypeResolver $typeResolver = null, |
|
53 | - ?DescriptionFactory $descriptionFactory = null, |
|
54 | - ?TypeContext $context = null |
|
55 | - ): self { |
|
56 | - Assert::stringNotEmpty($body); |
|
57 | - Assert::notNull($typeResolver); |
|
58 | - Assert::notNull($descriptionFactory); |
|
59 | - |
|
60 | - [$firstPart, $body] = self::extractTypeFromBody($body); |
|
61 | - $type = null; |
|
62 | - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | - $variableName = ''; |
|
64 | - |
|
65 | - // if the first item that is encountered is not a variable; it is a type |
|
66 | - if ($firstPart && $firstPart[0] !== '$') { |
|
67 | - $type = $typeResolver->resolve($firstPart, $context); |
|
68 | - } else { |
|
69 | - // first part is not a type; we should prepend it to the parts array for further processing |
|
70 | - array_unshift($parts, $firstPart); |
|
71 | - } |
|
72 | - |
|
73 | - // if the next item starts with a $ it must be the variable name |
|
74 | - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
75 | - $variableName = array_shift($parts); |
|
76 | - if ($type) { |
|
77 | - array_shift($parts); |
|
78 | - } |
|
79 | - |
|
80 | - Assert::notNull($variableName); |
|
81 | - |
|
82 | - $variableName = substr($variableName, 1); |
|
83 | - } |
|
84 | - |
|
85 | - $description = $descriptionFactory->create(implode('', $parts), $context); |
|
86 | - |
|
87 | - return new static($variableName, $type, $description); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the variable's name. |
|
92 | - */ |
|
93 | - public function getVariableName(): ?string |
|
94 | - { |
|
95 | - return $this->variableName; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns a string representation for this tag. |
|
100 | - */ |
|
101 | - public function __toString(): string |
|
102 | - { |
|
103 | - if ($this->description) { |
|
104 | - $description = $this->description->render(); |
|
105 | - } else { |
|
106 | - $description = ''; |
|
107 | - } |
|
108 | - |
|
109 | - if ($this->variableName) { |
|
110 | - $variableName = '$' . $this->variableName; |
|
111 | - } else { |
|
112 | - $variableName = ''; |
|
113 | - } |
|
114 | - |
|
115 | - $type = (string) $this->type; |
|
116 | - |
|
117 | - return $type |
|
118 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
120 | - } |
|
37 | + /** @var string|null */ |
|
38 | + protected $variableName; |
|
39 | + |
|
40 | + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) |
|
41 | + { |
|
42 | + Assert::string($variableName); |
|
43 | + |
|
44 | + $this->name = 'property'; |
|
45 | + $this->variableName = $variableName; |
|
46 | + $this->type = $type; |
|
47 | + $this->description = $description; |
|
48 | + } |
|
49 | + |
|
50 | + public static function create( |
|
51 | + string $body, |
|
52 | + ?TypeResolver $typeResolver = null, |
|
53 | + ?DescriptionFactory $descriptionFactory = null, |
|
54 | + ?TypeContext $context = null |
|
55 | + ): self { |
|
56 | + Assert::stringNotEmpty($body); |
|
57 | + Assert::notNull($typeResolver); |
|
58 | + Assert::notNull($descriptionFactory); |
|
59 | + |
|
60 | + [$firstPart, $body] = self::extractTypeFromBody($body); |
|
61 | + $type = null; |
|
62 | + $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | + $variableName = ''; |
|
64 | + |
|
65 | + // if the first item that is encountered is not a variable; it is a type |
|
66 | + if ($firstPart && $firstPart[0] !== '$') { |
|
67 | + $type = $typeResolver->resolve($firstPart, $context); |
|
68 | + } else { |
|
69 | + // first part is not a type; we should prepend it to the parts array for further processing |
|
70 | + array_unshift($parts, $firstPart); |
|
71 | + } |
|
72 | + |
|
73 | + // if the next item starts with a $ it must be the variable name |
|
74 | + if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
75 | + $variableName = array_shift($parts); |
|
76 | + if ($type) { |
|
77 | + array_shift($parts); |
|
78 | + } |
|
79 | + |
|
80 | + Assert::notNull($variableName); |
|
81 | + |
|
82 | + $variableName = substr($variableName, 1); |
|
83 | + } |
|
84 | + |
|
85 | + $description = $descriptionFactory->create(implode('', $parts), $context); |
|
86 | + |
|
87 | + return new static($variableName, $type, $description); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the variable's name. |
|
92 | + */ |
|
93 | + public function getVariableName(): ?string |
|
94 | + { |
|
95 | + return $this->variableName; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns a string representation for this tag. |
|
100 | + */ |
|
101 | + public function __toString(): string |
|
102 | + { |
|
103 | + if ($this->description) { |
|
104 | + $description = $this->description->render(); |
|
105 | + } else { |
|
106 | + $description = ''; |
|
107 | + } |
|
108 | + |
|
109 | + if ($this->variableName) { |
|
110 | + $variableName = '$' . $this->variableName; |
|
111 | + } else { |
|
112 | + $variableName = ''; |
|
113 | + } |
|
114 | + |
|
115 | + $type = (string) $this->type; |
|
116 | + |
|
117 | + return $type |
|
118 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
120 | + } |
|
121 | 121 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if ($this->variableName) { |
110 | - $variableName = '$' . $this->variableName; |
|
110 | + $variableName = '$'.$this->variableName; |
|
111 | 111 | } else { |
112 | 112 | $variableName = ''; |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $type = (string) $this->type; |
116 | 116 | |
117 | 117 | return $type |
118 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
119 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
118 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '').$variableName : '') |
|
119 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '').$description : ''); |
|
120 | 120 | } |
121 | 121 | } |
@@ -32,114 +32,114 @@ |
||
32 | 32 | */ |
33 | 33 | final class InvalidTag implements Tag |
34 | 34 | { |
35 | - /** @var string */ |
|
36 | - private $name; |
|
37 | - |
|
38 | - /** @var string */ |
|
39 | - private $body; |
|
40 | - |
|
41 | - /** @var Throwable|null */ |
|
42 | - private $throwable; |
|
43 | - |
|
44 | - private function __construct(string $name, string $body) |
|
45 | - { |
|
46 | - $this->name = $name; |
|
47 | - $this->body = $body; |
|
48 | - } |
|
49 | - |
|
50 | - public function getException(): ?Throwable |
|
51 | - { |
|
52 | - return $this->throwable; |
|
53 | - } |
|
54 | - |
|
55 | - public function getName(): string |
|
56 | - { |
|
57 | - return $this->name; |
|
58 | - } |
|
59 | - |
|
60 | - public static function create(string $body, string $name = ''): self |
|
61 | - { |
|
62 | - return new self($name, $body); |
|
63 | - } |
|
64 | - |
|
65 | - public function withError(Throwable $exception): self |
|
66 | - { |
|
67 | - $this->flattenExceptionBacktrace($exception); |
|
68 | - $tag = new self($this->name, $this->body); |
|
69 | - $tag->throwable = $exception; |
|
70 | - |
|
71 | - return $tag; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Removes all complex types from backtrace |
|
76 | - * |
|
77 | - * Not all objects are serializable. So we need to remove them from the |
|
78 | - * stored exception to be sure that we do not break existing library usage. |
|
79 | - */ |
|
80 | - private function flattenExceptionBacktrace(Throwable $exception): void |
|
81 | - { |
|
82 | - $traceProperty = (new ReflectionClass(Exception::class))->getProperty('trace'); |
|
83 | - $traceProperty->setAccessible(true); |
|
84 | - |
|
85 | - do { |
|
86 | - $trace = $exception->getTrace(); |
|
87 | - if (isset($trace[0]['args'])) { |
|
88 | - $trace = array_map( |
|
89 | - function (array $call): array { |
|
90 | - $call['args'] = array_map([$this, 'flattenArguments'], $call['args'] ?? []); |
|
91 | - |
|
92 | - return $call; |
|
93 | - }, |
|
94 | - $trace |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - $traceProperty->setValue($exception, $trace); |
|
99 | - $exception = $exception->getPrevious(); |
|
100 | - } while ($exception !== null); |
|
101 | - |
|
102 | - $traceProperty->setAccessible(false); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param mixed $value |
|
107 | - * |
|
108 | - * @return mixed |
|
109 | - * |
|
110 | - * @throws ReflectionException |
|
111 | - */ |
|
112 | - private function flattenArguments($value) |
|
113 | - { |
|
114 | - if ($value instanceof Closure) { |
|
115 | - $closureReflection = new ReflectionFunction($value); |
|
116 | - $value = sprintf( |
|
117 | - '(Closure at %s:%s)', |
|
118 | - $closureReflection->getFileName(), |
|
119 | - $closureReflection->getStartLine() |
|
120 | - ); |
|
121 | - } elseif (is_object($value)) { |
|
122 | - $value = sprintf('object(%s)', get_class($value)); |
|
123 | - } elseif (is_resource($value)) { |
|
124 | - $value = sprintf('resource(%s)', get_resource_type($value)); |
|
125 | - } elseif (is_array($value)) { |
|
126 | - $value = array_map([$this, 'flattenArguments'], $value); |
|
127 | - } |
|
128 | - |
|
129 | - return $value; |
|
130 | - } |
|
131 | - |
|
132 | - public function render(?Formatter $formatter = null): string |
|
133 | - { |
|
134 | - if ($formatter === null) { |
|
135 | - $formatter = new Formatter\PassthroughFormatter(); |
|
136 | - } |
|
137 | - |
|
138 | - return $formatter->format($this); |
|
139 | - } |
|
140 | - |
|
141 | - public function __toString(): string |
|
142 | - { |
|
143 | - return $this->body; |
|
144 | - } |
|
35 | + /** @var string */ |
|
36 | + private $name; |
|
37 | + |
|
38 | + /** @var string */ |
|
39 | + private $body; |
|
40 | + |
|
41 | + /** @var Throwable|null */ |
|
42 | + private $throwable; |
|
43 | + |
|
44 | + private function __construct(string $name, string $body) |
|
45 | + { |
|
46 | + $this->name = $name; |
|
47 | + $this->body = $body; |
|
48 | + } |
|
49 | + |
|
50 | + public function getException(): ?Throwable |
|
51 | + { |
|
52 | + return $this->throwable; |
|
53 | + } |
|
54 | + |
|
55 | + public function getName(): string |
|
56 | + { |
|
57 | + return $this->name; |
|
58 | + } |
|
59 | + |
|
60 | + public static function create(string $body, string $name = ''): self |
|
61 | + { |
|
62 | + return new self($name, $body); |
|
63 | + } |
|
64 | + |
|
65 | + public function withError(Throwable $exception): self |
|
66 | + { |
|
67 | + $this->flattenExceptionBacktrace($exception); |
|
68 | + $tag = new self($this->name, $this->body); |
|
69 | + $tag->throwable = $exception; |
|
70 | + |
|
71 | + return $tag; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Removes all complex types from backtrace |
|
76 | + * |
|
77 | + * Not all objects are serializable. So we need to remove them from the |
|
78 | + * stored exception to be sure that we do not break existing library usage. |
|
79 | + */ |
|
80 | + private function flattenExceptionBacktrace(Throwable $exception): void |
|
81 | + { |
|
82 | + $traceProperty = (new ReflectionClass(Exception::class))->getProperty('trace'); |
|
83 | + $traceProperty->setAccessible(true); |
|
84 | + |
|
85 | + do { |
|
86 | + $trace = $exception->getTrace(); |
|
87 | + if (isset($trace[0]['args'])) { |
|
88 | + $trace = array_map( |
|
89 | + function (array $call): array { |
|
90 | + $call['args'] = array_map([$this, 'flattenArguments'], $call['args'] ?? []); |
|
91 | + |
|
92 | + return $call; |
|
93 | + }, |
|
94 | + $trace |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + $traceProperty->setValue($exception, $trace); |
|
99 | + $exception = $exception->getPrevious(); |
|
100 | + } while ($exception !== null); |
|
101 | + |
|
102 | + $traceProperty->setAccessible(false); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param mixed $value |
|
107 | + * |
|
108 | + * @return mixed |
|
109 | + * |
|
110 | + * @throws ReflectionException |
|
111 | + */ |
|
112 | + private function flattenArguments($value) |
|
113 | + { |
|
114 | + if ($value instanceof Closure) { |
|
115 | + $closureReflection = new ReflectionFunction($value); |
|
116 | + $value = sprintf( |
|
117 | + '(Closure at %s:%s)', |
|
118 | + $closureReflection->getFileName(), |
|
119 | + $closureReflection->getStartLine() |
|
120 | + ); |
|
121 | + } elseif (is_object($value)) { |
|
122 | + $value = sprintf('object(%s)', get_class($value)); |
|
123 | + } elseif (is_resource($value)) { |
|
124 | + $value = sprintf('resource(%s)', get_resource_type($value)); |
|
125 | + } elseif (is_array($value)) { |
|
126 | + $value = array_map([$this, 'flattenArguments'], $value); |
|
127 | + } |
|
128 | + |
|
129 | + return $value; |
|
130 | + } |
|
131 | + |
|
132 | + public function render(?Formatter $formatter = null): string |
|
133 | + { |
|
134 | + if ($formatter === null) { |
|
135 | + $formatter = new Formatter\PassthroughFormatter(); |
|
136 | + } |
|
137 | + |
|
138 | + return $formatter->format($this); |
|
139 | + } |
|
140 | + |
|
141 | + public function __toString(): string |
|
142 | + { |
|
143 | + return $this->body; |
|
144 | + } |
|
145 | 145 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $trace = $exception->getTrace(); |
87 | 87 | if (isset($trace[0]['args'])) { |
88 | 88 | $trace = array_map( |
89 | - function (array $call): array { |
|
89 | + function(array $call): array { |
|
90 | 90 | $call['args'] = array_map([$this, 'flattenArguments'], $call['args'] ?? []); |
91 | 91 | |
92 | 92 | return $call; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | $traceProperty->setValue($exception, $trace); |
99 | 99 | $exception = $exception->getPrevious(); |
100 | - } while ($exception !== null); |
|
100 | + }while ($exception !== null); |
|
101 | 101 | |
102 | 102 | $traceProperty->setAccessible(false); |
103 | 103 | } |
@@ -25,40 +25,40 @@ |
||
25 | 25 | */ |
26 | 26 | final class Return_ extends TagWithType implements Factory\StaticMethod |
27 | 27 | { |
28 | - public function __construct(Type $type, ?Description $description = null) |
|
29 | - { |
|
30 | - $this->name = 'return'; |
|
31 | - $this->type = $type; |
|
32 | - $this->description = $description; |
|
33 | - } |
|
28 | + public function __construct(Type $type, ?Description $description = null) |
|
29 | + { |
|
30 | + $this->name = 'return'; |
|
31 | + $this->type = $type; |
|
32 | + $this->description = $description; |
|
33 | + } |
|
34 | 34 | |
35 | - public static function create( |
|
36 | - string $body, |
|
37 | - ?TypeResolver $typeResolver = null, |
|
38 | - ?DescriptionFactory $descriptionFactory = null, |
|
39 | - ?TypeContext $context = null |
|
40 | - ): self { |
|
41 | - Assert::notNull($typeResolver); |
|
42 | - Assert::notNull($descriptionFactory); |
|
35 | + public static function create( |
|
36 | + string $body, |
|
37 | + ?TypeResolver $typeResolver = null, |
|
38 | + ?DescriptionFactory $descriptionFactory = null, |
|
39 | + ?TypeContext $context = null |
|
40 | + ): self { |
|
41 | + Assert::notNull($typeResolver); |
|
42 | + Assert::notNull($descriptionFactory); |
|
43 | 43 | |
44 | - [$type, $description] = self::extractTypeFromBody($body); |
|
44 | + [$type, $description] = self::extractTypeFromBody($body); |
|
45 | 45 | |
46 | - $type = $typeResolver->resolve($type, $context); |
|
47 | - $description = $descriptionFactory->create($description, $context); |
|
46 | + $type = $typeResolver->resolve($type, $context); |
|
47 | + $description = $descriptionFactory->create($description, $context); |
|
48 | 48 | |
49 | - return new static($type, $description); |
|
50 | - } |
|
49 | + return new static($type, $description); |
|
50 | + } |
|
51 | 51 | |
52 | - public function __toString(): string |
|
53 | - { |
|
54 | - if ($this->description) { |
|
55 | - $description = $this->description->render(); |
|
56 | - } else { |
|
57 | - $description = ''; |
|
58 | - } |
|
52 | + public function __toString(): string |
|
53 | + { |
|
54 | + if ($this->description) { |
|
55 | + $description = $this->description->render(); |
|
56 | + } else { |
|
57 | + $description = ''; |
|
58 | + } |
|
59 | 59 | |
60 | - $type = $this->type ? '' . $this->type : 'mixed'; |
|
60 | + $type = $this->type ? '' . $this->type : 'mixed'; |
|
61 | 61 | |
62 | - return $type . ($description !== '' ? ' ' . $description : ''); |
|
63 | - } |
|
62 | + return $type . ($description !== '' ? ' ' . $description : ''); |
|
63 | + } |
|
64 | 64 | } |
@@ -57,8 +57,8 @@ |
||
57 | 57 | $description = ''; |
58 | 58 | } |
59 | 59 | |
60 | - $type = $this->type ? '' . $this->type : 'mixed'; |
|
60 | + $type = $this->type ? ''.$this->type : 'mixed'; |
|
61 | 61 | |
62 | - return $type . ($description !== '' ? ' ' . $description : ''); |
|
62 | + return $type.($description !== '' ? ' '.$description : ''); |
|
63 | 63 | } |
64 | 64 | } |
@@ -28,173 +28,173 @@ |
||
28 | 28 | */ |
29 | 29 | final class Example implements Tag, Factory\StaticMethod |
30 | 30 | { |
31 | - /** @var string Path to a file to use as an example. May also be an absolute URI. */ |
|
32 | - private $filePath; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var bool Whether the file path component represents an URI. This determines how the file portion |
|
36 | - * appears at {@link getContent()}. |
|
37 | - */ |
|
38 | - private $isURI; |
|
39 | - |
|
40 | - /** @var int */ |
|
41 | - private $startingLine; |
|
42 | - |
|
43 | - /** @var int */ |
|
44 | - private $lineCount; |
|
45 | - |
|
46 | - /** @var string|null */ |
|
47 | - private $content; |
|
48 | - |
|
49 | - public function __construct( |
|
50 | - string $filePath, |
|
51 | - bool $isURI, |
|
52 | - int $startingLine, |
|
53 | - int $lineCount, |
|
54 | - ?string $content |
|
55 | - ) { |
|
56 | - Assert::stringNotEmpty($filePath); |
|
57 | - Assert::greaterThanEq($startingLine, 1); |
|
58 | - Assert::greaterThanEq($lineCount, 0); |
|
59 | - |
|
60 | - $this->filePath = $filePath; |
|
61 | - $this->startingLine = $startingLine; |
|
62 | - $this->lineCount = $lineCount; |
|
63 | - if ($content !== null) { |
|
64 | - $this->content = trim($content); |
|
65 | - } |
|
66 | - |
|
67 | - $this->isURI = $isURI; |
|
68 | - } |
|
69 | - |
|
70 | - public function getContent(): string |
|
71 | - { |
|
72 | - if ($this->content === null || $this->content === '') { |
|
73 | - $filePath = $this->filePath; |
|
74 | - if ($this->isURI) { |
|
75 | - $filePath = $this->isUriRelative($this->filePath) |
|
76 | - ? str_replace('%2F', '/', rawurlencode($this->filePath)) |
|
77 | - : $this->filePath; |
|
78 | - } |
|
79 | - |
|
80 | - return trim($filePath); |
|
81 | - } |
|
82 | - |
|
83 | - return $this->content; |
|
84 | - } |
|
85 | - |
|
86 | - public function getDescription(): ?string |
|
87 | - { |
|
88 | - return $this->content; |
|
89 | - } |
|
90 | - |
|
91 | - public static function create(string $body): ?Tag |
|
92 | - { |
|
93 | - // File component: File path in quotes or File URI / Source information |
|
94 | - if (!preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - $filePath = null; |
|
99 | - $fileUri = null; |
|
100 | - if ($matches[1] !== '') { |
|
101 | - $filePath = $matches[1]; |
|
102 | - } else { |
|
103 | - $fileUri = $matches[2]; |
|
104 | - } |
|
105 | - |
|
106 | - $startingLine = 1; |
|
107 | - $lineCount = 0; |
|
108 | - $description = null; |
|
109 | - |
|
110 | - if (array_key_exists(3, $matches)) { |
|
111 | - $description = $matches[3]; |
|
112 | - |
|
113 | - // Starting line / Number of lines / Description |
|
114 | - if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) { |
|
115 | - $startingLine = (int) $contentMatches[1]; |
|
116 | - if (isset($contentMatches[2])) { |
|
117 | - $lineCount = (int) $contentMatches[2]; |
|
118 | - } |
|
119 | - |
|
120 | - if (array_key_exists(3, $contentMatches)) { |
|
121 | - $description = $contentMatches[3]; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - return new static( |
|
127 | - $filePath ?? ($fileUri ?? ''), |
|
128 | - $fileUri !== null, |
|
129 | - $startingLine, |
|
130 | - $lineCount, |
|
131 | - $description |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns the file path. |
|
137 | - * |
|
138 | - * @return string Path to a file to use as an example. |
|
139 | - * May also be an absolute URI. |
|
140 | - */ |
|
141 | - public function getFilePath(): string |
|
142 | - { |
|
143 | - return trim($this->filePath, '"'); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns a string representation for this tag. |
|
148 | - */ |
|
149 | - public function __toString(): string |
|
150 | - { |
|
151 | - $filePath = $this->filePath; |
|
152 | - $isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0; |
|
153 | - $startingLine = !$isDefaultLine ? (string) $this->startingLine : ''; |
|
154 | - $lineCount = !$isDefaultLine ? (string) $this->lineCount : ''; |
|
155 | - $content = (string) $this->content; |
|
156 | - |
|
157 | - return $filePath |
|
158 | - . ($startingLine !== '' |
|
159 | - ? ($filePath !== '' ? ' ' : '') . $startingLine |
|
160 | - : '') |
|
161 | - . ($lineCount !== '' |
|
162 | - ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount |
|
163 | - : '') |
|
164 | - . ($content !== '' |
|
165 | - ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content |
|
166 | - : ''); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute). |
|
171 | - */ |
|
172 | - private function isUriRelative(string $uri): bool |
|
173 | - { |
|
174 | - return strpos($uri, ':') === false; |
|
175 | - } |
|
176 | - |
|
177 | - public function getStartingLine(): int |
|
178 | - { |
|
179 | - return $this->startingLine; |
|
180 | - } |
|
181 | - |
|
182 | - public function getLineCount(): int |
|
183 | - { |
|
184 | - return $this->lineCount; |
|
185 | - } |
|
186 | - |
|
187 | - public function getName(): string |
|
188 | - { |
|
189 | - return 'example'; |
|
190 | - } |
|
191 | - |
|
192 | - public function render(?Formatter $formatter = null): string |
|
193 | - { |
|
194 | - if ($formatter === null) { |
|
195 | - $formatter = new Formatter\PassthroughFormatter(); |
|
196 | - } |
|
197 | - |
|
198 | - return $formatter->format($this); |
|
199 | - } |
|
31 | + /** @var string Path to a file to use as an example. May also be an absolute URI. */ |
|
32 | + private $filePath; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var bool Whether the file path component represents an URI. This determines how the file portion |
|
36 | + * appears at {@link getContent()}. |
|
37 | + */ |
|
38 | + private $isURI; |
|
39 | + |
|
40 | + /** @var int */ |
|
41 | + private $startingLine; |
|
42 | + |
|
43 | + /** @var int */ |
|
44 | + private $lineCount; |
|
45 | + |
|
46 | + /** @var string|null */ |
|
47 | + private $content; |
|
48 | + |
|
49 | + public function __construct( |
|
50 | + string $filePath, |
|
51 | + bool $isURI, |
|
52 | + int $startingLine, |
|
53 | + int $lineCount, |
|
54 | + ?string $content |
|
55 | + ) { |
|
56 | + Assert::stringNotEmpty($filePath); |
|
57 | + Assert::greaterThanEq($startingLine, 1); |
|
58 | + Assert::greaterThanEq($lineCount, 0); |
|
59 | + |
|
60 | + $this->filePath = $filePath; |
|
61 | + $this->startingLine = $startingLine; |
|
62 | + $this->lineCount = $lineCount; |
|
63 | + if ($content !== null) { |
|
64 | + $this->content = trim($content); |
|
65 | + } |
|
66 | + |
|
67 | + $this->isURI = $isURI; |
|
68 | + } |
|
69 | + |
|
70 | + public function getContent(): string |
|
71 | + { |
|
72 | + if ($this->content === null || $this->content === '') { |
|
73 | + $filePath = $this->filePath; |
|
74 | + if ($this->isURI) { |
|
75 | + $filePath = $this->isUriRelative($this->filePath) |
|
76 | + ? str_replace('%2F', '/', rawurlencode($this->filePath)) |
|
77 | + : $this->filePath; |
|
78 | + } |
|
79 | + |
|
80 | + return trim($filePath); |
|
81 | + } |
|
82 | + |
|
83 | + return $this->content; |
|
84 | + } |
|
85 | + |
|
86 | + public function getDescription(): ?string |
|
87 | + { |
|
88 | + return $this->content; |
|
89 | + } |
|
90 | + |
|
91 | + public static function create(string $body): ?Tag |
|
92 | + { |
|
93 | + // File component: File path in quotes or File URI / Source information |
|
94 | + if (!preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + $filePath = null; |
|
99 | + $fileUri = null; |
|
100 | + if ($matches[1] !== '') { |
|
101 | + $filePath = $matches[1]; |
|
102 | + } else { |
|
103 | + $fileUri = $matches[2]; |
|
104 | + } |
|
105 | + |
|
106 | + $startingLine = 1; |
|
107 | + $lineCount = 0; |
|
108 | + $description = null; |
|
109 | + |
|
110 | + if (array_key_exists(3, $matches)) { |
|
111 | + $description = $matches[3]; |
|
112 | + |
|
113 | + // Starting line / Number of lines / Description |
|
114 | + if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) { |
|
115 | + $startingLine = (int) $contentMatches[1]; |
|
116 | + if (isset($contentMatches[2])) { |
|
117 | + $lineCount = (int) $contentMatches[2]; |
|
118 | + } |
|
119 | + |
|
120 | + if (array_key_exists(3, $contentMatches)) { |
|
121 | + $description = $contentMatches[3]; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + return new static( |
|
127 | + $filePath ?? ($fileUri ?? ''), |
|
128 | + $fileUri !== null, |
|
129 | + $startingLine, |
|
130 | + $lineCount, |
|
131 | + $description |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns the file path. |
|
137 | + * |
|
138 | + * @return string Path to a file to use as an example. |
|
139 | + * May also be an absolute URI. |
|
140 | + */ |
|
141 | + public function getFilePath(): string |
|
142 | + { |
|
143 | + return trim($this->filePath, '"'); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns a string representation for this tag. |
|
148 | + */ |
|
149 | + public function __toString(): string |
|
150 | + { |
|
151 | + $filePath = $this->filePath; |
|
152 | + $isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0; |
|
153 | + $startingLine = !$isDefaultLine ? (string) $this->startingLine : ''; |
|
154 | + $lineCount = !$isDefaultLine ? (string) $this->lineCount : ''; |
|
155 | + $content = (string) $this->content; |
|
156 | + |
|
157 | + return $filePath |
|
158 | + . ($startingLine !== '' |
|
159 | + ? ($filePath !== '' ? ' ' : '') . $startingLine |
|
160 | + : '') |
|
161 | + . ($lineCount !== '' |
|
162 | + ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount |
|
163 | + : '') |
|
164 | + . ($content !== '' |
|
165 | + ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content |
|
166 | + : ''); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute). |
|
171 | + */ |
|
172 | + private function isUriRelative(string $uri): bool |
|
173 | + { |
|
174 | + return strpos($uri, ':') === false; |
|
175 | + } |
|
176 | + |
|
177 | + public function getStartingLine(): int |
|
178 | + { |
|
179 | + return $this->startingLine; |
|
180 | + } |
|
181 | + |
|
182 | + public function getLineCount(): int |
|
183 | + { |
|
184 | + return $this->lineCount; |
|
185 | + } |
|
186 | + |
|
187 | + public function getName(): string |
|
188 | + { |
|
189 | + return 'example'; |
|
190 | + } |
|
191 | + |
|
192 | + public function render(?Formatter $formatter = null): string |
|
193 | + { |
|
194 | + if ($formatter === null) { |
|
195 | + $formatter = new Formatter\PassthroughFormatter(); |
|
196 | + } |
|
197 | + |
|
198 | + return $formatter->format($this); |
|
199 | + } |
|
200 | 200 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | public static function create(string $body): ?Tag |
92 | 92 | { |
93 | 93 | // File component: File path in quotes or File URI / Source information |
94 | - if (!preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { |
|
94 | + if ( ! preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { |
|
95 | 95 | return null; |
96 | 96 | } |
97 | 97 | |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | { |
151 | 151 | $filePath = $this->filePath; |
152 | 152 | $isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0; |
153 | - $startingLine = !$isDefaultLine ? (string) $this->startingLine : ''; |
|
154 | - $lineCount = !$isDefaultLine ? (string) $this->lineCount : ''; |
|
153 | + $startingLine = ! $isDefaultLine ? (string) $this->startingLine : ''; |
|
154 | + $lineCount = ! $isDefaultLine ? (string) $this->lineCount : ''; |
|
155 | 155 | $content = (string) $this->content; |
156 | 156 | |
157 | 157 | return $filePath |
158 | 158 | . ($startingLine !== '' |
159 | - ? ($filePath !== '' ? ' ' : '') . $startingLine |
|
159 | + ? ($filePath !== '' ? ' ' : '').$startingLine |
|
160 | 160 | : '') |
161 | 161 | . ($lineCount !== '' |
162 | - ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount |
|
162 | + ? ($filePath !== '' || $startingLine !== '' ? ' ' : '').$lineCount |
|
163 | 163 | : '') |
164 | 164 | . ($content !== '' |
165 | - ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content |
|
165 | + ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '').$content |
|
166 | 166 | : ''); |
167 | 167 | } |
168 | 168 |