Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add psalm workflow #423

Merged
merged 12 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Static analysis

on:
pull_request:
push:
branches:
- main
- stable*

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

strategy:
matrix:
ocp-version: [ 'dev-master' ]

name: Nextcloud ${{ matrix.ocp-version }}
steps:
- name: Checkout
uses: actions/checkout@master

- name: Set up php
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

- name: Install dependencies
run: composer i

- name: Run coding standards check
run: composer run psalm
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
->getFinder()
->notPath('build')
->notPath('l10n')
->notPath('node_modules')
->notPath('src')
->notPath('tests/data')
->notPath('vendor')
->notPath('vendor-bin')
->notPath('node_modules')
->in(__DIR__);
return $config;
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ updater.phar: box updater.php lib/*.php buildVersionFile.php
clean:
rm updater.phar index.php

index.php:
index.php: lib/UpdateException.php lib/LogException.php lib/RecursiveDirectoryIteratorWithoutData.php lib/Updater.php index.web.php
# First put openining php tag and license
awk '/^<\?php$$/,/\*\//' index.web.php > index.php
# Then concat all files while filtering php tag and license
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"cs:fix": "php-cs-fixer fix",
"lint": "find . -name \\*.php -not -path './vendor*' -not -path './build/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l",
"post-install-cmd": ["@composer bin all install --ansi"],
"post-update-cmd": ["@composer bin all update --ansi"]
"post-update-cmd": ["@composer bin all update --ansi"],
"psalm": "psalm",
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:update-baseline": "psalm --threads=1 --update-baseline"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.5"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function __construct($baseDir) {
/** @var string $OC_VersionString */
/** @var string $OC_Build */
require_once $versionFileName;
/** @psalm-suppress UndefinedVariable */
$version = $OC_VersionString;
$buildTime = $OC_Build;
}
Expand Down Expand Up @@ -151,11 +152,9 @@ public function getCurrentVersion() {

/**
* Returns currently used release channel
*
* @return string
*/
private function getCurrentReleaseChannel() {
return !is_null($this->getConfigOption('updater.release.channel')) ? $this->getConfigOption('updater.release.channel') : 'stable';
private function getCurrentReleaseChannel(): string {
return (string)($this->getConfigOption('updater.release.channel') ?? 'stable');
}

/**
Expand Down Expand Up @@ -206,10 +205,9 @@ public function updateAvailable() {
/**
* Returns the specified config options
*
* @param string $key
* @return mixed|null Null if the entry is not found
*/
public function getConfigOption($key) {
public function getConfigOption(string $key) {
return isset($this->configValues[$key]) ? $this->configValues[$key] : null;
}

Expand Down Expand Up @@ -515,6 +513,7 @@ private function getUpdateServerResponse() {
]);
}

/** @var false|string $response */
$response = curl_exec($curl);
if ($response === false) {
throw new \Exception('Could not do request to updater server: '.curl_error($curl));
Expand Down Expand Up @@ -705,6 +704,7 @@ public function verifyIntegrity() {
private function getVersionByVersionFile($versionFile) {
require $versionFile;

/** @psalm-suppress UndefinedVariable */
if (isset($OC_Version)) {
/** @var array $OC_Version */
return implode('.', $OC_Version);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ public function endStep($step) {
}

/**
* @return string
* @return array
* @throws \Exception
*/
public function currentStep() {
Expand Down
2 changes: 1 addition & 1 deletion lib/CommandApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function getCommandName(InputInterface $input) {
/**
* Gets the default commands that should always be available.
*
* @return array An array of default Command instances
* @return \Symfony\Component\Console\Command\Command[] An array of default Command instances
*/
protected function getDefaultCommands() {
// Keep the core default commands to have the HelpCommand
Expand Down
1 change: 0 additions & 1 deletion lib/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Symfony\Component\Console\Question\ConfirmationQuestion;

class UpdateCommand extends Command {

/** @var Updater */
protected $updater;

Expand Down
14 changes: 7 additions & 7 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function __construct($baseDir) {
/** @var string $OC_VersionString */
/** @var string $OC_Build */
require_once $versionFileName;
/** @psalm-suppress UndefinedVariable */
$version = $OC_VersionString;
$buildTime = $OC_Build;
}
Expand Down Expand Up @@ -121,11 +122,9 @@ public function getCurrentVersion() {

/**
* Returns currently used release channel
*
* @return string
*/
private function getCurrentReleaseChannel() {
return !is_null($this->getConfigOption('updater.release.channel')) ? $this->getConfigOption('updater.release.channel') : 'stable';
private function getCurrentReleaseChannel(): string {
return (string)($this->getConfigOption('updater.release.channel') ?? 'stable');
}

/**
Expand Down Expand Up @@ -176,10 +175,9 @@ public function updateAvailable() {
/**
* Returns the specified config options
*
* @param string $key
* @return mixed|null Null if the entry is not found
*/
public function getConfigOption($key) {
public function getConfigOption(string $key) {
return isset($this->configValues[$key]) ? $this->configValues[$key] : null;
}

Expand Down Expand Up @@ -485,6 +483,7 @@ private function getUpdateServerResponse() {
]);
}

/** @var false|string $response */
$response = curl_exec($curl);
if ($response === false) {
throw new \Exception('Could not do request to updater server: '.curl_error($curl));
Expand Down Expand Up @@ -675,6 +674,7 @@ public function verifyIntegrity() {
private function getVersionByVersionFile($versionFile) {
require $versionFile;

/** @psalm-suppress UndefinedVariable */
if (isset($OC_Version)) {
/** @var array $OC_Version */
return implode('.', $OC_Version);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ public function endStep($step) {
}

/**
* @return string
* @return array
* @throws \Exception
*/
public function currentStep() {
Expand Down
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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="lib" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor" />
</extraFiles>
</psalm>
Binary file modified updater.phar
Binary file not shown.
3 changes: 2 additions & 1 deletion vendor-bin/coding-standard/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"sort-packages": true
},
"require-dev": {
"nextcloud/coding-standard": "^1.0"
"nextcloud/coding-standard": "^1.0",
"vimeo/psalm": "^4.26"
}
}
Loading