mirror of
https://github.com/danog/stun.git
synced 2024-11-26 12:04:38 +01:00
Psalm improvements
This commit is contained in:
parent
ea741248b5
commit
caa661d74f
@ -5,7 +5,8 @@
|
||||
"require": {
|
||||
"php-64bit": ">=8.1.17",
|
||||
"amphp/socket": "^2.2",
|
||||
"webmozart/assert": "^1.11"
|
||||
"webmozart/assert": "^1.11",
|
||||
"psalm/phar": "^5.15"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/php-cs-fixer-config": "v2.x-dev"
|
||||
|
45
psalm-baseline.xml
Normal file
45
psalm-baseline.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
|
||||
<file src="src/Attribute.php">
|
||||
<ArgumentTypeCoercion>
|
||||
<code>$left</code>
|
||||
<code>$length</code>
|
||||
</ArgumentTypeCoercion>
|
||||
<UndefinedConstant>
|
||||
<code>$this::TYPE</code>
|
||||
</UndefinedConstant>
|
||||
</file>
|
||||
<file src="src/Attributes/ErrorCode.php">
|
||||
<ArgumentTypeCoercion>
|
||||
<code>$length-4</code>
|
||||
</ArgumentTypeCoercion>
|
||||
<InvalidArgument>
|
||||
<code>$class*100+$number</code>
|
||||
</InvalidArgument>
|
||||
</file>
|
||||
<file src="src/Attributes/MappedAddress.php">
|
||||
<ParamNameMismatch>
|
||||
<code>$_</code>
|
||||
</ParamNameMismatch>
|
||||
</file>
|
||||
<file src="src/Attributes/Software.php">
|
||||
<ArgumentTypeCoercion>
|
||||
<code>$length</code>
|
||||
</ArgumentTypeCoercion>
|
||||
</file>
|
||||
<file src="src/Attributes/Username.php">
|
||||
<ArgumentTypeCoercion>
|
||||
<code>$length</code>
|
||||
</ArgumentTypeCoercion>
|
||||
</file>
|
||||
<file src="src/Attributes/XorMappedAddress.php">
|
||||
<PossiblyUndefinedVariable>
|
||||
<code>$len</code>
|
||||
</PossiblyUndefinedVariable>
|
||||
</file>
|
||||
<file src="src/Message.php">
|
||||
<UndefinedConstant>
|
||||
<code>MessageMethod::MASK</code>
|
||||
</UndefinedConstant>
|
||||
</file>
|
||||
</files>
|
18
psalm.xml
Normal file
18
psalm.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="2"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||
findUnusedBaselineEntry="true"
|
||||
findUnusedCode="false"
|
||||
errorBaseline="psalm-baseline.xml"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<ignoreFiles>
|
||||
<directory name="vendor" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>
|
@ -27,8 +27,7 @@ final class ErrorCode extends Attribute
|
||||
$reader->readLength(2, $cancellation);
|
||||
$class = \ord($reader->readLength(1, $cancellation));
|
||||
$number = \ord($reader->readLength(1, $cancellation));
|
||||
Assert::true($class >= 3);
|
||||
Assert::true($class <= 6);
|
||||
Assert::true($class >= 3 && $class <= 6);
|
||||
Assert::true($number < 100);
|
||||
return new self($class*100+$number, $reader->readLength($length-4));
|
||||
}
|
||||
|
@ -41,7 +41,10 @@ final class Message
|
||||
|
||||
$attributes = [];
|
||||
while ($length) {
|
||||
$attributes []= Attribute::read($reader, $length, $transactionId, $cancellation);
|
||||
$attr = Attribute::read($reader, $length, $transactionId, $cancellation);
|
||||
if ($attr) {
|
||||
$attributes []= $attr;
|
||||
}
|
||||
}
|
||||
|
||||
return new self(
|
||||
|
@ -24,9 +24,7 @@ final class StunClient
|
||||
$this->socket = connect($endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Attribute>
|
||||
*/
|
||||
/** @no-named-arguments */
|
||||
public function bind(Attribute ...$attributes): Message
|
||||
{
|
||||
$msg = new Message(MessageMethod::BINDING, MessageClass::REQUEST, $attributes, \random_bytes(12));
|
||||
|
Loading…
Reference in New Issue
Block a user