Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection_* functions are impure #2555

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/functionMetadata_original.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
'chown' => ['hasSideEffects' => true],
'copy' => ['hasSideEffects' => true],
'count' => ['hasSideEffects' => false],
'connection_aborted' => ['hasSideEffects' => true],
'connection_status' => ['hasSideEffects' => true],
'fclose' => ['hasSideEffects' => true],
'fflush' => ['hasSideEffects' => true],
'fgetc' => ['hasSideEffects' => true],
Expand Down
2 changes: 2 additions & 0 deletions bin/generate-function-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function enterNode(Node $node)
'rand',
'random_bytes',
'random_int',
'connection_aborted',
'connection_status',
], true)) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions resources/functionMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@
'collator_get_sort_key' => ['hasSideEffects' => false],
'collator_get_strength' => ['hasSideEffects' => false],
'compact' => ['hasSideEffects' => false],
'connection_aborted' => ['hasSideEffects' => false],
'connection_status' => ['hasSideEffects' => false],
'connection_aborted' => ['hasSideEffects' => true],
'connection_status' => ['hasSideEffects' => true],
'constant' => ['hasSideEffects' => false],
'convert_cyr_string' => ['hasSideEffects' => false],
'convert_uudecode' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullsafe-vs-scalar.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8517.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-9803.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-connection-fns.php');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Analyser/data/impure-connection-fns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ImpureConnectionFunctions;

use function PHPStan\Testing\assertType;

function doFoo() {
if (connection_aborted()) {
assertType('0|1', connection_aborted());
}

if (connection_status()) {
assertType('int<0, 3>', connection_status());
}
}