Skip to content

Commit

Permalink
Update functionMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 5, 2021
1 parent d365eff commit 1679c34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 10 additions & 2 deletions bin/generate-function-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function enterNode(Node $node)
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
$this->functions[] = $node->namespacedName->toLowerString();
break;
break 2;
}
}
}
Expand All @@ -45,7 +45,7 @@ public function enterNode(Node $node)
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->toString() === \JetBrains\PhpStorm\Pure::class) {
$this->methods[] = sprintf('%s::%s', $className, $node->name->toString());
break;
break 2;
}
}
}
Expand All @@ -71,6 +71,14 @@ public function enterNode(Node $node)
foreach ($visitor->functions as $functionName) {
if (array_key_exists($functionName, $metadata)) {
if ($metadata[$functionName]['hasSideEffects']) {
if (in_array($functionName, [
'mt_rand',
'rand',
'random_bytes',
'random_int',
], true)) {
continue;
}
throw new \PHPStan\ShouldNotHappenException($functionName);
}
}
Expand Down
18 changes: 12 additions & 6 deletions resources/functionMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
'DateTimeImmutable::setTimestamp' => ['hasSideEffects' => false],
'DateTimeImmutable::setTimezone' => ['hasSideEffects' => false],
'DateTimeImmutable::sub' => ['hasSideEffects' => false],
'Error::__construct' => ['hasSideEffects' => false],
'ErrorException::__construct' => ['hasSideEffects' => false],
'Event::__construct' => ['hasSideEffects' => false],
'EventBase::getFeatures' => ['hasSideEffects' => false],
Expand All @@ -86,6 +87,7 @@
'EventHttpConnection::__construct' => ['hasSideEffects' => false],
'EventHttpRequest::__construct' => ['hasSideEffects' => false],
'EventHttpRequest::getCommand' => ['hasSideEffects' => false],
'EventHttpRequest::getConnection' => ['hasSideEffects' => false],
'EventHttpRequest::getHost' => ['hasSideEffects' => false],
'EventHttpRequest::getInputBuffer' => ['hasSideEffects' => false],
'EventHttpRequest::getInputHeaders' => ['hasSideEffects' => false],
Expand Down Expand Up @@ -495,6 +497,7 @@
'ReflectionFunctionAbstract::getAttributes' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getClosureScopeClass' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getClosureThis' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getClosureUsedVariables' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getDocComment' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getEndLine' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getExtension' => ['hasSideEffects' => false],
Expand All @@ -509,10 +512,13 @@
'ReflectionFunctionAbstract::getShortName' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getStartLine' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getStaticVariables' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::getTentativeReturnType' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::hasTentativeReturnType' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isClosure' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isDeprecated' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isGenerator' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isInternal' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isStatic' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isUserDefined' => ['hasSideEffects' => false],
'ReflectionFunctionAbstract::isVariadic' => ['hasSideEffects' => false],
'ReflectionGenerator::getExecutingFile' => ['hasSideEffects' => false],
Expand All @@ -521,6 +527,7 @@
'ReflectionGenerator::getFunction' => ['hasSideEffects' => false],
'ReflectionGenerator::getThis' => ['hasSideEffects' => false],
'ReflectionGenerator::getTrace' => ['hasSideEffects' => false],
'ReflectionIntersectionType::getTypes' => ['hasSideEffects' => false],
'ReflectionMethod::getClosure' => ['hasSideEffects' => false],
'ReflectionMethod::getDeclaringClass' => ['hasSideEffects' => false],
'ReflectionMethod::getModifiers' => ['hasSideEffects' => false],
Expand All @@ -533,6 +540,7 @@
'ReflectionMethod::isProtected' => ['hasSideEffects' => false],
'ReflectionMethod::isPublic' => ['hasSideEffects' => false],
'ReflectionMethod::isStatic' => ['hasSideEffects' => false],
'ReflectionMethod::setAccessible' => ['hasSideEffects' => false],
'ReflectionNamedType::getName' => ['hasSideEffects' => false],
'ReflectionNamedType::isBuiltin' => ['hasSideEffects' => false],
'ReflectionParameter::getAttributes' => ['hasSideEffects' => false],
Expand Down Expand Up @@ -567,6 +575,7 @@
'ReflectionProperty::isProtected' => ['hasSideEffects' => false],
'ReflectionProperty::isPublic' => ['hasSideEffects' => false],
'ReflectionProperty::isStatic' => ['hasSideEffects' => false],
'ReflectionProperty::setAccessible' => ['hasSideEffects' => false],
'ReflectionReference::getId' => ['hasSideEffects' => false],
'ReflectionType::isBuiltin' => ['hasSideEffects' => false],
'ReflectionUnionType::getTypes' => ['hasSideEffects' => false],
Expand Down Expand Up @@ -601,15 +610,11 @@
'SimpleXMLIterator::valid' => ['hasSideEffects' => false],
'SoapFault::__construct' => ['hasSideEffects' => false],
'Spoofchecker::__construct' => ['hasSideEffects' => false],
'StubTests\\Model\\BasePHPElement::getFQN' => ['hasSideEffects' => false],
'StubTests\\Model\\BasePHPElement::getTypeNameFromNode' => ['hasSideEffects' => false],
'StubTests\\Model\\BasePHPElement::hasMutedProblem' => ['hasSideEffects' => false],
'StubTests\\Model\\StubsContainer::getClass' => ['hasSideEffects' => false],
'StubTests\\Model\\StubsContainer::getInterface' => ['hasSideEffects' => false],
'StubTests\\CodeStyle\\BracesOneLineFixer::getDefinition' => ['hasSideEffects' => false],
'StubTests\\Parsers\\ExpectedFunctionArgumentsInfo::__toString' => ['hasSideEffects' => false],
'StubTests\\Parsers\\Visitors\\CoreStubASTVisitor::__construct' => ['hasSideEffects' => false],
'StubTests\\StubsMetaExpectedArgumentsTest::getClassMemberFqn' => ['hasSideEffects' => false],
'StubTests\\StubsParameterNamesTest::printParameters' => ['hasSideEffects' => false],
'StubTests\\StubsTest::getParameterRepresentation' => ['hasSideEffects' => false],
'Transliterator::createInverse' => ['hasSideEffects' => false],
'Transliterator::getErrorCode' => ['hasSideEffects' => false],
'Transliterator::getErrorMessage' => ['hasSideEffects' => false],
Expand Down Expand Up @@ -658,6 +663,7 @@
'array_intersect_key' => ['hasSideEffects' => false],
'array_intersect_uassoc' => ['hasSideEffects' => false],
'array_intersect_ukey' => ['hasSideEffects' => false],
'array_is_list' => ['hasSideEffects' => false],
'array_key_exists' => ['hasSideEffects' => false],
'array_key_first' => ['hasSideEffects' => false],
'array_key_last' => ['hasSideEffects' => false],
Expand Down

0 comments on commit 1679c34

Please sign in to comment.