Fixed method arguments issue.

This commit is contained in:
flash 2024-09-30 17:34:51 +00:00
parent caf4eef02d
commit 2217c8c3de
5 changed files with 27 additions and 11 deletions

View file

@ -1 +1 @@
0.2408.610150 0.2408.611934

View file

@ -1,7 +1,7 @@
<?php <?php
// BencodeSerialisableTrait.php // BencodeSerialisableTrait.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-29 // Updated: 2024-09-30
namespace Index\Bencode; namespace Index\Bencode;
@ -55,15 +55,15 @@ trait BencodeSerialisableTrait {
$methodInfos = $objectInfo->getMethods(ReflectionMethod::IS_PUBLIC); $methodInfos = $objectInfo->getMethods(ReflectionMethod::IS_PUBLIC);
foreach($methodInfos as $methodInfo) { foreach($methodInfos as $methodInfo) {
if($methodInfo->getNumberOfRequiredParameters() > 0)
throw new RuntimeException('Methods marked with the BencodeProperty attribute must not have any required arguments.');
$attrInfos = $methodInfo->getAttributes(BencodeProperty::class); $attrInfos = $methodInfo->getAttributes(BencodeProperty::class);
if(count($attrInfos) < 1) if(count($attrInfos) < 1)
continue; continue;
if(count($attrInfos) > 1) if(count($attrInfos) > 1)
throw new RuntimeException('Methods may only carry a single instance of the BencodeProperty attribute.'); throw new RuntimeException('Methods may only carry a single instance of the BencodeProperty attribute.');
if($methodInfo->getNumberOfRequiredParameters() > 0)
throw new RuntimeException('Methods marked with the BencodeProperty attribute must not have any required arguments.');
$info = $attrInfos[0]->newInstance(); $info = $attrInfos[0]->newInstance();
$name = $info->getName() ?? $methodInfo->getName(); $name = $info->getName() ?? $methodInfo->getName();

View file

@ -1,7 +1,7 @@
<?php <?php
// JsonSerializableTrait.php // JsonSerializableTrait.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-29 // Updated: 2024-09-30
namespace Index\Json; namespace Index\Json;
@ -53,15 +53,15 @@ trait JsonSerializableTrait {
$methodInfos = $objectInfo->getMethods(ReflectionMethod::IS_PUBLIC); $methodInfos = $objectInfo->getMethods(ReflectionMethod::IS_PUBLIC);
foreach($methodInfos as $methodInfo) { foreach($methodInfos as $methodInfo) {
if($methodInfo->getNumberOfRequiredParameters() > 0)
throw new RuntimeException('Methods marked with the JsonProperty attribute must not have any required arguments.');
$attrInfos = $methodInfo->getAttributes(JsonProperty::class); $attrInfos = $methodInfo->getAttributes(JsonProperty::class);
if(count($attrInfos) < 1) if(count($attrInfos) < 1)
continue; continue;
if(count($attrInfos) > 1) if(count($attrInfos) > 1)
throw new RuntimeException('Methods may only carry a single instance of the JsonProperty attribute.'); throw new RuntimeException('Methods may only carry a single instance of the JsonProperty attribute.');
if($methodInfo->getNumberOfRequiredParameters() > 0)
throw new RuntimeException('Methods marked with the JsonProperty attribute must not have any required arguments.');
$info = $attrInfos[0]->newInstance(); $info = $attrInfos[0]->newInstance();
$name = $info->getName() ?? $methodInfo->getName(); $name = $info->getName() ?? $methodInfo->getName();

View file

@ -1,7 +1,7 @@
<?php <?php
// BencodeSerialisableTest.php // BencodeSerialisableTest.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-29 // Updated: 2024-09-30
declare(strict_types=1); declare(strict_types=1);
@ -134,6 +134,14 @@ final class BencodeSerialisableTest extends TestCase {
} }
}; };
} }
public function methodWithArguments(string $meow): string {
return $meow;
}
public static function staticMethodWithArguments(string $meow): string {
return $meow;
}
}; };
$this->assertEquals(self::BASIC_BENCODED_ENCODED, Bencode::encode($test)); $this->assertEquals(self::BASIC_BENCODED_ENCODED, Bencode::encode($test));

View file

@ -1,7 +1,7 @@
<?php <?php
// JsonSerializableTest.php // JsonSerializableTest.php
// Created: 2024-09-29 // Created: 2024-09-29
// Updated: 2024-09-29 // Updated: 2024-09-30
declare(strict_types=1); declare(strict_types=1);
@ -132,6 +132,14 @@ final class JsonSerializableTest extends TestCase {
} }
}; };
} }
public function methodWithArguments(string $meow, string $mewow): string {
return $meow . $mewow;
}
public static function staticMethodWithArguments(string $meow, string $mewow): string {
return $meow . $mewow;
}
}; };
$this->assertEquals(self::BASIC_JSON_ENCODED, json_encode($test)); $this->assertEquals(self::BASIC_JSON_ENCODED, json_encode($test));