Skip to content
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
21 changes: 19 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,34 @@ jobs:
uses: actions/checkout@master
- name: Setup xmllint
run: sudo apt-get install --no-install-recommends -y libxml2-utils
- name: Setup xmllint problem matcher
uses: korelstar/xmllint-problem-matcher@master
- name: lint XML
run: make lint-xml

lint-php:
runs-on: ubuntu-latest
strategy:
matrix:
version: [min, max]
include:
- version: min
php-version: 7.1
- version: max
php-version: 7.4
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
- name: Install Dependencies
run: composer install --prefer-dist
- name: Install latest Nextcloud API (dev-master)
if: matrix.version == 'max'
run: composer require --dev christophwurst/nextcloud:dev-master
- name: Load problem matcher for php -l
uses: korelstar/phplint-problem-matcher@master
- name: lint PHP
run: make lint-php
run: make -k lint-php
21 changes: 0 additions & 21 deletions .phan/to-annotation.php

This file was deleted.

23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,31 @@ test-watch:
test-coverage:
npm run test:coverage


# Linting
lint: lint-php lint-js lint-css lint-xml

lint-php:

lint-php: lint-php-lint lint-php-ncversion lint-php-phan lint-php-phpcs
lint-phpfast: lint-php-lint lint-php-ncversion lint-php-phpcs

lint-php-lint:
# Check PHP syntax errors
@! find lib/ -name "*.php" | xargs -I{} php -l '{}' | grep -v "No syntax errors detected"
# PHP CodeSniffer
vendor/bin/phpcs --standard=phpcs.xml --runtime-set ignore_warnings_on_exit 1 appinfo/ lib/
# PHAN
vendor/phan/phan/phan --allow-polyfill-parser -k .phan/config.php --no-progress-bar -m json | php .phan/to-annotation.php

lint-php-ncversion:
# Check min-version consistency
php tests/nextcloud-version.php

lint-php-phan:
# PHAN
vendor/bin/phan --allow-polyfill-parser -k .phan/config.php --no-progress-bar -m checkstyle | vendor/bin/cs2pr

lint-php-phpcs:
# PHP CodeSniffer
vendor/bin/phpcs --standard=phpcs.xml appinfo/ lib/ --report=checkstyle | vendor/bin/cs2pr


lint-js:
npm run lint

Expand All @@ -114,6 +126,7 @@ lint-xml:
wget https://apps.nextcloud.com/schema/apps/info.xsd -P appinfo/ -N --no-verbose || [ -f appinfo/info.xsd ]
xmllint appinfo/info.xml --schema appinfo/info.xsd --noout


