Skip to content

Commit

Permalink
add psalm action, fix all psalm errors
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 12, 2024
1 parent d61c218 commit daaddbd
Show file tree
Hide file tree
Showing 28 changed files with 454 additions and 134 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Psalm static analysis

on:
pull_request:
paths:
- .github/workflows/psalm.yml
- appinfo/**
- composer.*
- lib/**
- templates/**
- tests/**
push:
branches:
- main
- stable*
- test
paths:
- .github/workflows/psalm.yml
- appinfo/**
- composer.*
- lib/**
- templates/**
- tests/**

concurrency:
group: psalm-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
static-analysis:
runs-on: ubuntu-latest

name: Psalm check
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up php
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
with:
php-version: 8.2
coverage: none
ini-file: development
extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, gd, zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer i

- name: Run coding standards check
run: composer run psalm
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.idea
/css/fontawesome-free
/vendor
/.php-cs-fixer.cache
.php*.cache
/composer.lock
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar",
"psalm": "psalm.phar --no-cache",
"test:unit": "phpunit --config tests/phpunit.xml"
},
"require-dev": {
Expand Down
13 changes: 8 additions & 5 deletions lib/Controller/ComparisonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use OCP\DB\Exception;

use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IRequest;
Expand Down Expand Up @@ -62,8 +63,10 @@ public function comparePageGet(): TemplateResponse {
if (isset($_GET['path' . $i]) && $_GET['path' . $i] !== '') {
$cleanPath = str_replace(array('../', '..\\'), '', $_GET['path' . $i]);
$file = $userFolder->get($cleanPath);
$content = $file->getContent();
$gpxs[$cleanPath] = $content;
if ($file instanceof File) {
$content = $file->getContent();
$gpxs[$cleanPath] = $content;
}
}
}
}
Expand Down Expand Up @@ -756,15 +759,15 @@ private function getStats(array $contents, array &$process_errors): array {
if (empty($point->time)) {
$pointtime = null;
} else {
$pointtime = new \DateTime($point->time);
$pointtime = new \DateTime((string) $point->time);
}
if ($lastPoint !== null && (!empty($lastPoint->ele))) {
$lastPointele = (float)$lastPoint->ele;
} else {
$lastPointele = null;
}
if ($lastPoint !== null && (!empty($lastPoint->time))) {
$lastTime = new \DateTime($lastPoint->time);
$lastTime = new \DateTime((string) $lastPoint->time);
} else {
$lastTime = null;
}
Expand Down Expand Up @@ -860,7 +863,7 @@ private function getStats(array $contents, array &$process_errors): array {
$lastPointele = null;
}
if ($lastPoint !== null && (!empty($lastPoint->time))) {
$lastTime = new \DateTime($lastPoint->time);
$lastTime = new \DateTime((string) $lastPoint->time);
} else {
$lastTime = null;
}
Expand Down
14 changes: 9 additions & 5 deletions lib/Controller/OldComparisonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;

use OCP\Files\File;
use OCP\Files\IRootFolder;

use OCP\IConfig;
Expand Down Expand Up @@ -91,8 +92,10 @@ public function gpxvcomp(): TemplateResponse {
if (isset($_GET['path'.$i]) && $_GET['path'.$i] !== '') {
$cleanpath = str_replace(array('../', '..\\'), '', $_GET['path'.$i]);
$file = $userFolder->get($cleanpath);
$content = $file->getContent();
$gpxs[$cleanpath] = $content;
if ($file instanceof File) {
$content = $file->getContent();
$gpxs[$cleanpath] = $content;
}
}
}
}
Expand Down Expand Up @@ -222,6 +225,7 @@ private function processTrackComparison($contents, &$process_errors): array {
}

// comparison of each pair of input file
/** @var array $names */
$names = array_keys($contents);
$i = 0;
while ($i < count($names)) {
Expand Down Expand Up @@ -832,7 +836,7 @@ private function getStats($contents, &$process_errors): array {
$lastPointele = null;
}
if ($lastPoint !== null && (!empty($lastPoint->time))) {
$lastTime = new \DateTime($lastPoint->time);
$lastTime = new \DateTime((string) $lastPoint->time);
} else {
$lastTime = null;
}
Expand Down Expand Up @@ -928,7 +932,7 @@ private function getStats($contents, &$process_errors): array {
$lastPointele = null;
}
if ($lastPoint !== null && (!empty($lastPoint->time))) {
$lastTime = new \DateTime($lastPoint->time);
$lastTime = new \DateTime((string) $lastPoint->time);
} else {
$lastTime = null;
}
Expand Down Expand Up @@ -1021,7 +1025,7 @@ private function getStats($contents, &$process_errors): array {
$moving_avg_speed = $total_distance / $moving_time;
$moving_avg_speed = $moving_avg_speed / 1000;
$moving_avg_speed = $moving_avg_speed * 3600;
$moving_avg_speed = sprintf('%.2f', $moving_avg_speed);
$moving_avg_speed = (float) sprintf('%.2f', $moving_avg_speed);
}

if ($date_begin === null) {
Expand Down
Loading

0 comments on commit daaddbd

Please sign in to comment.