Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/functionMap_bleedingEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
'max' => ['', '...arg1'=>'non-empty-array'],
'min' => ['', '...arg1'=>'non-empty-array'],
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'0|FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES', 'context='=>'resource'],
'flock' => ['bool', 'fp'=>'resource', 'operation'=>'int-mask<LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB>', '&w_wouldblock='=>'int'],
],
'old' => [

Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1378,4 +1378,14 @@ public function testFileParams(): void
]);
}

public function testFlockParams(): void
{
$this->analyse([__DIR__ . '/data/flock.php'], [
[
'Parameter #2 $operation of function flock expects int<0, 7>, 8 given.',
45,
],
]);
}

}
47 changes: 47 additions & 0 deletions tests/PHPStan/Rules/Functions/data/flock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace flockFlags;

class flock {
/** @param resource $fp */
public function ok($fp):void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (flock($fp, LOCK_EX)) { // acquire an exclusive lock
ftruncate($fp, 0); // truncate file
fwrite($fp, "Write something here\n");
fflush($fp); // flush output before releasing the lock
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't get the lock!";
}

fclose($fp);
}

/** @param resource $fp */
public function ok1($fp):void {

/* Activate the LOCK_NB option on an LOCK_EX operation */
if(!flock($fp, LOCK_EX | LOCK_NB)) {
echo 'Unable to obtain lock';
exit(-1);
}
if(!flock($fp, LOCK_SH | LOCK_NB)) {
echo 'Unable to obtain lock';
exit(-1);
}
if(!flock($fp, LOCK_UN | LOCK_NB)) {
echo 'Unable to obtain lock';
exit(-1);
}

/* ... */

fclose($fp);
}

/** @param resource $fp */
public function error($fp):void {
$f = flock($fp, FILE_APPEND);
}
}