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
23 changes: 22 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@

use Nextcloud\CodingStandard\Config;

$config = new Config();
class CookbookConfig extends Config {
public function __construct($name = 'default') {
parent::__construct($name);
}

public function getRules() : array {
$parentRules = parent::getRules();
$additionalRules = [
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_indent' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true
];
return array_merge(['@PSR12' => true], $parentRules, $additionalRules);
}
}

$config = new CookbookConfig();
$config
->getFinder()
->ignoreVCSIgnored(true)
Expand All @@ -18,5 +37,7 @@
->exclude('vendor')
->exclude('.github')
->in(__DIR__);


return $config;

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
[#1033](https://github.com/nextcloud/cookbook/pull/1033) @MarcelRobitaille
- Reenable PR checks from foreign forks
[#1045](https://github.com/nextcloud/cookbook/pull/1045) @christianlupus
- Prevent access to guzzle client without explicit dependency
[#1011](https://github.com/nextcloud/cookbook/pull/1011) @christianlupus
- Make PHP code styling more strict
[#1011](https://github.com/nextcloud/cookbook/pull/1011) @christianlupus

### Codebase maintenance
- Removed codecov.io upload of intermediate merge commits during pull requests [#1028](https://github.com/nextcloud/cookbook/issues/1028)
Expand Down
4 changes: 2 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (Util::getVersion()[0] >= 20) {
class Application extends App implements IBootstrap {
public const APP_ID = 'cookbook';

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}
Expand All @@ -29,7 +29,7 @@ public function boot(IBootContext $context): void {
} else {
class Application extends App {
public const APP_ID = 'cookbook';

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class ConfigController extends Controller {
* @var RecipeService
*/
private $service;

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

/**
* @var RestParameterParser
*/
Expand Down Expand Up @@ -55,7 +55,7 @@ public function __construct(
*/
public function list() {
$this->dbCacheService->triggerCheck();

return new DataResponse([
'folder' => $this->userFolder->getPath(),
'update_interval' => $this->dbCacheService->getSearchIndexUpdateInterval(),
Expand All @@ -69,7 +69,7 @@ public function list() {
*/
public function config() {
$data = $this->restParser->getParameters();

if (isset($data['folder'])) {
$this->userFolder->setPath($data['folder']);
$this->dbCacheService->updateCache();
Expand All @@ -84,10 +84,10 @@ public function config() {
}

$this->dbCacheService->triggerCheck();

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

/**
* @NoAdminRequired
* @NoCSRFRequired
Expand Down
29 changes: 17 additions & 12 deletions lib/Controller/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainController extends Controller {
* @var IURLGenerator
*/
private $urlGenerator;

/**
* @var RestParameterParser
*/
Expand Down Expand Up @@ -83,13 +83,13 @@ public function index(): TemplateResponse {
* will prevent the controller to be called. If this does not happen for some reason, let the exception be
* thrown and the user most probably has found a bug. A stack trace might help there.
*/

$this->dbCacheService->triggerCheck();

Util::addScript('cookbook', 'nextcloud-cookbook-main');
return new TemplateResponse($this->appName, 'index'); // templates/index.php
}

/**
* @NoAdminRequired
* @NoCSRFRequired
Expand All @@ -113,7 +113,7 @@ public function getApiVersion(): DataResponse {
*/
public function categories() {
$this->dbCacheService->triggerCheck();

$categories = $this->service->getAllCategoriesInSearchIndex();
return new DataResponse($categories, 200, ['Content-Type' => 'application/json']);
}
Expand All @@ -124,18 +124,19 @@ public function categories() {
*/
public function keywords() {
$this->dbCacheService->triggerCheck();

$keywords = $this->service->getAllKeywordsInSearchIndex();
return new DataResponse($keywords, 200, ['Content-Type' => 'application/json']);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @param mixed $query
*/
public function search($query) {
$this->dbCacheService->triggerCheck();

$query = urldecode($query);
try {
$recipes = $this->service->findRecipesInSearchIndex($query);
Expand Down Expand Up @@ -167,10 +168,11 @@ public function search($query) {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param mixed $category
*/
public function category($category) {
$this->dbCacheService->triggerCheck();

$category = urldecode($category);
try {
$recipes = $this->service->getRecipesByCategory($category);
Expand Down Expand Up @@ -201,6 +203,7 @@ public function category($category) {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param mixed $category
*/
public function categoryUpdate($category) {
$this->dbCacheService->triggerCheck();
Expand Down Expand Up @@ -230,6 +233,7 @@ public function categoryUpdate($category) {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param mixed $keywords
*/
public function tags($keywords) {
$this->dbCacheService->triggerCheck();
Expand Down Expand Up @@ -268,9 +272,9 @@ public function tags($keywords) {
*/
public function import() {
$this->dbCacheService->triggerCheck();

$data = $this->restParser->getParameters();

if (!isset($data['url'])) {
return new DataResponse('Field "url" is required', 400);
}
Expand Down Expand Up @@ -299,7 +303,7 @@ public function import() {
*/
public function new() {
$this->dbCacheService->triggerCheck();

try {
$recipe_data = $this->restParser->getParameters();
$file = $this->service->addRecipe($recipe_data);
Expand All @@ -314,18 +318,19 @@ public function new() {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param mixed $id
*/
public function update($id) {
$this->dbCacheService->triggerCheck();

try {
$recipe_data = $this->restParser->getParameters();

$recipe_data['id'] = $id;

$file = $this->service->addRecipe($recipe_data);
$this->dbCacheService->addRecipe($file);

return new DataResponse($id);
} catch (\Exception $e) {
return new DataResponse($e->getMessage(), 500);
Expand Down
22 changes: 11 additions & 11 deletions lib/Controller/RecipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class RecipeController extends Controller {
* @var IURLGenerator
*/
private $urlGenerator;

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

/**
* @var RestParameterParser
*/
Expand Down Expand Up @@ -75,7 +75,7 @@ public function __construct(
*/
public function index() {
$this->dbCacheService->triggerCheck();

if (empty($_GET['keywords'])) {
$recipes = $this->service->getAllRecipesInSearchIndex();
} else {
Expand All @@ -96,7 +96,7 @@ public function index() {
*/
public function show($id) {
$this->dbCacheService->triggerCheck();

$json = $this->service->getRecipeById($id);

if (null === $json) {
Expand All @@ -105,7 +105,7 @@ public function show($id) {

$json['printImage'] = $this->service->getPrintImage();
$json['imageUrl'] = $this->urlGenerator->linkToRoute('cookbook.recipe.image', ['id' => $json['id'], 'size' => 'full']);

return new DataResponse($json, Http::STATUS_OK, ['Content-Type' => 'application/json']);
}

Expand All @@ -122,7 +122,7 @@ public function show($id) {
*/
public function update($id) {
$this->dbCacheService->triggerCheck();

$recipeData = $this->restParser->getParameters();
try {
$file = $this->service->addRecipe($recipeData);
Expand Down Expand Up @@ -151,12 +151,12 @@ public function update($id) {
*/
public function create() {
$this->dbCacheService->triggerCheck();

$recipeData = $this->restParser->getParameters();
try {
$file = $this->service->addRecipe($recipeData);
$this->dbCacheService->addRecipe($file);

return new DataResponse($file->getParent()->getId(), Http::STATUS_OK, ['Content-Type' => 'application/json']);
} catch (RecipeExistsException $ex) {
$json = [
Expand All @@ -183,7 +183,7 @@ public function create() {
*/
public function destroy($id) {
$this->dbCacheService->triggerCheck();

try {
$this->service->deleteRecipe($id);
return new DataResponse('Recipe ' . $id . ' deleted successfully', Http::STATUS_OK);
Expand All @@ -200,7 +200,7 @@ public function destroy($id) {
*/
public function image($id) {
$this->dbCacheService->triggerCheck();

$acceptHeader = $this->request->getHeader('Accept');
$acceptedExtensions = $this->acceptHeaderParser->parseHeader($acceptHeader);

Expand All @@ -220,7 +220,7 @@ public function image($id) {
} else {
// The client accepts the SVG file. Send it.
$file = file_get_contents(dirname(__FILE__) . '/../../img/recipe.svg');

return new DataDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/DbTypesPolyfillHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DbTypesPolyfillHelper {
* @var String
*/
private $string;

public function __construct(Util $util) {
switch ($util->getVersion()[0]) {
case 18:
Expand All @@ -22,14 +22,14 @@ public function __construct(Util $util) {
$this->int = \Doctrine\DBAL\Types\Type::INTEGER;
$this->string = \Doctrine\DBAL\Types\Type::STRING;
break;

default:
$this->int = \OCP\DB\Types::INTEGER;
$this->string = \OCP\DB\Types::STRING;
break;
}
}

/**
* @return string
*/
Expand Down
Loading