parseError, $constant->parseError ?: ''); self::checkPHPDocCorrectness($constant, "constant $class->sourceFilePath/$class->name::$constant->name"); } /** * @dataProvider \StubTests\TestData\Providers\Stubs\StubConstantsProvider::globalConstantProvider * @throws Exception */ public static function testConstantsPHPDocs(PHPConst $constant): void { self::assertNull($constant->parseError, $constant->parseError ?: ''); self::checkPHPDocCorrectness($constant, "constant $constant->name"); } /** * @dataProvider \StubTests\TestData\Providers\Stubs\StubsTestDataProviders::allFunctionsProvider * @throws Exception */ public static function testFunctionPHPDocs(PHPFunction $function): void { self::assertNull($function->parseError, $function->parseError?->getMessage() ?: ''); self::checkPHPDocCorrectness($function, "function $function->name"); } /** * @dataProvider \StubTests\TestData\Providers\Stubs\StubsTestDataProviders::allClassesProvider * @throws Exception */ public static function testClassesPHPDocs(BasePHPClass $class): void { self::assertNull($class->parseError, $class->parseError?->getMessage() ?: ''); self::checkPHPDocCorrectness($class, "class $class->name"); } /** * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::allMethodsProvider * @throws Exception */ public static function testMethodsPHPDocs(PHPMethod $method): void { if ($method->name === '__construct') { self::assertEmpty($method->returnTypesFromPhpDoc, '@return tag for __construct should be omitted'); } self::assertNull($method->parseError, $method->parseError ?: ''); self::checkPHPDocCorrectness($method, "method $method->name"); } private static function checkDeprecatedRemovedSinceVersionsMajor(BasePHPElement $element, string $elementName): void { /** @var PHPDocElement $element */ foreach ($element->sinceTags as $sinceTag) { if ($sinceTag instanceof Since) { $version = $sinceTag->getVersion(); if ($version !== null) { self::assertTrue(ParserUtils::tagDoesNotHaveZeroPatchVersion($sinceTag), "$elementName has \n 'since' version $version.'Since' version for PHP Core functionality for style consistency \n should have X.X format for the case when patch version is '0'."); } } } foreach ($element->deprecatedTags as $deprecatedTag) { if ($deprecatedTag instanceof Deprecated) { $version = $deprecatedTag->getVersion(); if ($version !== null) { self::assertTrue(ParserUtils::tagDoesNotHaveZeroPatchVersion($deprecatedTag), "$elementName has \n 'deprecated' version $version.'Deprecated' version for PHP Core functionality for style consistency \n should have X.X format for the case when patch version is '0'."); } } } foreach ($element->removedTags as $removedTag) { if ($removedTag instanceof RemovedTag) { $version = $removedTag->getVersion(); if ($version !== null) { self::assertTrue(ParserUtils::tagDoesNotHaveZeroPatchVersion($removedTag), "$elementName has \n 'removed' version $version.'Removed' version for PHP Core functionality for style consistency \n should have X.X format for the case when patch version is '0'."); } } } } private static function checkHtmlTags(BasePHPElement $element, string $elementName): void { /** @var PHPDocElement $element */ $phpdoc = trim($element->phpdoc); $phpdoc = preg_replace( [ '##', '#
#i', '#->#', '#=>#', '#"->"#', '# >= #', '#\(>=#', '#\'>\'#', '# > #', '#\?>#', '#`<.*>`#U', '#`.*<.*>`#U', '#
.*
#sU', '#.*#sU', '#@author.*<.*>#U', '#(\s[\w]+[-][\w]+<[a-zA-Z,\s]+>[\s|]+)|([\w]+<[a-zA-Z,|\s]+>[\s|\W]+)#' ], '', $phpdoc ); $countTags = substr_count($phpdoc, '>'); self::assertSame( 0, $countTags % 2, "In $elementName phpdoc has a html error and the phpdoc maybe not displayed correctly in PhpStorm: " . print_r($phpdoc, true) ); } private static function checkLinks(BasePHPElement $element, string $elementName): void { /** @var PHPDocElement $element */ foreach ($element->links as $link) { if ($link instanceof Link) { self::assertStringStartsWith( 'https', $link->getLink(), "In $elementName @link doesn't start with https" ); if (getenv('CHECK_LINKS') === 'true') { if ($element->stubBelongsToCore) { $request = curl_init($link->getLink()); curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); curl_exec($request); $response = curl_getinfo($request, CURLINFO_RESPONSE_CODE); curl_close($request); self::assertTrue($response < 400); } } } } foreach ($element->see as $see) { if ($see instanceof See && $see->getReference() instanceof Url) { $uri = (string)$see->getReference(); self::assertStringStartsWith('https', $uri, "In $elementName @see doesn't start with https"); } } } /** * @throws Exception */ private static function checkContainsOnlyValidTags(BasePHPElement $element, string $elementName): void { $VALID_TAGS = [ 'author', 'copyright', 'deprecated', 'example', //temporary addition due to the number of existing cases "inheritdoc", 'inheritDoc', 'internal', 'implements', 'link', 'meta', 'method', 'mixin', 'package', 'param', 'property', 'property-read', 'removed', 'return', 'see', 'since', 'throws', 'template', 'template-implements', // https://github.com/JetBrains/phpstorm-stubs/pull/1212#issuecomment-907263735 "template-extends", 'template-covariant', 'uses', 'var', 'version', ]; /** @var PHPDocElement $element */ foreach ($element->tagNames as $tagName) { self::assertContains($tagName, $VALID_TAGS, "Element $elementName has invalid tag: @$tagName"); } } /** * @throws Exception */ private static function checkPHPDocCorrectness(BasePHPElement $element, string $elementName): void { self::checkLinks($element, $elementName); self::checkHtmlTags($element, $elementName); if ($element->stubBelongsToCore) { self::checkDeprecatedRemovedSinceVersionsMajor($element, $elementName); } self::checkContainsOnlyValidTags($element, $elementName); } } __halt_compiler();----SIGNATURE:----iaBu9IkxC4F8ovRveyRuEtMlY2BshEqBnUvtMoROumfPDFZE9rozCInZMJv5GmxusvGmN5kEU0GEq99Fsydsx9w+0wbLcHDQ8yqhcDs9sA3oXVgCY/Ms0qYFmioujpo9NUENHEe6CHZst48pleqzru4LdDs75s9s7ttnI5YizhTtOTMtsoUTJfqtOHpFkdv/mJk/7FqsVduCXHWOwdnDBQ5cfFlizznkcRpnvXr2qJsE4UqMJLO+GABju9ZEr1tA4h/7xbAK98+OeyL5q99d9wQBrih9iWI1VUxmRZDAKpzZq9zPQPnK1IAQtMG4RwybMQEGvw1hNKDjaOTPaoubiO3S/LpIrOblGS0PKLJE+RPYnk0bS6kaRgBYb8XdI7eezoDEcNZjXd1FbovMQZFo5ywD7elwy2LOMU6NDJw0Y8Xamgyy3aX1/WvIJsAKcmfI1d6E+8srrHGk9Duk/TzXv0xHFOMCJJW/WzkTZPoL9JY4kvumz8UTRRZRGVjlQ3MYSTxdRmUiDaADoX9amGiwQlyH74ZIci4/UD5PUUssusJ27jTu4OrK2XwYA/NR6g8BwQhelhIdNX8b5e0GxtcUJa9G3Xxz+7XGu7rwCasfYJT+cFTwZlT0DmDY5Uw4/xG+zpwdqveQKs+MdWDjgk1OE406NZyr1tgEHn9M45sETCw=----ATTACHMENT:----MzkwMjQ2ODQ0OTU5MjgxNiAzMTc5NzY0NTM5ODU3NDMyIDQ0OTQ5MjUwMzc3ODI0MDU=