Skip to content

Commit 848988a

Browse files
Merge 036bacc into 44fe2a1
2 parents 44fe2a1 + 036bacc commit 848988a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+489
-445
lines changed

.php-cs-fixer.dist.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@
66

77
use Nextcloud\CodingStandard\Config;
88

9-
$config = new Config();
9+
class CookbookConfig extends Config {
10+
public function __construct($name = 'default') {
11+
parent::__construct($name);
12+
}
13+
14+
public function getRules() : array {
15+
$parentRules = parent::getRules();
16+
$additionalRules = [
17+
'phpdoc_add_missing_param_annotation' => true,
18+
'phpdoc_indent' => true,
19+
'phpdoc_no_empty_return' => true,
20+
'phpdoc_scalar' => true,
21+
'phpdoc_single_line_var_spacing' => true,
22+
'phpdoc_var_without_name' => true
23+
];
24+
return array_merge(['@PSR12' => true], $parentRules, $additionalRules);
25+
}
26+
}
27+
28+
$config = new CookbookConfig();
1029
$config
1130
->getFinder()
1231
->ignoreVCSIgnored(true)
@@ -18,5 +37,7 @@
1837
->exclude('vendor')
1938
->exclude('.github')
2039
->in(__DIR__);
40+
41+
2142
return $config;
2243

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
[#988](https://github.com/nextcloud/cookbook/pull/988) @rakekniven
88
- Move "Categories" caption above list of categories
99
[#1000](https://github.com/nextcloud/cookbook/pull/1000) @seyfeb
10+
- Prevent access to guzzle client without explicit dependency
11+
[#1011](https://github.com/nextcloud/cookbook/pull/1011) @christianlupus
12+
- Make PHP code styling more strict
13+
[#1011](https://github.com/nextcloud/cookbook/pull/1011) @christianlupus
1014

1115
### Documentation
1216
- Add documentation on updates of the API endpoints

lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if (Util::getVersion()[0] >= 20) {
1515
class Application extends App implements IBootstrap {
1616
public const APP_ID = 'cookbook';
17-
17+
1818
public function __construct(array $urlParams = []) {
1919
parent::__construct(self::APP_ID, $urlParams);
2020
}
@@ -29,7 +29,7 @@ public function boot(IBootContext $context): void {
2929
} else {
3030
class Application extends App {
3131
public const APP_ID = 'cookbook';
32-
32+
3333
public function __construct(array $urlParams = []) {
3434
parent::__construct(self::APP_ID, $urlParams);
3535
}

lib/Controller/ConfigController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class ConfigController extends Controller {
1616
* @var RecipeService
1717
*/
1818
private $service;
19-
19+
2020
/**
2121
* @var DbCacheService
2222
*/
2323
private $dbCacheService;
24-
24+
2525
/**
2626
* @var RestParameterParser
2727
*/
@@ -41,7 +41,7 @@ public function __construct($AppName, IRequest $request, RecipeService $recipeSe
4141
*/
4242
public function list() {
4343
$this->dbCacheService->triggerCheck();
44-
44+
4545
return new DataResponse([
4646
'folder' => $this->service->getUserFolderPath(),
4747
'update_interval' => $this->dbCacheService->getSearchIndexUpdateInterval(),
@@ -55,7 +55,7 @@ public function list() {
5555
*/
5656
public function config() {
5757
$data = $this->restParser->getParameters();
58-
58+
5959
if (isset($data['folder'])) {
6060
$this->service->setUserFolderPath($data['folder']);
6161
$this->dbCacheService->updateCache();
@@ -70,10 +70,10 @@ public function config() {
7070
}
7171

7272
$this->dbCacheService->triggerCheck();
73-
73+
7474
return new DataResponse('OK', Http::STATUS_OK);
7575
}
76-
76+
7777
/**
7878
* @NoAdminRequired
7979
* @NoCSRFRequired

lib/Controller/MainController.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MainController extends Controller {
3232
* @var IURLGenerator
3333
*/
3434
private $urlGenerator;
35-
35+
3636
/**
3737
* @var RestParameterParser
3838
*/
@@ -68,13 +68,13 @@ public function index(): TemplateResponse {
6868
* will prevent the controller to be called. If this does not happen for some reason, let the exception be
6969
* thrown and the user most probably has found a bug. A stack trace might help there.
7070
*/
71-
71+
7272
$this->dbCacheService->triggerCheck();
7373

7474
Util::addScript('cookbook', 'nextcloud-cookbook-main');
7575
return new TemplateResponse($this->appName, 'index'); // templates/index.php
7676
}
77-
77+
7878
/**
7979
* @NoAdminRequired
8080
* @NoCSRFRequired
@@ -98,7 +98,7 @@ public function getApiVersion(): DataResponse {
9898
*/
9999
public function categories() {
100100
$this->dbCacheService->triggerCheck();
101-
101+
102102
$categories = $this->service->getAllCategoriesInSearchIndex();
103103
return new DataResponse($categories, 200, ['Content-Type' => 'application/json']);
104104
}
@@ -109,18 +109,19 @@ public function categories() {
109109
*/
110110
public function keywords() {
111111
$this->dbCacheService->triggerCheck();
112-
112+
113113
$keywords = $this->service->getAllKeywordsInSearchIndex();
114114
return new DataResponse($keywords, 200, ['Content-Type' => 'application/json']);
115115
}
116116

117117
/**
118118
* @NoAdminRequired
119119
* @NoCSRFRequired
120+
* @param string $query
120121
*/
121122
public function search($query) {
122123
$this->dbCacheService->triggerCheck();
123-
124+
124125
$query = urldecode($query);
125126
try {
126127
$recipes = $this->service->findRecipesInSearchIndex($query);
@@ -152,10 +153,11 @@ public function search($query) {
152153
/**
153154
* @NoAdminRequired
154155
* @NoCSRFRequired
156+
* @param string $category
155157
*/
156158
public function category($category) {
157159
$this->dbCacheService->triggerCheck();
158-
160+
159161
$category = urldecode($category);
160162
try {
161163
$recipes = $this->service->getRecipesByCategory($category);
@@ -186,6 +188,7 @@ public function category($category) {
186188
/**
187189
* @NoAdminRequired
188190
* @NoCSRFRequired
191+
* @param string $category
189192
*/
190193
public function categoryUpdate($category) {
191194
$this->dbCacheService->triggerCheck();
@@ -215,6 +218,7 @@ public function categoryUpdate($category) {
215218
/**
216219
* @NoAdminRequired
217220
* @NoCSRFRequired
221+
* @param string $keywords
218222
*/
219223
public function tags($keywords) {
220224
$this->dbCacheService->triggerCheck();
@@ -253,9 +257,9 @@ public function tags($keywords) {
253257
*/
254258
public function import() {
255259
$this->dbCacheService->triggerCheck();
256-
260+
257261
$data = $this->restParser->getParameters();
258-
262+
259263
if (!isset($data['url'])) {
260264
return new DataResponse('Field "url" is required', 400);
261265
}
@@ -284,7 +288,7 @@ public function import() {
284288
*/
285289
public function new() {
286290
$this->dbCacheService->triggerCheck();
287-
291+
288292
try {
289293
$recipe_data = $this->restParser->getParameters();
290294
$file = $this->service->addRecipe($recipe_data);
@@ -299,18 +303,19 @@ public function new() {
299303
/**
300304
* @NoAdminRequired
301305
* @NoCSRFRequired
306+
* @param int $id
302307
*/
303308
public function update($id) {
304309
$this->dbCacheService->triggerCheck();
305-
310+
306311
try {
307312
$recipe_data = $this->restParser->getParameters();
308313

309314
$recipe_data['id'] = $id;
310315

311316
$file = $this->service->addRecipe($recipe_data);
312317
$this->dbCacheService->addRecipe($file);
313-
318+
314319
return new DataResponse($id);
315320
} catch (\Exception $e) {
316321
return new DataResponse($e->getMessage(), 500);

lib/Controller/RecipeController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class RecipeController extends Controller {
2828
* @var IURLGenerator
2929
*/
3030
private $urlGenerator;
31-
31+
3232
/**
3333
* @var DbCacheService
3434
*/
3535
private $dbCacheService;
36-
36+
3737
/**
3838
* @var RestParameterParser
3939
*/
@@ -75,7 +75,7 @@ public function __construct(
7575
*/
7676
public function index() {
7777
$this->dbCacheService->triggerCheck();
78-
78+
7979
if (empty($_GET['keywords'])) {
8080
$recipes = $this->service->getAllRecipesInSearchIndex();
8181
} else {
@@ -96,7 +96,7 @@ public function index() {
9696
*/
9797
public function show($id) {
9898
$this->dbCacheService->triggerCheck();
99-
99+
100100
$json = $this->service->getRecipeById($id);
101101

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

106106
$json['printImage'] = $this->service->getPrintImage();
107107
$json['imageUrl'] = $this->urlGenerator->linkToRoute('cookbook.recipe.image', ['id' => $json['id'], 'size' => 'full']);
108-
108+
109109
return new DataResponse($json, Http::STATUS_OK, ['Content-Type' => 'application/json']);
110110
}
111111

@@ -122,7 +122,7 @@ public function show($id) {
122122
*/
123123
public function update($id) {
124124
$this->dbCacheService->triggerCheck();
125-
125+
126126
$recipeData = $this->restParser->getParameters();
127127
try {
128128
$file = $this->service->addRecipe($recipeData);
@@ -151,12 +151,12 @@ public function update($id) {
151151
*/
152152
public function create() {
153153
$this->dbCacheService->triggerCheck();
154-
154+
155155
$recipeData = $this->restParser->getParameters();
156156
try {
157157
$file = $this->service->addRecipe($recipeData);
158158
$this->dbCacheService->addRecipe($file);
159-
159+
160160
return new DataResponse($file->getParent()->getId(), Http::STATUS_OK, ['Content-Type' => 'application/json']);
161161
} catch (RecipeExistsException $ex) {
162162
$json = [
@@ -183,7 +183,7 @@ public function create() {
183183
*/
184184
public function destroy($id) {
185185
$this->dbCacheService->triggerCheck();
186-
186+
187187
try {
188188
$this->service->deleteRecipe($id);
189189
return new DataResponse('Recipe ' . $id . ' deleted successfully', Http::STATUS_OK);
@@ -200,7 +200,7 @@ public function destroy($id) {
200200
*/
201201
public function image($id) {
202202
$this->dbCacheService->triggerCheck();
203-
203+
204204
$acceptHeader = $this->request->getHeader('Accept');
205205
$acceptedExtensions = $this->acceptHeaderParser->parseHeader($acceptHeader);
206206

@@ -220,7 +220,7 @@ public function image($id) {
220220
} else {
221221
// The client accepts the SVG file. Send it.
222222
$file = file_get_contents(dirname(__FILE__) . '/../../img/recipe.svg');
223-
223+
224224
return new DataDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
225225
}
226226
}

lib/Db/DbTypesPolyfillHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DbTypesPolyfillHelper {
1313
* @var String
1414
*/
1515
private $string;
16-
16+
1717
public function __construct(Util $util) {
1818
switch ($util->getVersion()[0]) {
1919
case 18:
@@ -22,14 +22,14 @@ public function __construct(Util $util) {
2222
$this->int = \Doctrine\DBAL\Types\Type::INTEGER;
2323
$this->string = \Doctrine\DBAL\Types\Type::STRING;
2424
break;
25-
25+
2626
default:
2727
$this->int = \OCP\DB\Types::INTEGER;
2828
$this->string = \OCP\DB\Types::STRING;
2929
break;
3030
}
3131
}
32-
32+
3333
/**
3434
* @return string
3535
*/

0 commit comments

Comments
 (0)