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
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect":
{
"host":"localhost",
"port":5678
},
"pathMappings": [
{
"localRoot":"${workspaceFolder:cookbook}/.github/actions/run-tests",
"remoteRoot":"."
}
],
"justMyCode":true
},
//{
// "name": "Xdebug on 9000",
// "type": "php",
Expand All @@ -14,6 +31,16 @@
// "/var/www/html": "${workspaceFolder:base}"
// }
//},
{
"name": "Xdebug PHPUnit",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/custom_apps/cookbook": "${workspaceFolder:cookbook}",
"/var/www/html": "${workspaceFolder:base}"
}
},
{
"name": "Xdebug on 9003",
"type": "php",
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
[#1691](https://github.com/nextcloud/cookbook/pull/1691) @christianlupus
- Fix some comments and updated PHP coding style
[#1710](https://github.com/nextcloud/cookbook/pull/1710) @dependabot @christianlupus
- Update Psalm and fix some introduced issues
[#1707](https://github.com/nextcloud/cookbook/pull/1707) @christianlupus


## 0.10.2 - 2023-03-24
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
"require-dev": {
"nextcloud/coding-standard": "^1.0.0",
"christophwurst/nextcloud_testing": "^0.12.4",
"psalm/phar": "^4.10",
"psalm/phar": "^5.12",
"nextcloud/ocp": "^25.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/*' -not -path './node_modules/*' -not -path './tests/phpunit/*' -print0 | xargs -0 -n1 php -l",
"psalm": "psalm.phar --threads=1",
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm.phar --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"psalm": "psalm.phar --threads=1 --no-diff",
"psalm:nobaseline": "psalm.phar --threads=1 --no-diff --ignore-baseline",
"psalm:nocache": "psalm.phar --no-cache --threads=1",
"psalm:update-baseline": "psalm.phar --threads=1 --no-diff --update-baseline",
"psalm:update-baseline:force": "psalm.phar --threads=1 --no-diff --update-baseline --set-baseline=tests/psalm-baseline.xml",
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
"psalm:fix": "psalm.phar --alter --no-cache --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
},
"config": {
"platform": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cookbook.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
},
"intelephense.environment.includePaths": [
"${workspaceFolder:base}/3rdparty/doctrine/dbal/src"
]
],
"psalm.phpExecutablePath": "",
"psalm.psalmScriptPath": "vendor/bin/psalm.phar"
}
}
4 changes: 3 additions & 1 deletion lib/Controller/RecipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use OCA\Cookbook\Controller\Implementation\RecipeImplementation;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;

class RecipeController extends Controller {
Expand Down Expand Up @@ -72,7 +74,7 @@ public function destroy($id) {
* @NoAdminRequired
* @NoCSRFRequired
* @param $id
* @return JSONResponse|FileDisplayResponse|DataDisplayResponse
* @return Response
*/
public function image($id) {
return $this->impl->image($id);
Expand Down
14 changes: 7 additions & 7 deletions lib/Db/RecipeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function findAllRecipes(string $user_id) {
return $this->unique($recipesGroupedTags);
}

private function mapDbNames($results) {
private function mapDbNames(array $results) {
return array_map(function ($x) {
$x['dateCreated'] = $x['date_created'];
$x['dateModified'] = $x['date_modified'];
Expand Down Expand Up @@ -347,7 +347,7 @@ public function getRecipesByKeywords(string $keywords, string $user_id) {
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
*/
public function findRecipes(array $keywords, string $user_id) {
$has_keywords = $keywords && is_array($keywords) && sizeof($keywords) > 0 && $keywords[0];
$has_keywords = $keywords && is_array($keywords) && $keywords[0];

if (!$has_keywords) {
return $this->findAllRecipes($user_id);
Expand Down Expand Up @@ -453,7 +453,7 @@ private function isRecipeEmpty($json) {
* @param array $ids
*/
public function deleteRecipes(array $ids, string $userId) {
if (!is_array($ids) || empty($ids)) {
if (empty($ids)) {
return;
}

Expand Down Expand Up @@ -488,7 +488,7 @@ public function deleteRecipes(array $ids, string $userId) {
* @param array $recipes
*/
public function insertRecipes(array $recipes, string $userId) {
if (!is_array($recipes) || empty($recipes)) {
if (empty($recipes)) {
return;
}

Expand Down Expand Up @@ -520,7 +520,7 @@ public function insertRecipes(array $recipes, string $userId) {
}

public function updateRecipes(array $recipes, string $userId) {
if (!is_array($recipes) || empty($recipes)) {
if (empty($recipes)) {
return;
}

Expand Down Expand Up @@ -635,7 +635,7 @@ public function removeCategoryOfRecipe(int $recipeId, string $userId) {
}

public function addKeywordPairs(array $pairs, string $userId) {
if (!is_array($pairs) || empty($pairs)) {
if (empty($pairs)) {
return;
}

Expand All @@ -657,7 +657,7 @@ public function addKeywordPairs(array $pairs, string $userId) {
}

public function removeKeywordPairs(array $pairs, string $userId) {
if (!is_array($pairs) || empty($pairs)) {
if (empty($pairs)) {
return;
}

Expand Down
8 changes: 6 additions & 2 deletions lib/Helper/DownloadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DownloadHelper {
/**
* The content of the last download
*
* @var ?string
* @var string
*/
private $content;
/**
Expand All @@ -30,7 +30,7 @@ class DownloadHelper {
/**
* The HTTP status of the last download
*
* @var ?int
* @var int
*/
private $status;

Expand All @@ -43,6 +43,8 @@ public function __construct(
$this->downloaded = false;
$this->l = $l;
$this->headers = [];
$this->status = 0;
$this->content = '';
}

/**
Expand Down Expand Up @@ -94,6 +96,7 @@ public function downloadFile(string $url, array $options = []): void {
* Note: You must first trigger the download using downloadFile method.
*
* @return string The content of the downloaded file
*
* @throws NoDownloadWasCarriedOutException if there was no successful download carried out before calling this method.
*/
public function getContent(): string {
Expand Down Expand Up @@ -133,6 +136,7 @@ public function getContentType(): ?string {
* Note: You must first trigger the download using downloadFile method.
*
* @return int The HTTP status code
*
* @throws NoDownloadWasCarriedOutException if there was no successful download carried out before calling this method.
*/
public function getStatus(): int {
Expand Down
5 changes: 4 additions & 1 deletion lib/Helper/Filter/AbstractJSONFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ abstract class AbstractJSONFilter {
*/
abstract public function apply(array &$json): bool;

protected function setJSONValue(array &$json, string $key, $value): bool {
/**
* @param string|int|float|array $value
*/
protected function setJSONValue(array &$json, string $key, string|int|float|array $value): bool {
if (!array_key_exists($key, $json)) {
$json[$key] = $value;
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/Filter/JSON/SchemaConformityFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function apply(array &$json): bool {
$changed |= $this->setJSONValue($json, '@context', 'http://schema.org');
$changed |= $this->setJSONValue($json, '@type', 'Recipe');

return $changed;
return (bool) $changed;
}
}
1 change: 0 additions & 1 deletion lib/Helper/HTMLParser/HttpMicrodataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ private function searchChildEntries(DOMNode $recipeNode, string $prop): DOMNodeL
private function extractAttribute(DOMNodeList $nodes, array $attributes): array {
$foundEntries = [];

/** @var $node \DOMElement */
foreach ($nodes as $node) {
try {
$foundEntries[] = $this->extractSingeAttribute($node, $attributes);
Expand Down
6 changes: 3 additions & 3 deletions lib/Helper/ISO8601DurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private function parseIsoFormat(string $duration): string {
$ret = preg_match($pattern, trim($duration), $matches);

if ($ret === 1) {
$hours = $matches[1] ?? 0;
$minutes = $matches[2] ?? 0;
$seconds = $matches[3] ?? 0;
$hours = (int)$matches[1];
$minutes = (int) ($matches[2] ?? 0);
$seconds = (int) ($matches[3] ?? 0);

while ($seconds >= 60) {
$seconds -= 60;
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/UserFolderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getFolder(): Folder {
return $this->cache;
}

private function getOrCreateFolder($path): Folder {
private function getOrCreateFolder(string $path): Folder {
try {
$node = $this->root->get($path);
} catch (NotFoundException $ex) {
Expand Down
5 changes: 4 additions & 1 deletion lib/Service/DbCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DbCacheService {
/** @var NormalizeRecipeFileFilter */
private $normalizeFileFilter;

/**
* @var array<int, mixed>
*/
private $jsonFiles;
private $dbReceipeFiles;
private $dbKeywords;
Expand Down Expand Up @@ -223,7 +226,7 @@ private function compareReceipeLists() {

// private function

private function isDbEntryUpToDate($id) {
private function isDbEntryUpToDate(int $id) {
$dbEntry = $this->dbReceipeFiles[$id];
$fileEntry = $this->jsonFiles[$id];

Expand Down
3 changes: 3 additions & 0 deletions lib/Service/HtmlDownloadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ public function getDom(): ?DOMDocument {

/**
* Fetch an HTML page from the internet
*
* @param string $url The URL of the page to fetch
*
* @throws ImportException If the given URL was not fetched
*
* @return string The content of the page as a plain string
*/
private function fetchHtmlPage(string $url): string {
Expand Down
2 changes: 0 additions & 2 deletions lib/Service/RecipeExtractionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OCA\Cookbook\Service;

use OCA\Cookbook\Exception\HtmlParsingException;
use OCA\Cookbook\Helper\HTMLParser\AbstractHtmlParser;
use OCA\Cookbook\Helper\HTMLParser\HttpJsonLdParser;
use OCA\Cookbook\Helper\HTMLParser\HttpMicrodataParser;
use OCP\IL10N;
Expand Down Expand Up @@ -34,7 +33,6 @@ public function __construct(HttpJsonLdParser $jsonParser, HttpMicrodataParser $m
* @return array The data as returned from the parser
*/
public function parse(\DOMDocument $document, ?string $url): array {
/** @var $parser AbstractHtmlParser */
foreach ($this->parsers as $parser) {
try {
return $parser->parse($document, $url);
Expand Down
Loading