Skip to content

Enable code styling and php linter #390

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

Merged
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: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ on:

jobs:

lint:
name: Run PHP Linter and Code Style checker
runs-on: ubuntu-latest
steps:
- name: Checkout the project
uses: actions/checkout@v2
- name: Install Composer
shell: bash
run: >-
wget https://github.com/composer/getcomposer.org/raw/master/web/installer -O - -q |
php -- --quiet
- name: Install packages
shell: bash
run: composer install
- name: Run linter
shell: bash
run: composer lint:lint
- name: Run code style checker
shell: bash
run: composer cs:check

test:
name: Run the unittests
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ cookbook.tar.gz

.idea/

/.php_cs.cache

# Built js package
js/*

Expand Down
22 changes: 22 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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('lib/Vendor')
->notPath('src')
->notPath('node_modules')
->notPath('vendor')
->notPath('.github')
->in(__DIR__);
return $config;

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
[#383](https://github.com/nextcloud/cookbook/pull/383/) @christianlupus
- Unit tests for JSON object service
[#387](https://github.com/nextcloud/cookbook/pull/387) @TobiasMie
- PHP linter and style checker enabled
[#390](https://github.com/nextcloud/cookbook/pull/390) @christianlupus

### Changed
- Switch of project ownership to neextcloud organization in GitHub
Expand Down
44 changes: 22 additions & 22 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
* it's instantiated in there
*/
return [
'routes' => [
['name' => 'main#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'main#home', 'url' => '/home', 'verb' => 'GET'],
['name' => 'main#keywords', 'url' => '/keywords', 'verb' => 'GET'],
['name' => 'main#categories', 'url' => '/categories', 'verb' => 'GET'],
['name' => 'main#error', 'url' => '/error', 'verb' => 'GET'],
['name' => 'main#create', 'url' => '/recipes/create', 'verb' => 'GET'],
['name' => 'main#new', 'url' => '/recipes/create', 'verb' => 'POST'],
['name' => 'main#import', 'url' => '/import', 'verb' => 'POST'],
['name' => 'main#edit', 'url' => '/recipes/{id}/edit', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'main#update', 'url' => '/recipes/{id}/edit', 'verb' => 'PUT', 'requirements' => ['id' => '\d+']],
['name' => 'main#recipe', 'url' => '/recipes/{id}', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'recipe#image', 'url' => '/recipes/{id}/image', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'config#reindex', 'url' => '/reindex', 'verb' => 'POST'],
['name' => 'config#list', 'url' => '/config', 'verb' => 'GET'],
['name' => 'config#config', 'url' => '/config', 'verb' => 'POST'],
/* API routes */
['name' => 'main#category', 'url' => '/api/category/{category}', 'verb' => 'GET'],
['name' => 'main#tags', 'url' => '/api/tags/{keywords}', 'verb' => 'GET'],
['name' => 'main#search', 'url' => '/api/search/{query}', 'verb' => 'GET'],
],
'routes' => [
['name' => 'main#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'main#home', 'url' => '/home', 'verb' => 'GET'],
['name' => 'main#keywords', 'url' => '/keywords', 'verb' => 'GET'],
['name' => 'main#categories', 'url' => '/categories', 'verb' => 'GET'],
['name' => 'main#error', 'url' => '/error', 'verb' => 'GET'],
['name' => 'main#create', 'url' => '/recipes/create', 'verb' => 'GET'],
['name' => 'main#new', 'url' => '/recipes/create', 'verb' => 'POST'],
['name' => 'main#import', 'url' => '/import', 'verb' => 'POST'],
['name' => 'main#edit', 'url' => '/recipes/{id}/edit', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'main#update', 'url' => '/recipes/{id}/edit', 'verb' => 'PUT', 'requirements' => ['id' => '\d+']],
['name' => 'main#recipe', 'url' => '/recipes/{id}', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'recipe#image', 'url' => '/recipes/{id}/image', 'verb' => 'GET', 'requirements' => ['id' => '\d+']],
['name' => 'config#reindex', 'url' => '/reindex', 'verb' => 'POST'],
['name' => 'config#list', 'url' => '/config', 'verb' => 'GET'],
['name' => 'config#config', 'url' => '/config', 'verb' => 'POST'],
/* API routes */
['name' => 'main#category', 'url' => '/api/category/{category}', 'verb' => 'GET'],
['name' => 'main#tags', 'url' => '/api/tags/{keywords}', 'verb' => 'GET'],
['name' => 'main#search', 'url' => '/api/search/{query}', 'verb' => 'GET'],
],

/* API resources */
'resources' => [
'recipe' => ['url' => '/api/recipes']
'recipe' => ['url' => '/api/recipes']
]
];
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
},
"require-dev": {
"phpunit/phpunit": ">=8.0",
"nikic/php-parser": "4.2"
"nikic/php-parser": "4.2",
"nextcloud/coding-standard": "^0.3.0"
},
"scripts": {
"cs:check": "./vendor/bin/php-cs-fixer fix --dry-run --diff",
"cs:fix": "./vendor/bin/php-cs-fixer fix",
"lint:lint": "find . -name '*.php' -not -path './vendor/*' -not -path './.github/*' -print0 | xargs -0 -n1 php -l"
}
}
129 changes: 60 additions & 69 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,82 @@

