Installed Psalm, set up static analysis

Fixed a couple of minor issues
This commit is contained in:
Barnaby Walters 2021-06-15 00:51:04 +02:00
parent f0469a7d54
commit 896f661a7f
6 changed files with 1537 additions and 5 deletions

View File

@ -34,5 +34,8 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: composer install --prefer-dist --no-progress run: composer install --prefer-dist --no-progress
- name: Run test suite - name: Run Test Suite
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit tests --coverage-filter src --coverage-text run: XDEBUG_MODE=coverage ./vendor/bin/phpunit tests --coverage-filter src --coverage-text
- name: Run Static Analysis
run: ./vendor/bin/psalm

View File

@ -34,6 +34,7 @@
}, },
"require-dev": { "require-dev": {
"guzzlehttp/guzzle": "^7.3", "guzzlehttp/guzzle": "^7.3",
"phpunit/phpunit": "^9.5" "phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.7"
} }
} }

1515
composer.lock generated

File diff suppressed because it is too large Load Diff

15
psalm.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
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"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>

View File

@ -369,7 +369,7 @@ class Server {
} }
// Check that this token either grants at most the profile scope. // Check that this token either grants at most the profile scope.
$requestedScopes = explode(' ', $authCode['scope'] ?? ''); $requestedScopes = array_filter(explode(' ', $authCode['scope'] ?? ''));
if (!empty($requestedScopes) && $requestedScopes != ['profile']) { if (!empty($requestedScopes) && $requestedScopes != ['profile']) {
$this->logger->error("An exchange request for a token granting scopes other than “profile” was sent to the authorization endpoint."); $this->logger->error("An exchange request for a token granting scopes other than “profile” was sent to the authorization endpoint.");
throw IndieAuthException::create(IndieAuthException::INVALID_GRANT, $request); throw IndieAuthException::create(IndieAuthException::INVALID_GRANT, $request);

View File

@ -40,7 +40,7 @@ class FilesystemJsonStorage implements TokenStorageInterface, LoggerAwareInterfa
public function __construct(string $path, string $secret, ?int $authCodeTtl=null, ?int $accessTokenTtl=null, $cleanUpNow=false, ?LoggerInterface $logger=null) { public function __construct(string $path, string $secret, ?int $authCodeTtl=null, ?int $accessTokenTtl=null, $cleanUpNow=false, ?LoggerInterface $logger=null) {
$this->logger = $logger ?? new NullLogger(); $this->logger = $logger ?? new NullLogger();
if (!is_string($secret) || strlen($secret) < 64) { if (strlen($secret) < 64) {
throw new Exception("\$secret must be a string with a minimum length of 64 characters. Make one with Taproot\IndieAuth\generateRandomString(64)"); throw new Exception("\$secret must be a string with a minimum length of 64 characters. Make one with Taproot\IndieAuth\generateRandomString(64)");
} }
$this->secret = $secret; $this->secret = $secret;