Skip to content

Commit

Permalink
increase psalm level and add fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jan 24, 2022
1 parent 2409839 commit 69fac8d
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/View/App.php
Expand Up @@ -79,7 +79,7 @@ public function getCollection(int $startIndex, int $count, ?string $search = nul
return $this->build($definition);
}

public function getEntity(string $id)
public function getEntity(int $id)
{
$definition = $this->doEntity([$this->getTable(Table\App::class), 'find'], [$id], [
'id' => $this->fieldInteger('id'),
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/View/Statistic/ErrorsPerRoute.php
Expand Up @@ -118,7 +118,7 @@ public function getView(int $categoryId, Log\QueryFilter $filter)

return [
'labels' => $labels,
'data' => array_values($values),
'data' => $values,
'series' => array_values($series),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/View/Statistic/MostUsedApps.php
Expand Up @@ -113,7 +113,7 @@ public function getView(Log\QueryFilter $filter)

return [
'labels' => $labels,
'data' => array_values($values),
'data' => $values,
'series' => array_values($series),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/View/Statistic/MostUsedRoutes.php
Expand Up @@ -114,7 +114,7 @@ public function getView(int $categoryId, Log\QueryFilter $filter)

return [
'labels' => $labels,
'data' => array_values($values),
'data' => $values,
'series' => array_values($series),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/View/Statistic/TimePerRoute.php
Expand Up @@ -117,7 +117,7 @@ public function getView(int $categoryId, Log\QueryFilter $filter)

return [
'labels' => $labels,
'data' => array_values($values),
'data' => $values,
'series' => array_values($series),
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/System/TokenCommand.php
Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!is_numeric($appId)) {
$app = $this->appTable->findOneByName($appId);
} else {
$app = $this->appTable->find($appId);
$app = $this->appTable->find((int) $appId);
}

if (empty($app)) {
Expand All @@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!is_numeric($userId)) {
$user = $this->userTable->findOneByName($userId);
} else {
$user = $this->userTable->find($userId);
$user = $this->userTable->find((int) $userId);
}

if (empty($user)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Consumer/Action/Event/Subscription/GetAll.php
Expand Up @@ -48,8 +48,7 @@ public function handle(RequestInterface $request, ParametersInterface $configura
{
return $this->table->getCollection(
$context->getUser()->getId(),
(int) $request->get('startIndex'),
$request->get('search')
(int) $request->get('startIndex')
);
}
}
2 changes: 1 addition & 1 deletion src/Framework/Api/ResourceListing.php
Expand Up @@ -151,7 +151,7 @@ public function getDocumentation(int $routeId, string $path, ?string $version =
if ($version == '*' || empty($version)) {
$version = $this->methodTable->getLatestVersion($routeId);
} else {
$version = $this->methodTable->getVersion($routeId, $version);
$version = $this->methodTable->getVersion($routeId, (int) $version);
}

if (empty($version)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Migrations/NewInstallation.php
Expand Up @@ -115,7 +115,7 @@ public static function getData(): DataBag
$bag->addRate('Default', 0, 720, 'PT1H');
$bag->addRate('Default-Anonymous', 4, 60, 'PT1H');
$bag->addRateAllocation('Default');
$bag->addRateAllocation('Default-Anonymous', null, null, 0);
$bag->addRateAllocation('Default-Anonymous', null, null, false);
$bag->addAction('backend', 'Backend_Action_Action_Async', Backend\Action\Action\Async::class);
$bag->addAction('backend', 'Backend_Action_Event_Execute', Backend\Action\Event\Execute::class);
$bag->addAction('backend', 'Backend_Action_Plan_Billing', Backend\Action\Plan\Billing::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/Routes/OpenAPI.php
Expand Up @@ -70,7 +70,7 @@ public function setup(SetupInterface $setup, string $basePath, ParametersInterfa
$schema = new Schema(TypeFactory::getReference($name), clone $definitions);
(new SchemaResolver())->resolve($schema);

$result = $generator->generate($schema);
$result = (string) $generator->generate($schema);

$this->schemas[$name] = $setup->addSchema($name, (array) \json_decode($result));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/User/Facebook.php
Expand Up @@ -76,7 +76,7 @@ public function requestUser(string $code, string $clientId, string $redirectUri)
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
$id = $data->id ?? null;
$name = $data->name ?? null;
$email = $data->email ?? null;
Expand All @@ -103,7 +103,7 @@ protected function getAccessToken(string $code, string $clientId, string $client
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
if (isset($data->access_token)) {
return $data->access_token;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/User/Github.php
Expand Up @@ -73,7 +73,7 @@ public function requestUser(string $code, string $clientId, string $redirectUri)
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
$id = $data->id ?? null;
$name = $data->login ?? null;
$email = $data->email ?? null;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected function getAccessToken($code, $clientId, $clientSecret, $redirectUri)
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
if (isset($data->access_token)) {
return $data->access_token;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/User/Google.php
Expand Up @@ -73,7 +73,7 @@ public function requestUser(string $code, string $clientId, string $redirectUri)
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
$id = $data->id ?? null;
$name = $data->name ?? null;
$email = $data->email ?? null;
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function getAccessToken(string $code, string $clientId, string $client
return null;
}

$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
if (isset($data->access_token)) {
return $data->access_token;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/App.php
Expand Up @@ -197,7 +197,7 @@ public function delete(int $appId, UserContext $context): int

protected function insertScopes(int $appId, ?array $scopes): void
{
if (!empty($scopes) && is_array($scopes)) {
if (!empty($scopes)) {
$scopes = $this->scopeTable->getValidScopes($scopes);

foreach ($scopes as $scope) {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Cronjob.php
Expand Up @@ -160,7 +160,7 @@ public function delete(int $cronjobId, UserContext $context): int
public function execute(string|int $cronjobId)
{
if (is_numeric($cronjobId)) {
$existing = $this->cronjobTable->find($cronjobId);
$existing = $this->cronjobTable->find((int) $cronjobId);
} else {
$existing = $this->cronjobTable->findOneByName($cronjobId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Plan/Invoice.php
Expand Up @@ -205,9 +205,9 @@ public function pay(TransactionInterface $transaction)
private function generateInvoiceId(int $userId): string
{
$parts = [
str_pad($userId, 4, '0', STR_PAD_LEFT),
str_pad((string) $userId, 4, '0', STR_PAD_LEFT),
date('Y'),
str_pad(substr(intval(microtime(true) * 10), -6), 6, '0', STR_PAD_LEFT)
str_pad(substr((string) intval(microtime(true) * 10), -6), 6, '0', STR_PAD_LEFT)
];

return implode('-', $parts);
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Rate.php
Expand Up @@ -164,8 +164,8 @@ public function assertLimit(string $ip, int $routeId, Model\AppInterface $app, ?
$rateLimit = (int) $rate['rate_limit'];

if ($response !== null) {
$response->setHeader('X-RateLimit-Limit', $rateLimit);
$response->setHeader('X-RateLimit-Remaining', $rateLimit - $count);
$response->setHeader('X-RateLimit-Limit', '' . $rateLimit);
$response->setHeader('X-RateLimit-Remaining', '' . ($rateLimit - $count));
}

if ($count >= $rateLimit) {
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Role.php
Expand Up @@ -169,9 +169,9 @@ public function exists(string $name): int|false
}
}

protected function insertScopes(int $roleId, array $scopes): void
protected function insertScopes(int $roleId, ?array $scopes): void
{
if (!empty($scopes) && is_array($scopes)) {
if (!empty($scopes)) {
$scopes = $this->scopeTable->getValidScopes($scopes);

foreach ($scopes as $scope) {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Route/Config.php
Expand Up @@ -82,7 +82,7 @@ public function handleConfig(int $categoryId, int $routeId, string $path, array
if ($status == Resource::STATUS_DEVELOPMENT) {
// invalidate resource cache
if ($this->listing instanceof CachedListing) {
$this->listing->invalidateResource($path, $ver);
$this->listing->invalidateResource($path, (string) $ver);
}

// delete all responses from existing responses
Expand Down
14 changes: 10 additions & 4 deletions src/Service/Route/Method.php
Expand Up @@ -65,7 +65,7 @@ public function getMethod(int $routeId, ?string $version, string $method): array
if ($version === '*' || empty($version)) {
$version = $this->methodTable->getLatestVersion($routeId);
} else {
$version = $this->methodTable->getVersion($routeId, $version);
$version = $this->methodTable->getVersion($routeId, (int) $version);
}

if (empty($version)) {
Expand All @@ -77,15 +77,21 @@ public function getMethod(int $routeId, ?string $version, string $method): array

public function getAllowedMethods(int $routeId, ?string $version): array
{
if ($version === '*' || empty($version)) {
$version = $this->methodTable->getLatestVersion($routeId);
} else {
$version = (int) $version;
}

return $this->methodTable->getAllowedMethods($routeId, $version);
}

public function getRequestSchemas(int $routeId, string $version): array
public function getRequestSchemas(int $routeId, ?string $version): array
{
if ($version == '*' || empty($version)) {
if ($version === '*' || empty($version)) {
$version = $this->methodTable->getLatestVersion($routeId);
} else {
$version = $this->methodTable->getVersion($routeId, $version);
$version = $this->methodTable->getVersion($routeId, (int) $version);
}

if (empty($version)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Scope.php
Expand Up @@ -247,7 +247,7 @@ public function exists(string $name): int|false
*/
protected function insertRoutes(int $scopeId, ?array $routes): void
{
if (!empty($routes) && is_array($routes)) {
if (!empty($routes)) {
foreach ($routes as $route) {
if ($route->getAllow()) {
$this->scopeRouteTable->create(new Table\Generated\ScopeRoutesRow([
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Transaction.php
Expand Up @@ -230,7 +230,7 @@ private function buildPrepareContext(TransactionInterface $transaction): Prepare
private function buildReturnUrl(TransactionInterface $transaction): string
{
$returnUrl = $transaction->getReturnUrl();
$returnUrl = str_replace('{transaction_id}', $transaction->getId(), $returnUrl);
$returnUrl = str_replace('{transaction_id}', (string) $transaction->getId(), $returnUrl);

return $returnUrl;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Service/User/Authorize.php
Expand Up @@ -79,7 +79,7 @@ public function authorize(int $userId, Authorize_Request $request): array
throw new StatusCode\BadRequestException('Invalid redirect uri scheme');
}

$url = $app['url'];
$url = $app->getUrl();
if (!empty($url)) {
$url = new Url($url);
if ($url->getHost() != $redirectUri->getHost()) {
Expand All @@ -93,14 +93,14 @@ public function authorize(int $userId, Authorize_Request $request): array
}

// scopes
$scopes = $this->scopeService->getValidScopes($request->getScope(), (int) $app['id'], (int) $userId);
$scopes = $this->scopeService->getValidScopes($request->getScope(), $app->getId(), $userId);
if (empty($scopes)) {
throw new StatusCode\BadRequestException('No valid scopes provided');
}

// save the decision of the user. We save the decision so that it is
// possible for the user to revoke the access later on
$this->saveUserDecision($userId, $app['id'], $request->getAllow());
$this->saveUserDecision($userId, $app->getId(), $request->getAllow());

$state = $request->getState();
if ($request->getAllow()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/User/Captcha.php
Expand Up @@ -68,7 +68,7 @@ protected function verifyCaptcha(?string $captcha, string $secret)
$response = $this->httpClient->request($request);

if ($response->getStatusCode() == 200) {
$data = Parser::decode($response->getBody());
$data = Parser::decode((string) $response->getBody());
if ($data->success === true) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/User/Provider.php
Expand Up @@ -65,7 +65,7 @@ public function provider(string $providerName, User_Provider $request): string
}

$remote = new User_Remote();
$remote->setProvider($provider->getId());
$remote->setProvider((string) $provider->getId());
$remote->setRemoteId($user->getId());
$remote->setName($user->getUserName());
$remote->setEmail($user->getEmail());
Expand Down
2 changes: 1 addition & 1 deletion src/System/Action/GetSchema.php
Expand Up @@ -65,7 +65,7 @@ public function handle(RequestInterface $request, ParametersInterface $configura
}

$type = $this->loader->getSchema($schema['name']);
$json = \json_decode((new Generator\TypeSchema())->generate($type));
$json = \json_decode((string) (new Generator\TypeSchema())->generate($type));

return [
'schema' => $json,
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Route/Method.php
Expand Up @@ -90,7 +90,7 @@ public function getMethods(int $routeId, ?int $version = null, ?bool $active = t
return $this->project($sql, $params);
}

public function getAllowedMethods(int $routeId, ?string $version): array
public function getAllowedMethods(int $routeId, ?int $version): array
{
$methods = $this->getMethods($routeId, $version);
$names = [];
Expand Down Expand Up @@ -145,7 +145,7 @@ public function getMethodByOperationId(string $operationId): array|false
]);
}

public function getVersion(int $routeId, ?string $version): string|false
public function getVersion(int $routeId, int $version): string|false
{
$sql = 'SELECT version
FROM fusio_routes_method
Expand Down

0 comments on commit 69fac8d

Please sign in to comment.