code style and lint errors

This commit is contained in:
korelstar 2019-05-25 08:15:05 +02:00 committed by GitHub
parent 682dc48055
commit 16de16937e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 892 additions and 901 deletions

2
.gitignore vendored
View File

@ -1,10 +1,12 @@
node_modules/
vendor/
*.log
build/
js/
.rvm
report
clover.xml
composer.lock
# just sane ignores
.*.sw[po]

View File

@ -11,6 +11,7 @@ build:
tests:
override:
- php-scrutinizer-run
- phpcs-run --standard=phpcs.xml appinfo/ lib/
- eslint-run --ext .js,.vue src
tools:

View File

@ -49,8 +49,7 @@ script:
# - phpunit -c phpunit.integration.xml
# build js
- make npm-init
- make init
- make lint
- make stylelint
- make build-js-production

View File

@ -9,32 +9,32 @@ appstore_dir=$(build_dir)/appstore
package_name=$(app_name)
cert_dir=$(HOME)/.nextcloud/certificates
appstore: clean
appstore: clean lint build-js-production
mkdir -p $(sign_dir)
rsync -a \
--exclude=.git \
--exclude=.babelrc.js \
--exclude=build \
--exclude=.gitignore \
--exclude=.travis.yml \
--exclude=.scrutinizer.yml \
--exclude=CONTRIBUTING.md \
--exclude=composer.json \
--exclude=composer.lock \
--exclude=composer.phar \
--exclude=.tx \
--exclude=CONTRIBUTING.md \
--exclude=.editorconfig \
--exclude=.eslintrc.js \
--exclude=.git \
--exclude=.github \
--exclude=.gitignore \
--exclude=l10n/no-php \
--exclude=Makefile \
--exclude=nbproject \
--exclude=screenshots \
--exclude=package*.json \
--exclude=phpcs.xml \
--exclude=phpunit*xml \
--exclude=.scrutinizer.yml \
--exclude=src \
--exclude=.stylelintrc.js \
--exclude=tests \
--exclude=vendor/bin \
--exclude=js/node_modules \
--exclude=js/tests \
--exclude=js/karma.conf.js \
--exclude=js/gulpfile.js \
--exclude=js/bower.json \
--exclude=js/package.json \
--exclude=.travis.yml \
--exclude=.tx \
--exclude=vendor \
$(project_dir) $(sign_dir)
@echo "Signing…"
php ../server/occ integrity:sign-app \
@ -51,7 +51,12 @@ appstore: clean
all: dev-setup lint build-js-production test
# Dev env management
dev-setup: clean clean-dev npm-init
dev-setup: clean clean-dev init
init: composer-init npm-init
composer-init:
composer install
npm-init:
npm install
@ -84,17 +89,27 @@ test-coverage:
npm run test:coverage
# Linting
lint:
lint: lint-php lint-js lint-css
lint-php:
vendor/bin/phpcs --standard=phpcs.xml --runtime-set ignore_warnings_on_exit 1 appinfo/ lib/
lint-js:
npm run lint
lint-fix:
npm run lint:fix
# Style linting
stylelint:
lint-css:
npm run stylelint
stylelint-fix:
# Fix lint
lint-fix: lint-php-fix lint-js-fix lint-css-fix
lint-php-fix:
vendor/bin/phpcbf --standard=phpcs.xml appinfo/ lib/
lint-js-fix:
npm run lint:fix
lint-css-fix:
npm run stylelint:fix
# Cleaning
@ -104,4 +119,5 @@ clean:
clean-dev:
rm -rf node_modules
rm -rf vendor

View File

@ -27,4 +27,3 @@ $container->query('OCP\INavigationManager')->add(function () use ($container) {
'name' => $l10n->t('Notes')
];
});

View File

