Skip to content

Commit

Permalink
Fixed unpack - third parameter introduced in 7.1.1 is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 30, 2017
1 parent c7582cf commit 24894eb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Reflection/FunctionReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public function getParameters(): array
true
);
}
if (
$this->reflection->getName() === 'unpack'
&& PHP_VERSION_ID >= 70101
) {
$this->parameters[2] = new DummyParameter(
'offset',
new IntegerType(false),
true
);
}
}

return $this->parameters;
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,34 @@ public function testCallToWeirdFunctions()
]);
}

/**
* @requires PHP 7.1.1
*/
public function testUnpackOnAfter711()
{
$this->analyse([__DIR__ . '/data/unpack.php'], [
[
'Function unpack invoked with 0 parameters, 2-3 required.',
3,
],
]);
}

public function testUnpackOnBefore711()
{
if (PHP_VERSION_ID >= 70101) {
$this->markTestSkipped('This test requires PHP < 7.1.1');
}
$this->analyse([__DIR__ . '/data/unpack.php'], [
[
'Function unpack invoked with 0 parameters, 2 required.',
3,
],
[
'Function unpack invoked with 3 parameters, 2 required.',
4,
],
]);
}

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

unpack();
unpack($format, $data, 1);

0 comments on commit 24894eb

Please sign in to comment.