feat: Add rate limit and token permissions checking support#7
Merged
ralflang merged 5 commits intoFRAMEWORK_6_0from Feb 26, 2026
Merged
feat: Add rate limit and token permissions checking support#7ralflang merged 5 commits intoFRAMEWORK_6_0from
ralflang merged 5 commits intoFRAMEWORK_6_0from
Conversation
This commit adds two new features to the GitHub API client: RATE LIMIT SUPPORT: - RateLimit value object to hold rate limit data - RateLimitRequestFactory for creating /rate_limit endpoint requests - GithubApiClient::getRateLimit() method - Tracks limit, remaining, used, and reset timestamp - Helper methods: isExhausted(), getUsagePercentage(), getSecondsUntilReset() - Comprehensive PHPUnit tests (10 tests, 22 assertions) TOKEN PERMISSIONS/SCOPES SUPPORT: - TokenScopes value object to hold OAuth scope list - AuthenticatedUserRequestFactory for creating /user endpoint requests - GithubApiClient::getTokenScopes() method - Parses X-OAuth-Scopes header from API response - Helper methods: has(), hasAny(), hasAll(), canReadRepositories(), etc. - Comprehensive PHPUnit tests (19 tests, 27 assertions) DEMO SCRIPT: - bin/demo-token-info.php demonstrates both features - Displays formatted rate limit and scope information All tests passing (29 tests, 49 assertions) Follows existing library patterns and conventions
FIXES: - Install psr/http-client, psr/http-message, psr/http-factory as dev dependencies to fix missing ClientInterface error in tests - Upgrade deprecated @coversNothing annotation to PHPUnit 12 attribute syntax #[\PHPUnit\Framework\Attributes\CoversNothing] RESULT: - All tests now pass (30 tests, 50 assertions) - No more deprecated annotation warnings - Compatible with PHPUnit 12
Replace deprecated @Covers doc-comment annotations with #[\PHPUnit\Framework\Attributes\CoversClass] attributes in: - RateLimitTest.php - TokenScopesTest.php Result: All PHPUnit deprecation warnings eliminated Tests: 30, Assertions: 50, No deprecations
FIXES: - Upgrade deprecated @PHP82Migration to @PHP83Migration in .php-cs-fixer.dist.php - Run php-cs-fixer fix on all source files - Fix braces_position, single_line_empty_body, no_whitespace_in_blank_line issues - Fix operator_linebreak and no_trailing_whitespace issues - Add PHP ^8.3 requirement to composer.json (addresses CS Fixer warning) AFFECTED FILES: - .php-cs-fixer.dist.php (rule set updated) - composer.json (PHP version requirement added) - src/RateLimit.php (whitespace fixes) - src/RateLimitRequestFactory.php (whitespace fixes) - src/AuthenticatedUserRequestFactory.php (whitespace fixes) - src/GithubRepository.php (operator linebreak fixes) - src/GithubRepositoryList.php (operator linebreak fixes) - tests/unit/RateLimitTest.php (whitespace fixes) - tests/unit/TokenScopesTest.php (whitespace fixes) RESULT: - 0 CS violations remaining - All tests still passing (30 tests, 50 assertions) - No deprecation warnings from php-cs-fixer
Change constructor parameter type from array<string> to array<mixed> since the implementation explicitly filters non-string values. This fixes PHPStan error: "Parameter #1 \ of class Horde\GithubApiClient\TokenScopes constructor expects array<string>, array<int, int|string|null> given." The constructor behavior remains unchanged - it filters out non-strings using array_filter with is_string callback. PHPStan now passes with 0 errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two essential features to the GitHub API client library:
Features Added
1. Rate Limit Support
New Classes:
RateLimit- Value object for rate limit dataRateLimitRequestFactory- Creates requests for/rate_limitendpointAPI Method:
Features:
isExhausted(),getUsagePercentage(),getSecondsUntilReset(),getResetDateTime()2. Token Permissions/Scopes Support
New Classes:
TokenScopes- Value object for OAuth scope listAuthenticatedUserRequestFactory- Creates requests for/userendpointAPI Method:
Features:
X-OAuth-Scopesheader from API responsehas(),hasAny(),hasAll(),canReadRepositories(),canWriteRepositories(),canReadOrganizations()3. Demo Script
Added
bin/demo-token-info.phpto demonstrate both features with formatted output.Testing
✅ Comprehensive PHPUnit test coverage
✅ PHPUnit 12 Compatible
Code Quality
Commits
Files Changed
Usage Example
See
bin/demo-token-info.phpfor a complete example.