From 40a39a554a52ddc743d00200f4c1f9e3ff1ed972 Mon Sep 17 00:00:00 2001 From: landrok Date: Sat, 6 Apr 2024 18:24:15 +0200 Subject: [PATCH] [CS] Fix some doc-comment and bad types --- .github/workflows/php.yml | 2 +- src/ActivityPhp/Server.php | 1 + src/ActivityPhp/Server/Actor/Outbox.php | 8 +- .../ActivityPhp/Server/ConfigurationTest.php | 1 - tests/ActivityPhp/Server/HelperTest.php | 1 - .../ActivityPhp/Server/HttpSignatureTest.php | 74 +++++++++---------- tests/ActivityPhp/Server/OutboxPostTest.php | 1 - tests/ActivityPhp/Server/WebFingerTest.php | 3 - .../Type/AttributeFormatValidationTest.php | 2 - tests/ActivityPhp/Type/FactoryTest.php | 1 - .../Type/TypesTypeAttributeTest.php | 1 - 11 files changed, 43 insertions(+), 52 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ad7637f..a4dfb2c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -22,7 +22,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: "${{ matrix.php-versions }}" - coverage: xdebug2 + coverage: xdebug ini-values: "memory_limit=-1" tools: phpunit, composer diff --git a/src/ActivityPhp/Server.php b/src/ActivityPhp/Server.php index ba5e8b5..d0da9ee 100644 --- a/src/ActivityPhp/Server.php +++ b/src/ActivityPhp/Server.php @@ -95,6 +95,7 @@ public function cache(): ?CacheItemPoolInterface * @return \ActivityPhp\Server\Configuration\LoggerConfiguration * | \ActivityPhp\Server\Configuration\InstanceConfiguration * | \ActivityPhp\Server\Configuration\HttpConfiguration + * | \ActivityPhp\Server\Configuration\CacheConfiguration * | string */ public function config(string $parameter) diff --git a/src/ActivityPhp/Server/Actor/Outbox.php b/src/ActivityPhp/Server/Actor/Outbox.php index 9c37968..6deb272 100644 --- a/src/ActivityPhp/Server/Actor/Outbox.php +++ b/src/ActivityPhp/Server/Actor/Outbox.php @@ -18,6 +18,7 @@ use ActivityPhp\Server\Actor; use ActivityPhp\Server\Helper; use ActivityPhp\Type; +use ActivityPhp\Type\AbstractObject; use ActivityPhp\Type\Core\AbstractActivity; use ActivityPhp\Type\Util; use Exception; @@ -46,10 +47,9 @@ public function __construct(Actor $actor, Server $server) /** * Get items from an outbox * - * @param string $page - * @return array + * @param string $url A page URL */ - public function getPage(string $url) + public function getPage(string $url): AbstractObject { $this->server->logger()->info( $this->actor->webfinger()->getHandle() . ':' . __METHOD__, @@ -62,7 +62,7 @@ public function getPage(string $url) /** * Fetch an outbox * - * @return \ActivityPhp\Type\Core\OrderedCollection + * @return void|\ActivityPhp\Type\Core\OrderedCollection */ public function get() { diff --git a/tests/ActivityPhp/Server/ConfigurationTest.php b/tests/ActivityPhp/Server/ConfigurationTest.php index 140a3ff..21718be 100644 --- a/tests/ActivityPhp/Server/ConfigurationTest.php +++ b/tests/ActivityPhp/Server/ConfigurationTest.php @@ -27,7 +27,6 @@ public static function getFailingInstanceScenarios() * Check that all tests are failing * * @dataProvider getFailingInstanceScenarios - * #[DataProvider('getFailingInstanceScenarios')] */ public function testFailingInstanceScenarios($data) { diff --git a/tests/ActivityPhp/Server/HelperTest.php b/tests/ActivityPhp/Server/HelperTest.php index 0be341b..70c2577 100644 --- a/tests/ActivityPhp/Server/HelperTest.php +++ b/tests/ActivityPhp/Server/HelperTest.php @@ -33,7 +33,6 @@ public static function getAcceptHeaderScenarios() /** * @dataProvider getAcceptHeaderScenarios - * #[DataProvider('getAcceptHeaderScenarios')] */ public function testAcceptHeaderScenarios($input, $expected) { diff --git a/tests/ActivityPhp/Server/HttpSignatureTest.php b/tests/ActivityPhp/Server/HttpSignatureTest.php index df1074c..a6de94c 100644 --- a/tests/ActivityPhp/Server/HttpSignatureTest.php +++ b/tests/ActivityPhp/Server/HttpSignatureTest.php @@ -12,7 +12,7 @@ /* * These scenarios are around verifying an HTTP signature - * + * * Requests are sent from localhost:8001 (distant) */ class HttpSignatureTest extends TestCase @@ -32,18 +32,18 @@ public function testValidSignature() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash('sha256'); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; @@ -93,42 +93,42 @@ public function testSplittingSignature() 'enabled' => false, ] ]); - + $verifier = new HttpSignature($server); - + // Split a signature with headers but no algorithm $signature = 'keyId="http://localhost:8001/accounts/bob#main-key",headers="(request-target) host date",signature="FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg=="'; - + $split = $verifier->splitSignature($signature); - - $this->assertEquals($split, [ + + $this->assertEquals($split, [ 'keyId' => 'http://localhost:8001/accounts/bob#main-key', 'algorithm' => '', 'headers' => ' host date', 'signature' => 'FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg==', ]); - + // Split a signature with headers and algorithm $signature = 'keyId="http://localhost:8001/accounts/bob#main-key",algorithm="rsa-sha256",headers="(request-target) host date",signature="FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg=="'; - + $split = $verifier->splitSignature($signature); - - $this->assertEquals($split, [ + + $this->assertEquals($split, [ 'keyId' => 'http://localhost:8001/accounts/bob#main-key', 'algorithm' => 'rsa-sha256', 'headers' => ' host date', 'signature' => 'FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg==', ]); - // Split a signature with headers (headers contains hyphens), algorithm. + // Split a signature with headers (headers contains hyphens), algorithm. // For informtion, the following signature is false, no problem here as - // we're only testing split HTTP signature component. Verification is + // we're only testing split HTTP signature component. Verification is // made after $signature = 'keyId="http://localhost:8001/accounts/bob#main-key",algorithm="rsa-sha256",headers="(request-target) host content-type digest date",signature="FbVtmZhMWrfbqQpXf1v86+ie/fL8Ng4O67PePKvxChnUtV7J8N6lndQcNfXcDuKDJ4Nda6gKUQabAF2JK2qeYPNZNJ1AdAa5Lak3hQd+rAbdMJdvQpzGhAaSWK6atqOTH9v2CWdjAQbzvY0nOfGiw3ymtDSvTL0pVlIvq116uMtci0WOHeIbuBSyzM23liJmBomlm4EeB3/V1BVWY2MwaQ1cHVzxR7epP6XYts3C1KbZrdMKxhlWJFLdbLy0YGu5HRkYZepAh2q2NriSikNg8YTJ67owgQv/LqhFKnObgZU6np54fBMSpg7eAdWSIbhhg1a/WHtzFicc9cgoWMRhEg=="'; - + $split = $verifier->splitSignature($signature); - - $this->assertEquals($split, [ + + $this->assertEquals($split, [ 'keyId' => 'http://localhost:8001/accounts/bob#main-key', 'algorithm' => 'rsa-sha256', 'headers' => ' host content-type digest date', @@ -152,18 +152,18 @@ public function testValidSignatureWithFallbackHeaders() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\ndate: $date"; @@ -199,7 +199,7 @@ public function testValidSignatureWithFallbackHeaders() } /** - * Check that it returns false when signature header is not + * Check that it returns false when signature header is not * specified */ public function testWrongSignatureMissingSignatureHeader() @@ -214,18 +214,18 @@ public function testWrongSignatureMissingSignatureHeader() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; @@ -274,18 +274,18 @@ public function testWrongSignatureMissingKeyId() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; @@ -335,18 +335,18 @@ public function testWrongSignatureMissingSignature() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; @@ -398,18 +398,18 @@ public function testWrongSignatureActorDoesNotExist() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; @@ -454,18 +454,18 @@ public function testWrongSignatureNotVerifiedSignature() ]); $payload = json_encode([]); - + /* ------------------------------------------------------------------ | Prepare signature | ------------------------------------------------------------------ */ - $date = gmdate('D, d M Y H:i:s T', time()); + $date = gmdate('D, d M Y H:i:s T', time()); $host = 'localhost'; $path = '/my-path?q=ok'; $rsa = PublicKeyLoader::loadPrivateKey( file_get_contents( dirname(__DIR__, 2) . '/WebServer/distant/keys/private.pem' - ) + ) )->withHash("sha256"); // private key $plaintext = "(request-target) post $path\nhost: $host\ndate: $date"; diff --git a/tests/ActivityPhp/Server/OutboxPostTest.php b/tests/ActivityPhp/Server/OutboxPostTest.php index 5506772..13ee416 100644 --- a/tests/ActivityPhp/Server/OutboxPostTest.php +++ b/tests/ActivityPhp/Server/OutboxPostTest.php @@ -64,7 +64,6 @@ public static function getOutboxPostActivities() * Check that all response are valid * * @dataProvider getOutboxPostActivities - * #[DataProvider('getOutboxPostActivities')] */ public function testOutboxPostActivities($payload, $accept = 'application/activity+json', $code = 201) { diff --git a/tests/ActivityPhp/Server/WebFingerTest.php b/tests/ActivityPhp/Server/WebFingerTest.php index 7f2930d..8f7577e 100644 --- a/tests/ActivityPhp/Server/WebFingerTest.php +++ b/tests/ActivityPhp/Server/WebFingerTest.php @@ -80,7 +80,6 @@ public static function getFailingScenarios() * Check that all response are valid * * @dataProvider getSuccessScenarios - * #[DataProvider('getSuccessScenarios')] */ public function testSuccessScenarios($handle, $method, $expected) { @@ -109,7 +108,6 @@ public function testSuccessScenarios($handle, $method, $expected) * Check that all tests are failing * * @dataProvider getFailingScenarios - * #[DataProvider('getFailingScenarios')] */ public function testFailingScenarios($handle, $method, $expected) { @@ -194,7 +192,6 @@ public static function getFailingInstanceScenarios() * Check that all tests are failing * * @dataProvider getFailingInstanceScenarios - * #[DataProvider('getFailingInstanceScenarios')] */ public function testFailingInstanceScenarios($data) { diff --git a/tests/ActivityPhp/Type/AttributeFormatValidationTest.php b/tests/ActivityPhp/Type/AttributeFormatValidationTest.php index 5942bea..561b91f 100644 --- a/tests/ActivityPhp/Type/AttributeFormatValidationTest.php +++ b/tests/ActivityPhp/Type/AttributeFormatValidationTest.php @@ -1370,7 +1370,6 @@ public static function getExceptionScenarios() * It checks that getter is working well too. * * @dataProvider getValidAttributesScenarios - * #[DataProvider('getValidAttributesScenarios')] */ public function testValidAttributesScenarios($attr, $type, $value) { @@ -1399,7 +1398,6 @@ public function testValidAttributesScenarios($attr, $type, $value) /** * @dataProvider getExceptionScenarios - * #[DataProvider('getExceptionScenarios')] */ public function testExceptionScenarios($attr, $type, $value) { diff --git a/tests/ActivityPhp/Type/FactoryTest.php b/tests/ActivityPhp/Type/FactoryTest.php index 382cf3b..fc5d2b6 100644 --- a/tests/ActivityPhp/Type/FactoryTest.php +++ b/tests/ActivityPhp/Type/FactoryTest.php @@ -79,7 +79,6 @@ public static function getShortTypes() * Check that all core objects have a correct type property. * * @dataProvider getShortTypes - * #[DataProvider('getShortTypes')] */ public function testShortTypesInstanciation($type) { diff --git a/tests/ActivityPhp/Type/TypesTypeAttributeTest.php b/tests/ActivityPhp/Type/TypesTypeAttributeTest.php index f8744a0..be5af70 100644 --- a/tests/ActivityPhp/Type/TypesTypeAttributeTest.php +++ b/tests/ActivityPhp/Type/TypesTypeAttributeTest.php @@ -129,7 +129,6 @@ public static function getObjectTypeScenarios() * It checks that getter is working well too. * * @dataProvider getObjectTypeScenarios - * #[DataProvider('getObjectTypeScenarios')] */ public function testObjectTypeScenarios($type, $attr, $value) {