diff --git a/src/Extension/Autolink/UrlAutolinkParser.php b/src/Extension/Autolink/UrlAutolinkParser.php index 6b4290a994..f44da3357e 100644 --- a/src/Extension/Autolink/UrlAutolinkParser.php +++ b/src/Extension/Autolink/UrlAutolinkParser.php @@ -58,7 +58,11 @@ final class UrlAutolinkParser implements InlineParserInterface */ private array $prefixes = ['www']; - /** @psalm-readonly */ + /** + * @psalm-var non-empty-string + * + * @psalm-readonly + */ private string $finalRegex; /** @@ -66,6 +70,9 @@ final class UrlAutolinkParser implements InlineParserInterface */ public function __construct(array $allowedProtocols = ['http', 'https', 'ftp']) { + /** + * @psalm-suppress PropertyTypeCoercion + */ $this->finalRegex = \sprintf(self::REGEX, \implode('|', $allowedProtocols)); foreach ($allowedProtocols as $protocol) { diff --git a/src/Extension/CommonMark/Parser/Block/ListBlockStartParser.php b/src/Extension/CommonMark/Parser/Block/ListBlockStartParser.php index 74b0c2bb99..65b4535b82 100644 --- a/src/Extension/CommonMark/Parser/Block/ListBlockStartParser.php +++ b/src/Extension/CommonMark/Parser/Block/ListBlockStartParser.php @@ -28,7 +28,11 @@ final class ListBlockStartParser implements BlockStartParserInterface, Configura /** @psalm-readonly-allow-private-mutation */ private ?ConfigurationInterface $config = null; - /** @psalm-readonly-allow-private-mutation */ + /** + * @psalm-var non-empty-string|null + * + * @psalm-readonly-allow-private-mutation + */ private ?string $listMarkerRegex = null; public function setConfiguration(ConfigurationInterface $configuration): void @@ -131,6 +135,9 @@ private static function calculateListMarkerPadding(Cursor $cursor, int $markerLe return $markerLength + $spacesAfterMarker; } + /** + * @psalm-return non-empty-string + */ private function generateListMarkerRegex(): string { // No configuration given - use the defaults diff --git a/src/Extension/Embed/DomainFilteringAdapter.php b/src/Extension/Embed/DomainFilteringAdapter.php index 69dc096f35..d150764aa4 100644 --- a/src/Extension/Embed/DomainFilteringAdapter.php +++ b/src/Extension/Embed/DomainFilteringAdapter.php @@ -17,6 +17,7 @@ class DomainFilteringAdapter implements EmbedAdapterInterface { private EmbedAdapterInterface $decorated; + /** @psalm-var non-empty-string */ private string $regex; /** @@ -40,6 +41,8 @@ public function updateEmbeds(array $embeds): void /** * @param string[] $allowedDomains + * + * @psalm-return non-empty-string */ private static function createRegex(array $allowedDomains): string { diff --git a/src/Extension/ExternalLink/ExternalLinkProcessor.php b/src/Extension/ExternalLink/ExternalLinkProcessor.php index 125053575c..0f1852070a 100644 --- a/src/Extension/ExternalLink/ExternalLinkProcessor.php +++ b/src/Extension/ExternalLink/ExternalLinkProcessor.php @@ -95,7 +95,7 @@ private function applyRelAttribute(Link $link, bool $isExternal): void /** * @internal This method is only public so we can easily test it. DO NOT USE THIS OUTSIDE OF THIS EXTENSION! * - * @param mixed $compareTo + * @param non-empty-string|list $compareTo */ public static function hostMatches(string $host, $compareTo): bool { diff --git a/src/Extension/FrontMatter/Data/SymfonyYamlFrontMatterParser.php b/src/Extension/FrontMatter/Data/SymfonyYamlFrontMatterParser.php index b21e9f78e0..8d99d336aa 100644 --- a/src/Extension/FrontMatter/Data/SymfonyYamlFrontMatterParser.php +++ b/src/Extension/FrontMatter/Data/SymfonyYamlFrontMatterParser.php @@ -30,6 +30,7 @@ public function parse(string $frontMatter) } try { + /** @psalm-suppress ReservedWord */ return Yaml::parse($frontMatter); } catch (ParseException $ex) { throw InvalidFrontMatterException::wrap($ex); diff --git a/src/Parser/Cursor.php b/src/Parser/Cursor.php index f2b6c96c55..d6d76b3a92 100644 --- a/src/Parser/Cursor.php +++ b/src/Parser/Cursor.php @@ -393,6 +393,8 @@ public function isAtEnd(): bool * Try to match a regular expression * * Returns the matching text and advances to the end of that match + * + * @psalm-param non-empty-string $regex */ public function match(string $regex): ?string { diff --git a/src/Parser/Inline/InlineParserMatch.php b/src/Parser/Inline/InlineParserMatch.php index 516a2c293f..e433ed27e8 100644 --- a/src/Parser/Inline/InlineParserMatch.php +++ b/src/Parser/Inline/InlineParserMatch.php @@ -36,6 +36,8 @@ public function caseSensitive(): self /** * @internal + * + * @psalm-return non-empty-string */ public function getRegex(): string { diff --git a/src/Parser/InlineParserEngine.php b/src/Parser/InlineParserEngine.php index da5c25e323..b91a63f72f 100644 --- a/src/Parser/InlineParserEngine.php +++ b/src/Parser/InlineParserEngine.php @@ -36,8 +36,8 @@ final class InlineParserEngine implements InlineParserEngineInterface /** * @var array - * @psalm-var list - * @phpstan-var array + * @psalm-var list + * @phpstan-var array */ private array $parsers = []; diff --git a/src/Util/RegexHelper.php b/src/Util/RegexHelper.php index 8ead731e2b..44e7e3ade5 100644 --- a/src/Util/RegexHelper.php +++ b/src/Util/RegexHelper.php @@ -98,6 +98,8 @@ public static function isLetter(?string $character): bool /** * Attempt to match a regex in string s at offset offset * + * @psalm-param non-empty-string $regex + * * @return int|null Index of match, or null * * @psalm-pure @@ -119,6 +121,8 @@ public static function matchAt(string $regex, string $string, int $offset = 0): /** * Functional wrapper around preg_match_all which only returns the first set of matches * + * @psalm-param non-empty-string $pattern + * * @return string[]|null * * @psalm-pure @@ -162,6 +166,8 @@ public static function unescape(string $string): string * * @phpstan-param HtmlBlock::TYPE_* $type * + * @psalm-return non-empty-string + * * @throws InvalidArgumentException if an invalid type is given * * @psalm-pure @@ -197,6 +203,8 @@ public static function getHtmlBlockOpenRegex(int $type): string * * @phpstan-param HtmlBlock::TYPE_* $type * + * @psalm-return non-empty-string + * * @throws InvalidArgumentException if an invalid type is given * * @psalm-pure