@ -1,5 +1,6 @@
{
"require-dev": {
"christophwurst/nextcloud": "^15.0"
"christophwurst/nextcloud": "^15.0",
"squizlabs/php_codesniffer": "3.*"
}
}

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;
@ -165,9 +156,9 @@ class NotesApiController extends ApiController {
/**
* Updates a note, used by create and update
* @param int $id
* @param string $content
* @param string|null $content
* @param int $modified
* @param boolean $favorite
* @param boolean|null $favorite
* @return Note
*/
private function updateData($id, $content, $category, $modified, $favorite) {
@ -195,6 +186,4 @@ class NotesApiController extends ApiController {
return [];
});
}
}

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;
@ -49,13 +40,15 @@ class NotesController extends Controller {
* @param IL10N $l10n
* @param string $UserId
*/
public function __construct($AppName,
public function __construct(
$AppName,
IRequest $request,
NotesService $notesService,
SettingsService $settingsService,
IConfig $settings,
IL10N $l10n,
$UserId) {
$UserId
) {
parent::__construct($AppName, $request);
$this->notesService = $notesService;
$this->settingsService = $settingsService;
@ -73,8 +66,11 @@ class NotesController extends Controller {
$settings = $this->settingsService->getAll($this->userId);
$errorMessage = null;
$lastViewedNote = (int) $this->settings->getUserValue($this->userId,
$this->appName, 'notesLastViewedNote');
$lastViewedNote = (int) $this->settings->getUserValue(
$this->userId,
$this->appName,
'notesLastViewedNote'
);
// check if notes folder is accessible
try {
$this->notesService->checkNotesFolder($this->userId);
@ -110,7 +106,10 @@ class NotesController extends Controller {
public function get($id) {
// save the last viewed note
$this->settings->setUserValue(
$this->userId, $this->appName, 'notesLastViewedNote', $id
$this->userId,
$this->appName,
'notesLastViewedNote',
$id
);
return $this->respond(function () use ($id) {
@ -127,7 +126,10 @@ class NotesController extends Controller {
public function create($content = '', $category = null) {
$note = $this->notesService->create($this->userId);
$note = $this->notesService->update(
$note->getId(), $content, $this->userId, $category
$note->getId(),
$content,
$this->userId,
$category
);
return new DataResponse($note);
}
@ -189,5 +191,4 @@ class NotesController extends Controller {
return [];
});
}
}

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;
@ -51,5 +42,4 @@ class PageController extends Controller {
return $response;
}
}

View File

@ -1,5 +1,6 @@
<?php
namespace OCA\Notes\Controller;
use OCP\AppFramework\Controller;
use OCP\IConfig;
@ -10,8 +11,8 @@ use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\JSONResponse;
use OCA\Notes\Service\SettingsService;
class SettingsController extends Controller
{
class SettingsController extends Controller {
private $service;
private $userSession;

View File

@ -1,15 +1,21 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/
namespace OCA\Notes\Db;
use OCP\AppFramework\Db\Entity;
/**
* Class Meta
* @method string getUserId()
* @method void setUserId(string $value)
* @method integer getFileId()
* @method void setFileId(integer $value)
* @method integer getLastUpdate()
* @method void setLastUpdate(integer $value)
* @method string getEtag()
* @method void setEtag(string $value)
* @package OCA\Notes\Db
*/
class Meta extends Entity {
public $userId;

View File

@ -1,29 +1,24 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/
namespace OCA\Notes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
class MetaMapper extends Mapper {
class MetaMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'notes_meta');
}
public function getAll($userId) {
$sql = 'SELECT * FROM `*PREFIX*notes_meta` WHERE user_id=?';
return $this->findEntities($sql, [$userId]);
}
public function get($userId, $fileId) {
$sql = 'SELECT * FROM `*PREFIX*notes_meta` WHERE user_id=? AND file_id=?';
return $this->findEntity($sql, [$userId, $fileId]);
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('*PREFIX*notes_meta')
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
);
return $this->findEntities($qb);
}
}

View File

@ -1,20 +1,11 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Db;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\AppFramework\Db\Entity;
use League\Flysystem\FileNotFoundException;
/**
* Class Note
* @method integer getId()
@ -62,7 +53,7 @@ class Note extends Entity {
if (!$onlyMeta) {
$fileContent=$file->getContent();
if ($fileContent===false) {
throw new FileNotFoundException("File not found");
throw new \Exception("File not found");
}
$note->setContent(self::convertEncoding($fileContent));
}
@ -80,6 +71,7 @@ class Note extends Entity {
$note->resetUpdatedFields();
return $note;
}
/**
* @param File $file
* @return static

View File

@ -1,10 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/
namespace OCA\Notes\Service;

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Service;
@ -18,4 +9,5 @@ use Exception;
*
* @package OCA\Notes\Service
*/
class NoteDoesNotExistException extends Exception {}
class NoteDoesNotExistException extends Exception {
}

View File

@ -1,11 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
*/
namespace OCA\Notes\Service;
@ -16,4 +9,5 @@ use Exception;
*
* @package OCA\Notes\Service
*/
class NotesFolderException extends Exception {}
class NotesFolderException extends Exception {
}

View File

@ -1,13 +1,4 @@
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Service;
@ -17,13 +8,11 @@ use OCP\Files\IRootFolder;
use OCP\Files\Folder;
use OCP\ILogger;
use OCP\Encryption\Exceptions\GenericEncryptionException;
use League\Flysystem\FileNotFoundException;
use OCA\Notes\Db\Note;
use OCA\Notes\Service\SettingsService;
use OCP\IConfig;
use OCP\IUserSession;
/**
* Class NotesService
*
@ -109,8 +98,6 @@ class NotesService {
$id = $file->getId();
try {
$note = Note::fromFile($file, $notesFolder, $tags, $onlyMeta);
} catch(FileNotFoundException $e){
$note = Note::fromException($this->l10n->t('File error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
} catch (GenericEncryptionException $e) {
$note = Note::fromException($this->l10n->t('Encryption Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
} catch (\Exception $e) {
@ -149,8 +136,9 @@ class NotesService {
* Updates a note. Be sure to check the returned note since the title is
* dynamically generated and filename conflicts are resolved
* @param int $id the id of the note used to update
* @param string $content the content which will be written into the note
* @param string|null $content the content which will be written into the note
* the title is generated from the first line of the content
* @param string|null $category the category in which the note should be saved
* @param int $mtime time of the note modification (optional)
* @throws NoteDoesNotExistException if note does not exist
* @return \OCA\Notes\Db\Note the updated note
@ -177,7 +165,9 @@ class NotesService {
// sanitise path
$cats = explode('/', $category);
$cats = array_map([$this, 'sanitisePath'], $cats);
$cats = array_filter($cats, function($str) { return !empty($str); });
$cats = array_filter($cats, function ($str) {
return !empty($str);
});
$basePath .= '/'.implode('/', $cats);
}
}
@ -224,10 +214,11 @@ class NotesService {
throw new NoteDoesNotExistException();
}
$tagger = \OC::$server->getTagManager()->load('files');
if($favorite)
if ($favorite) {
$tagger->addToFavorites($id);
else
} else {
$tagger->removeFromFavorites($id);
}
$tags = $tagger->getTagsForObjects([$id]);
return array_key_exists($id, $tags) && in_array(\OC\Tags::TAG_FAVORITE, $tags[$id]);
@ -316,7 +307,7 @@ class NotesService {
* @return boolean true if folder is accessible, or Exception otherwise
*/
public function checkNotesFolder($userId) {
$folder = $this->getFolderForUser($userId);
$this->getFolderForUser($userId);
return true;
}
@ -391,8 +382,11 @@ class NotesService {
$match = preg_match('/\((?P<id>\d+)\)$/u', $title, $matches);
if ($match) {
$newId = ((int) $matches['id']) + 1;
$newTitle = preg_replace('/(.*)\s\((\d+)\)$/u',
'$1 (' . $newId . ')', $title);
$newTitle = preg_replace(
'/(.*)\s\((\d+)\)$/u',
'$1 (' . $newId . ')',
$title
);
} else {
$newTitle = $title . ' (2)';
}
@ -430,7 +424,9 @@ class NotesService {
private function isNote($file) {
$allowedExtensions = ['txt', 'org', 'markdown', 'md', 'note'];
if($file->getType() !== 'file') return false;
if ($file->getType() !== 'file') {
return false;
}
$ext = pathinfo($file->getName(), PATHINFO_EXTENSION);
$iext = strtolower($ext);
@ -439,5 +435,4 @@ class NotesService {
}
return true;
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace OCA\Notes\Service;
use OCP\AppFramework\Controller;
use OCP\IConfig;
@ -10,15 +11,15 @@ use OCP\IUserSession;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\JSONResponse;
class SettingsService
{
class SettingsService {
private $config;
private $root;
/* Default values */
private $defaults = [
"notesPath" => "Notes",
"fileSuffix" => ".txt",
'notesPath' => 'Notes',
'fileSuffix' => '.txt',
];
public function __construct(

32
phpcs.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>
PSR2 with changes:
* tabs instead of spaces (https://gist.github.com/gsherwood/9d22f634c57f990a7c64)
* bracers on end of line instead new line
</description>
<!-- tabs -->
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<!-- bracers -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<!-- tabs -->
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
</rule>
<!-- tabs -->
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<!-- bracers -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
<rule ref="Generic.Classes.OpeningBraceSameLine"/>
</ruleset>