# Fix lint
lint-fix: lint-php-fix lint-js-fix lint-css-fix

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"require-dev": {
"christophwurst/nextcloud": "^15.0",
"squizlabs/php_codesniffer": "3.*",
"phan/phan": "^2.0"
"phan/phan": "^2.0",
"staabm/annotate-pull-request-from-checkstyle": "^1.0"
}
}
14 changes: 10 additions & 4 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public function getOrCreateFolder(string $path) : Folder {

/*
* Delete a folder and it's parent(s) if it's/they're empty
* @param Folder root folder for notes
* @param Folder folder to delete
* @param Folder $notesFolder root folder for notes
* @param Folder $folder folder to delete
*/
public function deleteEmptyFolder(Folder $notesFolder, Folder $folder) : void {
$content = $folder->getDirectoryListing();
Expand All @@ -225,13 +225,19 @@ public function deleteEmptyFolder(Folder $notesFolder, Folder $folder) : void {

/**
* Checks if there is enough space left on storage. Throws an Exception if storage is not sufficient.
* @param Folder folder that needs storage
* @param Folder $folder that needs storage
* @param int $requiredBytes amount of storage needed in $folder
* @throws InsufficientStorageException
*/
public function ensureSufficientStorage(Folder $folder, $requiredBytes) : void {
$availableBytes = $folder->getFreeSpace();
if ($availableBytes >= 0 && $availableBytes < $requiredBytes) {
$this->logger->error('Insufficient storage in '.$folder->getPath().': available are '.$availableBytes.'; required are '.$requiredBytes, ['app' => $this->appName]);
$this->logger->error(
'Insufficient storage in '.$folder->getPath().': '.
'available are '.$availableBytes.'; '.
'required are '.$requiredBytes,
['app' => $this->appName]
);
throw new InsufficientStorageException($requiredBytes.' are required in '.$folder->getPath());
}
}
Expand Down
78 changes: 58 additions & 20 deletions tests/nextcloud-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,45 @@ function getNCVersionFromComposer($path) {
if(!is_object($json)) {
throw new Exception('Composer file does not contain valid JSON');
}
if(!property_exists($json, 'require-dev')) {
throw new Exception('Composer file has no "require-dev" section');
$dev = getValidProperty($json, 'require-dev');
$v = getValidProperty($dev, 'christophwurst/nextcloud');
if(substr($v, 0, 1)=='^') {
$v = substr($v, 1);
}
$dev = $json->{'require-dev'};
if(!is_object($dev)) {
throw new Exception('Composer file has no valid "require-dev" section');
return $v;
}


function getNCVersionFromComposerBranchAlias($path) {
if(!file_exists($path)) {
throw new Exception('Composer file does not exists: '.$path);
}
if(!property_exists($dev, 'christophwurst/nextcloud')) {
throw new Exception('Composer file has no "nextcloud" dependency');
if(!is_readable($path)) {
throw new Exception('Composer file is not readable: '.$path);
}
$v = $dev->{'christophwurst/nextcloud'};
if(substr($v, 0, 1)=='^') {
$v = substr($v, 1);
$content = file_get_contents($path);
$json = json_decode($content);
if(!is_object($json)) {
throw new Exception('Composer file does not contain valid JSON');
}
$extra = getValidProperty($json, 'extra');
$branchAlias = getValidProperty($extra, 'branch-alias');
$v = getValidProperty($branchAlias, 'dev-master');
if(substr($v, -4)=='-dev') {
$v = substr($v, 0, -4);
}
return $v;
}

function getNCVersionFromAppInfo($path) {

function getValidProperty($json, $prop) {
if(!property_exists($json, $prop)) {
throw new Exception('Composer file has no "'.$prop.'" section');
}
return $json->{$prop};
}

function getNCVersionFromAppInfo($path, $minmax='min') {
if(!file_exists($path)) {
throw new Exception('AppInfo does not exists: '.$path);
}
Expand All @@ -39,21 +60,38 @@ function getNCVersionFromAppInfo($path) {
$content = file_get_contents($path);
$info = new SimpleXMLElement($content);
$nc = $info->dependencies->nextcloud;
$v = (string)$nc->attributes()->{'min-version'};
if(strpos($v, '.') === false) {
$v .= '.0';
}
$v = (string)$nc->attributes()->{$minmax.'-version'};
return $v;
}

echo 'Testing Nextcloud min-version: ';
function versionCompare($sv1, $sv2) {
$v1 = explode('.', $sv1);
$v2 = explode('.', $sv2);
$count = min(count($v1), count($v2));
for($i=0; $i<$count; $i++) {
if($v1[$i] !== $v2[$i]) {
return false;
}
}
return true;
}

echo 'Testing Nextcloud version ';
try {
$vComposer = getNCVersionFromComposer(__DIR__.'/../composer.json');
$vAppInfo = getNCVersionFromAppInfo(__DIR__.'/../appinfo/info.xml');
if($vComposer === $vAppInfo) {
echo $vAppInfo.PHP_EOL;
if($vComposer === 'dev-master') {
$vComposer = getNCVersionFromComposerBranchAlias(__DIR__.'/../vendor/christophwurst/nextcloud/composer.json');
$vAppInfo = getNCVersionFromAppInfo(__DIR__.'/../appinfo/info.xml', 'max');
echo 'max';
} else {
$vAppInfo = getNCVersionFromAppInfo(__DIR__.'/../appinfo/info.xml', 'min');
echo 'min';
}
echo ': '.$vAppInfo.' (AppInfo) vs. '.$vComposer.' (Composer) => ';
if(versionCompare($vComposer, $vAppInfo)) {
echo 'OK'.PHP_EOL;
} else {
echo 'FAILED with '.$vComposer.' (Composer) vs. '.$vAppInfo.' (AppInfo)'.PHP_EOL;
echo 'FAILED'.PHP_EOL;
exit(1);
}
} catch(Exception $e) {
Expand Down