@@ -24,55 +24,55 @@ |
||
24 | 24 | */ |
25 | 25 | final class Link extends BaseTag implements Factory\StaticMethod |
26 | 26 | { |
27 | - /** @var string */ |
|
28 | - protected $name = 'link'; |
|
27 | + /** @var string */ |
|
28 | + protected $name = 'link'; |
|
29 | 29 | |
30 | - /** @var string */ |
|
31 | - private $link; |
|
30 | + /** @var string */ |
|
31 | + private $link; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Initializes a link to a URL. |
|
35 | - */ |
|
36 | - public function __construct(string $link, ?Description $description = null) |
|
37 | - { |
|
38 | - $this->link = $link; |
|
39 | - $this->description = $description; |
|
40 | - } |
|
33 | + /** |
|
34 | + * Initializes a link to a URL. |
|
35 | + */ |
|
36 | + public function __construct(string $link, ?Description $description = null) |
|
37 | + { |
|
38 | + $this->link = $link; |
|
39 | + $this->description = $description; |
|
40 | + } |
|
41 | 41 | |
42 | - public static function create( |
|
43 | - string $body, |
|
44 | - ?DescriptionFactory $descriptionFactory = null, |
|
45 | - ?TypeContext $context = null |
|
46 | - ): self { |
|
47 | - Assert::notNull($descriptionFactory); |
|
42 | + public static function create( |
|
43 | + string $body, |
|
44 | + ?DescriptionFactory $descriptionFactory = null, |
|
45 | + ?TypeContext $context = null |
|
46 | + ): self { |
|
47 | + Assert::notNull($descriptionFactory); |
|
48 | 48 | |
49 | - $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
50 | - $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; |
|
49 | + $parts = Utils::pregSplit('/\s+/Su', $body, 2); |
|
50 | + $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; |
|
51 | 51 | |
52 | - return new static($parts[0], $description); |
|
53 | - } |
|
52 | + return new static($parts[0], $description); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Gets the link |
|
57 | - */ |
|
58 | - public function getLink(): string |
|
59 | - { |
|
60 | - return $this->link; |
|
61 | - } |
|
55 | + /** |
|
56 | + * Gets the link |
|
57 | + */ |
|
58 | + public function getLink(): string |
|
59 | + { |
|
60 | + return $this->link; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns a string representation for this tag. |
|
65 | - */ |
|
66 | - public function __toString(): string |
|
67 | - { |
|
68 | - if ($this->description) { |
|
69 | - $description = $this->description->render(); |
|
70 | - } else { |
|
71 | - $description = ''; |
|
72 | - } |
|
63 | + /** |
|
64 | + * Returns a string representation for this tag. |
|
65 | + */ |
|
66 | + public function __toString(): string |
|
67 | + { |
|
68 | + if ($this->description) { |
|
69 | + $description = $this->description->render(); |
|
70 | + } else { |
|
71 | + $description = ''; |
|
72 | + } |
|
73 | 73 | |
74 | - $link = $this->link; |
|
74 | + $link = $this->link; |
|
75 | 75 | |
76 | - return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : ''); |
|
77 | - } |
|
76 | + return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : ''); |
|
77 | + } |
|
78 | 78 | } |
@@ -73,6 +73,6 @@ |
||
73 | 73 | |
74 | 74 | $link = $this->link; |
75 | 75 | |
76 | - return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : ''); |
|
76 | + return $link.($description !== '' ? ($link !== '' ? ' ' : '').$description : ''); |
|
77 | 77 | } |
78 | 78 | } |
@@ -34,88 +34,88 @@ |
||
34 | 34 | */ |
35 | 35 | final class PropertyWrite extends TagWithType implements Factory\StaticMethod |
36 | 36 | { |
37 | - /** @var string */ |
|
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-write'; |
|
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 */ |
|
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-write'; |
|
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 | } |
@@ -34,89 +34,89 @@ |
||
34 | 34 | */ |
35 | 35 | final class Var_ 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 = 'var'; |
|
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 | - |
|
62 | - $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | - $type = null; |
|
64 | - $variableName = ''; |
|
65 | - |
|
66 | - // if the first item that is encountered is not a variable; it is a type |
|
67 | - if ($firstPart && $firstPart[0] !== '$') { |
|
68 | - $type = $typeResolver->resolve($firstPart, $context); |
|
69 | - } else { |
|
70 | - // first part is not a type; we should prepend it to the parts array for further processing |
|
71 | - array_unshift($parts, $firstPart); |
|
72 | - } |
|
73 | - |
|
74 | - // if the next item starts with a $ it must be the variable name |
|
75 | - if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
76 | - $variableName = array_shift($parts); |
|
77 | - if ($type) { |
|
78 | - array_shift($parts); |
|
79 | - } |
|
80 | - |
|
81 | - Assert::notNull($variableName); |
|
82 | - |
|
83 | - $variableName = substr($variableName, 1); |
|
84 | - } |
|
85 | - |
|
86 | - $description = $descriptionFactory->create(implode('', $parts), $context); |
|
87 | - |
|
88 | - return new static($variableName, $type, $description); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns the variable's name. |
|
93 | - */ |
|
94 | - public function getVariableName(): ?string |
|
95 | - { |
|
96 | - return $this->variableName; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns a string representation for this tag. |
|
101 | - */ |
|
102 | - public function __toString(): string |
|
103 | - { |
|
104 | - if ($this->description) { |
|
105 | - $description = $this->description->render(); |
|
106 | - } else { |
|
107 | - $description = ''; |
|
108 | - } |
|
109 | - |
|
110 | - if ($this->variableName) { |
|
111 | - $variableName = '$' . $this->variableName; |
|
112 | - } else { |
|
113 | - $variableName = ''; |
|
114 | - } |
|
115 | - |
|
116 | - $type = (string) $this->type; |
|
117 | - |
|
118 | - return $type |
|
119 | - . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
120 | - . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
121 | - } |
|
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 = 'var'; |
|
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 | + |
|
62 | + $parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
63 | + $type = null; |
|
64 | + $variableName = ''; |
|
65 | + |
|
66 | + // if the first item that is encountered is not a variable; it is a type |
|
67 | + if ($firstPart && $firstPart[0] !== '$') { |
|
68 | + $type = $typeResolver->resolve($firstPart, $context); |
|
69 | + } else { |
|
70 | + // first part is not a type; we should prepend it to the parts array for further processing |
|
71 | + array_unshift($parts, $firstPart); |
|
72 | + } |
|
73 | + |
|
74 | + // if the next item starts with a $ it must be the variable name |
|
75 | + if (isset($parts[0]) && strpos($parts[0], '$') === 0) { |
|
76 | + $variableName = array_shift($parts); |
|
77 | + if ($type) { |
|
78 | + array_shift($parts); |
|
79 | + } |
|
80 | + |
|
81 | + Assert::notNull($variableName); |
|
82 | + |
|
83 | + $variableName = substr($variableName, 1); |
|
84 | + } |
|
85 | + |
|
86 | + $description = $descriptionFactory->create(implode('', $parts), $context); |
|
87 | + |
|
88 | + return new static($variableName, $type, $description); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns the variable's name. |
|
93 | + */ |
|
94 | + public function getVariableName(): ?string |
|
95 | + { |
|
96 | + return $this->variableName; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns a string representation for this tag. |
|
101 | + */ |
|
102 | + public function __toString(): string |
|
103 | + { |
|
104 | + if ($this->description) { |
|
105 | + $description = $this->description->render(); |
|
106 | + } else { |
|
107 | + $description = ''; |
|
108 | + } |
|
109 | + |
|
110 | + if ($this->variableName) { |
|
111 | + $variableName = '$' . $this->variableName; |
|
112 | + } else { |
|
113 | + $variableName = ''; |
|
114 | + } |
|
115 | + |
|
116 | + $type = (string) $this->type; |
|
117 | + |
|
118 | + return $type |
|
119 | + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') |
|
120 | + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); |
|
121 | + } |
|
122 | 122 | } |
@@ -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 | } |
@@ -31,129 +31,129 @@ |
||
31 | 31 | */ |
32 | 32 | class ExampleFinder |
33 | 33 | { |
34 | - /** @var string */ |
|
35 | - private $sourceDirectory = ''; |
|
36 | - |
|
37 | - /** @var string[] */ |
|
38 | - private $exampleDirectories = []; |
|
39 | - |
|
40 | - /** |
|
41 | - * Attempts to find the example contents for the given descriptor. |
|
42 | - */ |
|
43 | - public function find(Example $example): string |
|
44 | - { |
|
45 | - $filename = $example->getFilePath(); |
|
46 | - |
|
47 | - $file = $this->getExampleFileContents($filename); |
|
48 | - if (!$file) { |
|
49 | - return sprintf('** File not found : %s **', $filename); |
|
50 | - } |
|
51 | - |
|
52 | - return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount())); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Registers the project's root directory where an 'examples' folder can be expected. |
|
57 | - */ |
|
58 | - public function setSourceDirectory(string $directory = ''): void |
|
59 | - { |
|
60 | - $this->sourceDirectory = $directory; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the project's root directory where an 'examples' folder can be expected. |
|
65 | - */ |
|
66 | - public function getSourceDirectory(): string |
|
67 | - { |
|
68 | - return $this->sourceDirectory; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Registers a series of directories that may contain examples. |
|
73 | - * |
|
74 | - * @param string[] $directories |
|
75 | - */ |
|
76 | - public function setExampleDirectories(array $directories): void |
|
77 | - { |
|
78 | - $this->exampleDirectories = $directories; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns a series of directories that may contain examples. |
|
83 | - * |
|
84 | - * @return string[] |
|
85 | - */ |
|
86 | - public function getExampleDirectories(): array |
|
87 | - { |
|
88 | - return $this->exampleDirectories; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Attempts to find the requested example file and returns its contents or null if no file was found. |
|
93 | - * |
|
94 | - * This method will try several methods in search of the given example file, the first one it encounters is |
|
95 | - * returned: |
|
96 | - * |
|
97 | - * 1. Iterates through all examples folders for the given filename |
|
98 | - * 2. Checks the source folder for the given filename |
|
99 | - * 3. Checks the 'examples' folder in the current working directory for examples |
|
100 | - * 4. Checks the path relative to the current working directory for the given filename |
|
101 | - * |
|
102 | - * @return string[] all lines of the example file |
|
103 | - */ |
|
104 | - private function getExampleFileContents(string $filename): ?array |
|
105 | - { |
|
106 | - $normalizedPath = null; |
|
107 | - |
|
108 | - foreach ($this->exampleDirectories as $directory) { |
|
109 | - $exampleFileFromConfig = $this->constructExamplePath($directory, $filename); |
|
110 | - if (is_readable($exampleFileFromConfig)) { |
|
111 | - $normalizedPath = $exampleFileFromConfig; |
|
112 | - break; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - if (!$normalizedPath) { |
|
117 | - if (is_readable($this->getExamplePathFromSource($filename))) { |
|
118 | - $normalizedPath = $this->getExamplePathFromSource($filename); |
|
119 | - } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) { |
|
120 | - $normalizedPath = $this->getExamplePathFromExampleDirectory($filename); |
|
121 | - } elseif (is_readable($filename)) { |
|
122 | - $normalizedPath = $filename; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - $lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false; |
|
127 | - |
|
128 | - return $lines !== false ? $lines : null; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get example filepath based on the example directory inside your project. |
|
133 | - */ |
|
134 | - private function getExamplePathFromExampleDirectory(string $file): string |
|
135 | - { |
|
136 | - return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns a path to the example file in the given directory.. |
|
141 | - */ |
|
142 | - private function constructExamplePath(string $directory, string $file): string |
|
143 | - { |
|
144 | - return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get example filepath based on sourcecode. |
|
149 | - */ |
|
150 | - private function getExamplePathFromSource(string $file): string |
|
151 | - { |
|
152 | - return sprintf( |
|
153 | - '%s%s%s', |
|
154 | - trim($this->getSourceDirectory(), '\\/'), |
|
155 | - DIRECTORY_SEPARATOR, |
|
156 | - trim($file, '"') |
|
157 | - ); |
|
158 | - } |
|
34 | + /** @var string */ |
|
35 | + private $sourceDirectory = ''; |
|
36 | + |
|
37 | + /** @var string[] */ |
|
38 | + private $exampleDirectories = []; |
|
39 | + |
|
40 | + /** |
|
41 | + * Attempts to find the example contents for the given descriptor. |
|
42 | + */ |
|
43 | + public function find(Example $example): string |
|
44 | + { |
|
45 | + $filename = $example->getFilePath(); |
|
46 | + |
|
47 | + $file = $this->getExampleFileContents($filename); |
|
48 | + if (!$file) { |
|
49 | + return sprintf('** File not found : %s **', $filename); |
|
50 | + } |
|
51 | + |
|
52 | + return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount())); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Registers the project's root directory where an 'examples' folder can be expected. |
|
57 | + */ |
|
58 | + public function setSourceDirectory(string $directory = ''): void |
|
59 | + { |
|
60 | + $this->sourceDirectory = $directory; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the project's root directory where an 'examples' folder can be expected. |
|
65 | + */ |
|
66 | + public function getSourceDirectory(): string |
|
67 | + { |
|
68 | + return $this->sourceDirectory; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Registers a series of directories that may contain examples. |
|
73 | + * |
|
74 | + * @param string[] $directories |
|
75 | + */ |
|
76 | + public function setExampleDirectories(array $directories): void |
|
77 | + { |
|
78 | + $this->exampleDirectories = $directories; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns a series of directories that may contain examples. |
|
83 | + * |
|
84 | + * @return string[] |
|
85 | + */ |
|
86 | + public function getExampleDirectories(): array |
|
87 | + { |
|
88 | + return $this->exampleDirectories; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Attempts to find the requested example file and returns its contents or null if no file was found. |
|
93 | + * |
|
94 | + * This method will try several methods in search of the given example file, the first one it encounters is |
|
95 | + * returned: |
|
96 | + * |
|
97 | + * 1. Iterates through all examples folders for the given filename |
|
98 | + * 2. Checks the source folder for the given filename |
|
99 | + * 3. Checks the 'examples' folder in the current working directory for examples |
|
100 | + * 4. Checks the path relative to the current working directory for the given filename |
|
101 | + * |
|
102 | + * @return string[] all lines of the example file |
|
103 | + */ |
|
104 | + private function getExampleFileContents(string $filename): ?array |
|
105 | + { |
|
106 | + $normalizedPath = null; |
|
107 | + |
|
108 | + foreach ($this->exampleDirectories as $directory) { |
|
109 | + $exampleFileFromConfig = $this->constructExamplePath($directory, $filename); |
|
110 | + if (is_readable($exampleFileFromConfig)) { |
|
111 | + $normalizedPath = $exampleFileFromConfig; |
|
112 | + break; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + if (!$normalizedPath) { |
|
117 | + if (is_readable($this->getExamplePathFromSource($filename))) { |
|
118 | + $normalizedPath = $this->getExamplePathFromSource($filename); |
|
119 | + } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) { |
|
120 | + $normalizedPath = $this->getExamplePathFromExampleDirectory($filename); |
|
121 | + } elseif (is_readable($filename)) { |
|
122 | + $normalizedPath = $filename; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + $lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false; |
|
127 | + |
|
128 | + return $lines !== false ? $lines : null; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get example filepath based on the example directory inside your project. |
|
133 | + */ |
|
134 | + private function getExamplePathFromExampleDirectory(string $file): string |
|
135 | + { |
|
136 | + return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns a path to the example file in the given directory.. |
|
141 | + */ |
|
142 | + private function constructExamplePath(string $directory, string $file): string |
|
143 | + { |
|
144 | + return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get example filepath based on sourcecode. |
|
149 | + */ |
|
150 | + private function getExamplePathFromSource(string $file): string |
|
151 | + { |
|
152 | + return sprintf( |
|
153 | + '%s%s%s', |
|
154 | + trim($this->getSourceDirectory(), '\\/'), |
|
155 | + DIRECTORY_SEPARATOR, |
|
156 | + trim($file, '"') |
|
157 | + ); |
|
158 | + } |
|
159 | 159 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $filename = $example->getFilePath(); |
46 | 46 | |
47 | 47 | $file = $this->getExampleFileContents($filename); |
48 | - if (!$file) { |
|
48 | + if ( ! $file) { |
|
49 | 49 | return sprintf('** File not found : %s **', $filename); |
50 | 50 | } |
51 | 51 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - if (!$normalizedPath) { |
|
116 | + if ( ! $normalizedPath) { |
|
117 | 117 | if (is_readable($this->getExamplePathFromSource($filename))) { |
118 | 118 | $normalizedPath = $this->getExamplePathFromSource($filename); |
119 | 119 | } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | private function getExamplePathFromExampleDirectory(string $file): string |
135 | 135 | { |
136 | - return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; |
|
136 | + return getcwd().DIRECTORY_SEPARATOR.'examples'.DIRECTORY_SEPARATOR.$file; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | private function constructExamplePath(string $directory, string $file): string |
143 | 143 | { |
144 | - return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; |
|
144 | + return rtrim($directory, '\\/').DIRECTORY_SEPARATOR.$file; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -17,15 +17,15 @@ |
||
17 | 17 | |
18 | 18 | interface Tag |
19 | 19 | { |
20 | - public function getName(): string; |
|
20 | + public function getName(): string; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return Tag|mixed Class that implements Tag |
|
24 | - * @phpstan-return ?Tag |
|
25 | - */ |
|
26 | - public static function create(string $body); |
|
22 | + /** |
|
23 | + * @return Tag|mixed Class that implements Tag |
|
24 | + * @phpstan-return ?Tag |
|
25 | + */ |
|
26 | + public static function create(string $body); |
|
27 | 27 | |
28 | - public function render(?Formatter $formatter = null): string; |
|
28 | + public function render(?Formatter $formatter = null): string; |
|
29 | 29 | |
30 | - public function __toString(): string; |
|
30 | + public function __toString(): string; |
|
31 | 31 | } |
@@ -16,29 +16,29 @@ |
||
16 | 16 | |
17 | 17 | final class PcreException extends InvalidArgumentException |
18 | 18 | { |
19 | - public static function createFromPhpError(int $errorCode): self |
|
20 | - { |
|
21 | - switch ($errorCode) { |
|
22 | - case PREG_BACKTRACK_LIMIT_ERROR: |
|
23 | - return new self('Backtrack limit error'); |
|
19 | + public static function createFromPhpError(int $errorCode): self |
|
20 | + { |
|
21 | + switch ($errorCode) { |
|
22 | + case PREG_BACKTRACK_LIMIT_ERROR: |
|
23 | + return new self('Backtrack limit error'); |
|
24 | 24 | |
25 | - case PREG_RECURSION_LIMIT_ERROR: |
|
26 | - return new self('Recursion limit error'); |
|
25 | + case PREG_RECURSION_LIMIT_ERROR: |
|
26 | + return new self('Recursion limit error'); |
|
27 | 27 | |
28 | - case PREG_BAD_UTF8_ERROR: |
|
29 | - return new self('Bad UTF8 error'); |
|
28 | + case PREG_BAD_UTF8_ERROR: |
|
29 | + return new self('Bad UTF8 error'); |
|
30 | 30 | |
31 | - case PREG_BAD_UTF8_OFFSET_ERROR: |
|
32 | - return new self('Bad UTF8 offset error'); |
|
31 | + case PREG_BAD_UTF8_OFFSET_ERROR: |
|
32 | + return new self('Bad UTF8 offset error'); |
|
33 | 33 | |
34 | - case PREG_JIT_STACKLIMIT_ERROR: |
|
35 | - return new self('Jit stacklimit error'); |
|
34 | + case PREG_JIT_STACKLIMIT_ERROR: |
|
35 | + return new self('Jit stacklimit error'); |
|
36 | 36 | |
37 | - case PREG_NO_ERROR: |
|
38 | - case PREG_INTERNAL_ERROR: |
|
39 | - default: |
|
40 | - } |
|
37 | + case PREG_NO_ERROR: |
|
38 | + case PREG_INTERNAL_ERROR: |
|
39 | + default: |
|
40 | + } |
|
41 | 41 | |
42 | - return new self('Unknown Pcre error'); |
|
43 | - } |
|
42 | + return new self('Unknown Pcre error'); |
|
43 | + } |
|
44 | 44 | } |
@@ -9,15 +9,15 @@ |
||
9 | 9 | // phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix |
10 | 10 | interface DocBlockFactoryInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Factory method for easy instantiation. |
|
14 | - * |
|
15 | - * @param array<string, class-string<Tag>> $additionalTags |
|
16 | - */ |
|
17 | - public static function createInstance(array $additionalTags = []): DocBlockFactory; |
|
12 | + /** |
|
13 | + * Factory method for easy instantiation. |
|
14 | + * |
|
15 | + * @param array<string, class-string<Tag>> $additionalTags |
|
16 | + */ |
|
17 | + public static function createInstance(array $additionalTags = []): DocBlockFactory; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string|object $docblock |
|
21 | - */ |
|
22 | - public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock; |
|
19 | + /** |
|
20 | + * @param string|object $docblock |
|
21 | + */ |
|
22 | + public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock; |
|
23 | 23 | } |
@@ -12,35 +12,35 @@ |
||
12 | 12 | use Symfony\Polyfill\Ctype as p; |
13 | 13 | |
14 | 14 | if (!function_exists('ctype_alnum')) { |
15 | - function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } |
|
15 | + function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } |
|
16 | 16 | } |
17 | 17 | if (!function_exists('ctype_alpha')) { |
18 | - function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } |
|
18 | + function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } |
|
19 | 19 | } |
20 | 20 | if (!function_exists('ctype_cntrl')) { |
21 | - function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } |
|
21 | + function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } |
|
22 | 22 | } |
23 | 23 | if (!function_exists('ctype_digit')) { |
24 | - function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } |
|
24 | + function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } |
|
25 | 25 | } |
26 | 26 | if (!function_exists('ctype_graph')) { |
27 | - function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } |
|
27 | + function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } |
|
28 | 28 | } |
29 | 29 | if (!function_exists('ctype_lower')) { |
30 | - function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } |
|
30 | + function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } |
|
31 | 31 | } |
32 | 32 | if (!function_exists('ctype_print')) { |
33 | - function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } |
|
33 | + function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } |
|
34 | 34 | } |
35 | 35 | if (!function_exists('ctype_punct')) { |
36 | - function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } |
|
36 | + function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } |
|
37 | 37 | } |
38 | 38 | if (!function_exists('ctype_space')) { |
39 | - function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } |
|
39 | + function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } |
|
40 | 40 | } |
41 | 41 | if (!function_exists('ctype_upper')) { |
42 | - function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } |
|
42 | + function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } |
|
43 | 43 | } |
44 | 44 | if (!function_exists('ctype_xdigit')) { |
45 | - function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } |
|
45 | + function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } |
|
46 | 46 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Ctype as p; |
13 | 13 | |
14 | -if (!function_exists('ctype_alnum')) { |
|
14 | +if ( ! function_exists('ctype_alnum')) { |
|
15 | 15 | function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } |
16 | 16 | } |
17 | -if (!function_exists('ctype_alpha')) { |
|
17 | +if ( ! function_exists('ctype_alpha')) { |
|
18 | 18 | function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } |
19 | 19 | } |
20 | -if (!function_exists('ctype_cntrl')) { |
|
20 | +if ( ! function_exists('ctype_cntrl')) { |
|
21 | 21 | function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } |
22 | 22 | } |
23 | -if (!function_exists('ctype_digit')) { |
|
23 | +if ( ! function_exists('ctype_digit')) { |
|
24 | 24 | function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } |
25 | 25 | } |
26 | -if (!function_exists('ctype_graph')) { |
|
26 | +if ( ! function_exists('ctype_graph')) { |
|
27 | 27 | function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } |
28 | 28 | } |
29 | -if (!function_exists('ctype_lower')) { |
|
29 | +if ( ! function_exists('ctype_lower')) { |
|
30 | 30 | function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } |
31 | 31 | } |
32 | -if (!function_exists('ctype_print')) { |
|
32 | +if ( ! function_exists('ctype_print')) { |
|
33 | 33 | function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } |
34 | 34 | } |
35 | -if (!function_exists('ctype_punct')) { |
|
35 | +if ( ! function_exists('ctype_punct')) { |
|
36 | 36 | function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } |
37 | 37 | } |
38 | -if (!function_exists('ctype_space')) { |
|
38 | +if ( ! function_exists('ctype_space')) { |
|
39 | 39 | function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } |
40 | 40 | } |
41 | -if (!function_exists('ctype_upper')) { |
|
41 | +if ( ! function_exists('ctype_upper')) { |
|
42 | 42 | function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } |
43 | 43 | } |
44 | -if (!function_exists('ctype_xdigit')) { |
|
44 | +if ( ! function_exists('ctype_xdigit')) { |
|
45 | 45 | function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } |
46 | 46 | } |
@@ -20,213 +20,213 @@ |
||
20 | 20 | */ |
21 | 21 | final class Ctype |
22 | 22 | { |
23 | - /** |
|
24 | - * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. |
|
25 | - * |
|
26 | - * @see https://php.net/ctype-alnum |
|
27 | - * |
|
28 | - * @param mixed $text |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public static function ctype_alnum($text) |
|
33 | - { |
|
34 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
35 | - |
|
36 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns TRUE if every character in text is a letter, FALSE otherwise. |
|
41 | - * |
|
42 | - * @see https://php.net/ctype-alpha |
|
43 | - * |
|
44 | - * @param mixed $text |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public static function ctype_alpha($text) |
|
49 | - { |
|
50 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
51 | - |
|
52 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. |
|
57 | - * |
|
58 | - * @see https://php.net/ctype-cntrl |
|
59 | - * |
|
60 | - * @param mixed $text |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public static function ctype_cntrl($text) |
|
65 | - { |
|
66 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
67 | - |
|
68 | - return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. |
|
73 | - * |
|
74 | - * @see https://php.net/ctype-digit |
|
75 | - * |
|
76 | - * @param mixed $text |
|
77 | - * |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public static function ctype_digit($text) |
|
81 | - { |
|
82 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
83 | - |
|
84 | - return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. |
|
89 | - * |
|
90 | - * @see https://php.net/ctype-graph |
|
91 | - * |
|
92 | - * @param mixed $text |
|
93 | - * |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public static function ctype_graph($text) |
|
97 | - { |
|
98 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
99 | - |
|
100 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Returns TRUE if every character in text is a lowercase letter. |
|
105 | - * |
|
106 | - * @see https://php.net/ctype-lower |
|
107 | - * |
|
108 | - * @param mixed $text |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public static function ctype_lower($text) |
|
113 | - { |
|
114 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
115 | - |
|
116 | - return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. |
|
121 | - * |
|
122 | - * @see https://php.net/ctype-print |
|
123 | - * |
|
124 | - * @param mixed $text |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - public static function ctype_print($text) |
|
129 | - { |
|
130 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
131 | - |
|
132 | - return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. |
|
137 | - * |
|
138 | - * @see https://php.net/ctype-punct |
|
139 | - * |
|
140 | - * @param mixed $text |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - public static function ctype_punct($text) |
|
145 | - { |
|
146 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
147 | - |
|
148 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. |
|
153 | - * |
|
154 | - * @see https://php.net/ctype-space |
|
155 | - * |
|
156 | - * @param mixed $text |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public static function ctype_space($text) |
|
161 | - { |
|
162 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
163 | - |
|
164 | - return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns TRUE if every character in text is an uppercase letter. |
|
169 | - * |
|
170 | - * @see https://php.net/ctype-upper |
|
171 | - * |
|
172 | - * @param mixed $text |
|
173 | - * |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function ctype_upper($text) |
|
177 | - { |
|
178 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
179 | - |
|
180 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. |
|
185 | - * |
|
186 | - * @see https://php.net/ctype-xdigit |
|
187 | - * |
|
188 | - * @param mixed $text |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - public static function ctype_xdigit($text) |
|
193 | - { |
|
194 | - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
195 | - |
|
196 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Converts integers to their char versions according to normal ctype behaviour, if needed. |
|
201 | - * |
|
202 | - * If an integer between -128 and 255 inclusive is provided, |
|
203 | - * it is interpreted as the ASCII value of a single character |
|
204 | - * (negative values have 256 added in order to allow characters in the Extended ASCII range). |
|
205 | - * Any other integer is interpreted as a string containing the decimal digits of the integer. |
|
206 | - * |
|
207 | - * @param mixed $int |
|
208 | - * @param string $function |
|
209 | - * |
|
210 | - * @return mixed |
|
211 | - */ |
|
212 | - private static function convert_int_to_char_for_ctype($int, $function) |
|
213 | - { |
|
214 | - if (!\is_int($int)) { |
|
215 | - return $int; |
|
216 | - } |
|
217 | - |
|
218 | - if ($int < -128 || $int > 255) { |
|
219 | - return (string) $int; |
|
220 | - } |
|
221 | - |
|
222 | - if (\PHP_VERSION_ID >= 80100) { |
|
223 | - @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); |
|
224 | - } |
|
225 | - |
|
226 | - if ($int < 0) { |
|
227 | - $int += 256; |
|
228 | - } |
|
229 | - |
|
230 | - return \chr($int); |
|
231 | - } |
|
23 | + /** |
|
24 | + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. |
|
25 | + * |
|
26 | + * @see https://php.net/ctype-alnum |
|
27 | + * |
|
28 | + * @param mixed $text |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public static function ctype_alnum($text) |
|
33 | + { |
|
34 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
35 | + |
|
36 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns TRUE if every character in text is a letter, FALSE otherwise. |
|
41 | + * |
|
42 | + * @see https://php.net/ctype-alpha |
|
43 | + * |
|
44 | + * @param mixed $text |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public static function ctype_alpha($text) |
|
49 | + { |
|
50 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
51 | + |
|
52 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. |
|
57 | + * |
|
58 | + * @see https://php.net/ctype-cntrl |
|
59 | + * |
|
60 | + * @param mixed $text |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public static function ctype_cntrl($text) |
|
65 | + { |
|
66 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
67 | + |
|
68 | + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. |
|
73 | + * |
|
74 | + * @see https://php.net/ctype-digit |
|
75 | + * |
|
76 | + * @param mixed $text |
|
77 | + * |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public static function ctype_digit($text) |
|
81 | + { |
|
82 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
83 | + |
|
84 | + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. |
|
89 | + * |
|
90 | + * @see https://php.net/ctype-graph |
|
91 | + * |
|
92 | + * @param mixed $text |
|
93 | + * |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public static function ctype_graph($text) |
|
97 | + { |
|
98 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
99 | + |
|
100 | + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Returns TRUE if every character in text is a lowercase letter. |
|
105 | + * |
|
106 | + * @see https://php.net/ctype-lower |
|
107 | + * |
|
108 | + * @param mixed $text |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public static function ctype_lower($text) |
|
113 | + { |
|
114 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
115 | + |
|
116 | + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. |
|
121 | + * |
|
122 | + * @see https://php.net/ctype-print |
|
123 | + * |
|
124 | + * @param mixed $text |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + public static function ctype_print($text) |
|
129 | + { |
|
130 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
131 | + |
|
132 | + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. |
|
137 | + * |
|
138 | + * @see https://php.net/ctype-punct |
|
139 | + * |
|
140 | + * @param mixed $text |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + public static function ctype_punct($text) |
|
145 | + { |
|
146 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
147 | + |
|
148 | + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. |
|
153 | + * |
|
154 | + * @see https://php.net/ctype-space |
|
155 | + * |
|
156 | + * @param mixed $text |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public static function ctype_space($text) |
|
161 | + { |
|
162 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
163 | + |
|
164 | + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns TRUE if every character in text is an uppercase letter. |
|
169 | + * |
|
170 | + * @see https://php.net/ctype-upper |
|
171 | + * |
|
172 | + * @param mixed $text |
|
173 | + * |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function ctype_upper($text) |
|
177 | + { |
|
178 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
179 | + |
|
180 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. |
|
185 | + * |
|
186 | + * @see https://php.net/ctype-xdigit |
|
187 | + * |
|
188 | + * @param mixed $text |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + public static function ctype_xdigit($text) |
|
193 | + { |
|
194 | + $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
|
195 | + |
|
196 | + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Converts integers to their char versions according to normal ctype behaviour, if needed. |
|
201 | + * |
|
202 | + * If an integer between -128 and 255 inclusive is provided, |
|
203 | + * it is interpreted as the ASCII value of a single character |
|
204 | + * (negative values have 256 added in order to allow characters in the Extended ASCII range). |
|
205 | + * Any other integer is interpreted as a string containing the decimal digits of the integer. |
|
206 | + * |
|
207 | + * @param mixed $int |
|
208 | + * @param string $function |
|
209 | + * |
|
210 | + * @return mixed |
|
211 | + */ |
|
212 | + private static function convert_int_to_char_for_ctype($int, $function) |
|
213 | + { |
|
214 | + if (!\is_int($int)) { |
|
215 | + return $int; |
|
216 | + } |
|
217 | + |
|
218 | + if ($int < -128 || $int > 255) { |
|
219 | + return (string) $int; |
|
220 | + } |
|
221 | + |
|
222 | + if (\PHP_VERSION_ID >= 80100) { |
|
223 | + @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); |
|
224 | + } |
|
225 | + |
|
226 | + if ($int < 0) { |
|
227 | + $int += 256; |
|
228 | + } |
|
229 | + |
|
230 | + return \chr($int); |
|
231 | + } |
|
232 | 232 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
35 | 35 | |
36 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); |
|
36 | + return \is_string($text) && '' !== $text && ! preg_match('/[^A-Za-z0-9]/', $text); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
51 | 51 | |
52 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); |
|
52 | + return \is_string($text) && '' !== $text && ! preg_match('/[^A-Za-z]/', $text); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
67 | 67 | |
68 | - return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
68 | + return \is_string($text) && '' !== $text && ! preg_match('/[^\x00-\x1f\x7f]/', $text); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | { |
82 | 82 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
83 | 83 | |
84 | - return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); |
|
84 | + return \is_string($text) && '' !== $text && ! preg_match('/[^0-9]/', $text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
99 | 99 | |
100 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); |
|
100 | + return \is_string($text) && '' !== $text && ! preg_match('/[^!-~]/', $text); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
115 | 115 | |
116 | - return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); |
|
116 | + return \is_string($text) && '' !== $text && ! preg_match('/[^a-z]/', $text); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
131 | 131 | |
132 | - return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); |
|
132 | + return \is_string($text) && '' !== $text && ! preg_match('/[^ -~]/', $text); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
147 | 147 | |
148 | - return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
148 | + return \is_string($text) && '' !== $text && ! preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | { |
162 | 162 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
163 | 163 | |
164 | - return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); |
|
164 | + return \is_string($text) && '' !== $text && ! preg_match('/[^\s]/', $text); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | { |
178 | 178 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
179 | 179 | |
180 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); |
|
180 | + return \is_string($text) && '' !== $text && ! preg_match('/[^A-Z]/', $text); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | { |
194 | 194 | $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); |
195 | 195 | |
196 | - return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); |
|
196 | + return \is_string($text) && '' !== $text && ! preg_match('/[^A-Fa-f0-9]/', $text); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | private static function convert_int_to_char_for_ctype($int, $function) |
213 | 213 | { |
214 | - if (!\is_int($int)) { |
|
214 | + if ( ! \is_int($int)) { |
|
215 | 215 | return $int; |
216 | 216 | } |
217 | 217 |