use Nextcloud Coding Standard

This commit is contained in:
korelstar 2020-07-13 08:27:52 +02:00
parent 552bae269a
commit 017e825daf
33 changed files with 111 additions and 47 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ js/
report
clover.xml
composer.lock
.php_cs.cache
appinfo/info.xsd
# just sane ignores

18
.php_cs.dist Normal file
View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
require_once './vendor/autoload.php';
use Nextcloud\CodingStandard\Config;
$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;

View File

@ -88,8 +88,8 @@ test-api:
lint: lint-php lint-js lint-css lint-xml
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-phpfast lint-php-phan
lint-phpfast: lint-php-lint lint-php-ncversion lint-php-cs-fixer lint-php-phpcs
lint-php-lint:
# Check PHP syntax errors
@ -107,6 +107,10 @@ lint-php-phpcs:
# PHP CodeSniffer
vendor/bin/phpcs --standard=tests/phpcs.xml appinfo/ lib/ tests/api/ --report=checkstyle | vendor/bin/cs2pr --graceful-warnings --colorize
lint-php-cs-fixer:
# PHP Coding Standards Fixer (with Nextcloud coding standards)
vendor/bin/php-cs-fixer fix --dry-run --diff
lint-js:
npm run lint
@ -125,6 +129,7 @@ lint-fix: lint-php-fix lint-js-fix lint-css-fix
lint-php-fix:
vendor/bin/phpcbf --standard=tests/phpcs.xml appinfo/ lib/ tests/api/
vendor/bin/php-cs-fixer fix
lint-js-fix:
npm run lint:fix

View File

@ -1,4 +1,5 @@
<?php
return ['routes' => [
////////// P A G E //////////
[

View File

@ -1,6 +1,7 @@
{
"require-dev": {
"christophwurst/nextcloud": "^16.0",
"nextcloud/coding-standard": "^0.3.0",
"squizlabs/php_codesniffer": "3.*",
"phan/phan": "^3.0",
"guzzlehttp/guzzle": "^7.0",

View File

@ -1,11 +1,12 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes;
use OCP\AppFramework\App;
class Application extends App {
public static $API_VERSIONS = [ '0.2', '1.1' ];
public function __construct(array $urlParams = []) {

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Controller;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Controller;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Controller;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Controller;
@ -8,7 +10,6 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\IRequest;
class PageController extends Controller {
public function __construct(string $AppName, IRequest $request) {
parent::__construct($AppName, $request);
}

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Controller;
@ -10,7 +12,6 @@ use OCP\IRequest;
use OCP\IUserSession;
class SettingsController extends Controller {
private $service;
private $userSession;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Db;
@ -21,7 +23,6 @@ use OCP\AppFramework\Db\Entity;
* @package OCA\Notes\Db
*/
class Meta extends Entity {
protected $userId;
protected $fileId;
protected $lastUpdate;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Db;
@ -7,7 +9,6 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
class MetaMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'notes_meta');
}

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Migration;
@ -8,7 +10,6 @@ use OCP\Migration\IRepairStep;
use OCP\Migration\IOutput;
class Cleanup implements IRepairStep {
private $metaMapper;
public function __construct(MetaMapper $metaMapper) {

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Migration;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Migration;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
@ -47,7 +49,6 @@ use OCA\Notes\Db\MetaMapper;
* with this approach! :-)
*/
class MetaService {
private $metaMapper;
public function __construct(MetaMapper $metaMapper) {
@ -105,7 +106,7 @@ class MetaService {
private function getIndexedArray(array $data, string $property) : array {
$property = ucfirst($property);
$getter = 'get'.$property;
$result = array();
$result = [];
foreach ($data as $entity) {
$result[$entity->$getter()] = $entity;
}

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
@ -6,7 +8,6 @@ use OCP\Files\File;
use OCP\Files\Folder;
class Note {
private $file;
private $notesFolder;
private $noteUtil;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
@ -9,7 +11,6 @@ use OCP\IL10N;
use OCP\ILogger;
class NoteUtil {
private $db;
private $l10n;
private $root;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;

View File

@ -1,15 +1,14 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
use OCA\Notes\Service\SettingsService;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
class NotesService {
private $metaService;
private $settings;
private $noteUtil;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;
@ -7,7 +9,6 @@ use OCP\IL10N;
use OCP\Files\IRootFolder;
class SettingsService {
private $config;
private $l10n;
private $root;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Service;

View File

@ -1,4 +1,4 @@
<?php
script('notes', 'notes');
style('notes', 'notes');
?>

View File

@ -1,9 +1,10 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Tests\API;
class APIv02Test extends CommonAPITest {
public function __construct() {
parent::__construct('0.2', true);
}

View File

@ -1,9 +1,10 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Tests\API;
class APIv1Test extends CommonAPITest {
public function __construct() {
parent::__construct('1.1', false);
}

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Tests\API;

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Tests\API;

View File

@ -1,9 +1,10 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace OCA\Notes\Tests\API;
abstract class CommonAPITest extends AbstractAPITest {
private $requiredAttributes = [
'id' => 'integer',
'content' => 'string',