namespace OCA\Cookbook\Controller;

use OCP\IConfig;
use OCP\IRequest;
use OCP\IDBConnection;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Controller;

use OCA\Cookbook\Service\RecipeService;
use OCP\IURLGenerator;
use OCA\Cookbook\Service\DbCacheService;

class ConfigController extends Controller
{
/**
* @var RecipeService
*/
private $service;
/**
* @var IURLGenerator
*/
private $urlGenerator;

/**
* @var DbCacheService
*/
private $dbCacheService;
class ConfigController extends Controller {
/**
* @var RecipeService
*/
private $service;
/**
* @var IURLGenerator
*/
private $urlGenerator;

/**
* @var DbCacheService
*/
private $dbCacheService;

public function __construct($AppName, IRequest $request, IURLGenerator $urlGenerator, RecipeService $recipeService, DbCacheService $dbCacheService)
{
parent::__construct($AppName, $request);
public function __construct($AppName, IRequest $request, IURLGenerator $urlGenerator, RecipeService $recipeService, DbCacheService $dbCacheService) {
parent::__construct($AppName, $request);

$this->service = $recipeService;
$this->urlGenerator = $urlGenerator;
$this->dbCacheService = $dbCacheService;
}
$this->service = $recipeService;
$this->urlGenerator = $urlGenerator;
$this->dbCacheService = $dbCacheService;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function list() {
$this->dbCacheService->triggerCheck();
return new DataResponse([
'folder' => $this->service->getUserFolderPath(),
'update_interval' => $this->dbCacheService->getSearchIndexUpdateInterval(),
'print_image' => $this->service->getPrintImage(),
], Http::STATUS_OK);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function list() {
$this->dbCacheService->triggerCheck();
return new DataResponse([
'folder' => $this->service->getUserFolderPath(),
'update_interval' => $this->dbCacheService->getSearchIndexUpdateInterval(),
'print_image' => $this->service->getPrintImage(),
], Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function config()
{
$this->dbCacheService->triggerCheck();

if (isset($_POST['folder'])) {
$this->service->setUserFolderPath($_POST['folder']);
$this->dbCacheService->updateCache();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function config() {
$this->dbCacheService->triggerCheck();

if (isset($_POST['folder'])) {
$this->service->setUserFolderPath($_POST['folder']);
$this->dbCacheService->updateCache();
}

if (isset($_POST['update_interval'])) {
$this->service->setSearchIndexUpdateInterval($_POST['update_interval']);
}
if (isset($_POST['update_interval'])) {
$this->service->setSearchIndexUpdateInterval($_POST['update_interval']);
}

if (isset($_POST['print_image'])) {
$this->service->setPrintImage((bool)$_POST['print_image']);
}
if (isset($_POST['print_image'])) {
$this->service->setPrintImage((bool)$_POST['print_image']);
}

return new DataResponse('OK', Http::STATUS_OK);
}
return new DataResponse('OK', Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function reindex()
{
$this->dbCacheService->updateCache();
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function reindex() {
$this->dbCacheService->updateCache();

return new DataResponse('Search index rebuilt successfully', Http::STATUS_OK);
}
return new DataResponse('Search index rebuilt successfully', Http::STATUS_OK);
}
}
Loading