Some old issues were solved but not all.

Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Christian Wolf 2023-06-04 11:44:15 +02:00
Родитель a5a649c95d
Коммит e058d2ef82
9 изменённых файлов: 81 добавлений и 125 удалений

Просмотреть файл

@ -21,11 +21,13 @@
"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 --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType --no-diff"
},
"config": {
"platform": {

Просмотреть файл

@ -4,6 +4,8 @@ namespace OCA\Cookbook\Controller;
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 {
@ -72,7 +74,7 @@ class RecipeController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
* @param $id
* @return JSONResponse|FileDisplayResponse|DataDisplayResponse
* @return Response
*/
public function image($id) {
return $this->impl->image($id);

Просмотреть файл

@ -347,7 +347,7 @@ class RecipeDb {
* @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);
@ -453,7 +453,7 @@ class RecipeDb {
* @param array $ids
*/
public function deleteRecipes(array $ids, string $userId) {
if (!is_array($ids) || empty($ids)) {
if (empty($ids)) {
return;
}
@ -488,7 +488,7 @@ class RecipeDb {
* @param array $recipes
*/
public function insertRecipes(array $recipes, string $userId) {
if (!is_array($recipes) || empty($recipes)) {
if (empty($recipes)) {
return;
}
@ -520,7 +520,7 @@ class RecipeDb {
}
public function updateRecipes(array $recipes, string $userId) {
if (!is_array($recipes) || empty($recipes)) {
if (empty($recipes)) {
return;
}
@ -635,7 +635,7 @@ class RecipeDb {
}
public function addKeywordPairs(array $pairs, string $userId) {
if (!is_array($pairs) || empty($pairs)) {
if (empty($pairs)) {
return;
}
@ -657,7 +657,7 @@ class RecipeDb {
}
public function removeKeywordPairs(array $pairs, string $userId) {
if (!is_array($pairs) || empty($pairs)) {
if (empty($pairs)) {
return;
}

Просмотреть файл

@ -233,7 +233,6 @@ class HttpMicrodataParser extends AbstractHtmlParser {
private function extractAttribute(DOMNodeList $nodes, array $attributes): array {
$foundEntries = [];
/** @var $node \DOMElement */
foreach ($nodes as $node) {
try {
$foundEntries[] = $this->extractSingeAttribute($node, $attributes);

Просмотреть файл

@ -47,9 +47,9 @@ class ISO8601DurationHelper {
$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];
$seconds = (int)$matches[3];
while ($seconds >= 60) {
$seconds -= 60;

Просмотреть файл

@ -37,6 +37,9 @@ class DbCacheService {
/** @var NormalizeRecipeFileFilter */
private $normalizeFileFilter;
/**
* @var array<int, mixed>
*/
private $jsonFiles;
private $dbReceipeFiles;
private $dbKeywords;

Просмотреть файл

@ -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;
@ -34,7 +33,6 @@ class RecipeExtractionService {
* @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);

Просмотреть файл

@ -184,7 +184,7 @@ class RecipeService {
$user_folder = $this->userFolder->getFolder();
$recipe_folder = $user_folder->getById($id);
if ($recipe_folder && count($recipe_folder) > 0) {
if ($recipe_folder) {
$recipe_folder[0]->delete();
}

Просмотреть файл

@ -1,121 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<files psalm-version="5.12.0@f90118cdeacd0088e7215e64c0c99ceca819e176">
<file src="lib/Controller/Implementation/CategoryImplementation.php">
<InvalidArgument occurrences="2">
<code>$e-&gt;getMessage()</code>
<code>'New category name not found in data'</code>
<InvalidArgument>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA['New category name not found in data']]></code>
</InvalidArgument>
</file>
<file src="lib/Controller/Implementation/ConfigImplementation.php">
<InvalidArgument occurrences="2">
<code>'OK'</code>
<code>'Search index rebuilt successfully'</code>
<InvalidArgument>
<code><![CDATA['OK']]></code>
<code><![CDATA['Search index rebuilt successfully']]></code>
</InvalidArgument>
</file>
<file src="lib/Controller/Implementation/RecipeImplementation.php">
<InvalidArgument occurrences="10">
<code>$e-&gt;getMessage()</code>
<code>$e-&gt;getMessage()</code>
<code>$e-&gt;getMessage()</code>
<code>$e-&gt;getMessage()</code>
<code>$e-&gt;getMessage()</code>
<code>$file-&gt;getParent()-&gt;getId()</code>
<code>$file-&gt;getParent()-&gt;getId()</code>
<InvalidArgument>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA[$e->getMessage()]]></code>
<code><![CDATA[$file->getParent()->getId()]]></code>
<code><![CDATA[$file->getParent()->getId()]]></code>
<code>$id</code>
<code>'Field "url" is required'</code>
<code>'Recipe ' . $id . ' deleted successfully'</code>
<code><![CDATA['Field "url" is required']]></code>
<code><![CDATA['Recipe ' . $id . ' deleted successfully']]></code>
</InvalidArgument>
<TooManyArguments occurrences="3">
<code>new JSONResponse($recipes, 200, ['Content-Type' =&gt; 'application/json'])</code>
<code>new JSONResponse($recipes, Http::STATUS_OK, ['Content-Type' =&gt; 'application/json'])</code>
<code>new JSONResponse($recipes, Http::STATUS_OK, ['Content-Type' =&gt; 'application/json'])</code>
<TooManyArguments>
<code><![CDATA[new JSONResponse($recipes, 200, ['Content-Type' => 'application/json'])]]></code>
<code><![CDATA[new JSONResponse($recipes, Http::STATUS_OK, ['Content-Type' => 'application/json'])]]></code>
<code><![CDATA[new JSONResponse($recipes, Http::STATUS_OK, ['Content-Type' => 'application/json'])]]></code>
</TooManyArguments>
</file>
<file src="lib/Controller/RecipeController.php">
<InvalidReturnStatement occurrences="8">
<code>$this-&gt;impl-&gt;create()</code>
<code>$this-&gt;impl-&gt;destroy($id)</code>
<code>$this-&gt;impl-&gt;getAllInCategory($category)</code>
<code>$this-&gt;impl-&gt;getAllWithTags($keywords)</code>
<code>$this-&gt;impl-&gt;image($id)</code>
<code>$this-&gt;impl-&gt;search($query)</code>
<code>$this-&gt;impl-&gt;show($id)</code>
<code>$this-&gt;impl-&gt;update($id)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="8">
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse|FileDisplayResponse|DataDisplayResponse</code>
</InvalidReturnType>
<UndefinedDocblockClass occurrences="8">
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse</code>
<code>JSONResponse|FileDisplayResponse|DataDisplayResponse</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Db/RecipeDb.php">
<RedundantCondition occurrences="2">
<code>$keywords &amp;&amp; is_array($keywords)</code>
<RedundantCondition>
<code><![CDATA[$keywords && is_array($keywords)]]></code>
<code>is_array($keywords)</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="5">
<code>!is_array($ids)</code>
<code>!is_array($pairs)</code>
<code>!is_array($pairs)</code>
<code>!is_array($recipes)</code>
<code>!is_array($recipes)</code>
</TypeDoesNotContainType>
</file>
<file src="lib/Helper/DownloadHelper.php">
<InvalidNullableReturnType occurrences="2">
<InvalidNullableReturnType>
<code>int</code>
<code>string</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="2">
<code>$this-&gt;content</code>
<code>$this-&gt;status</code>
<NullableReturnStatement>
<code><![CDATA[$this->content]]></code>
<code><![CDATA[$this->status]]></code>
</NullableReturnStatement>
</file>
<file src="lib/Helper/Filter/JSON/FixRecipeYieldFilter.php">
<ParadoxicalCondition occurrences="1">
<code>is_float($json[self::YIELD]) || is_double($json[self::YIELD])</code>
</ParadoxicalCondition>
<file src="lib/Helper/Filter/JSON/FixInstructionsFilter.php">
<NamedArgumentNotAllowed>
<code>$instructions</code>
<code>$newElements</code>
</NamedArgumentNotAllowed>
</file>
<file src="lib/Helper/Filter/JSON/SchemaConformityFilter.php">
<FalseOperand occurrences="1">
<FalseOperand>
<code>$changed</code>
</FalseOperand>
<InvalidOperand occurrences="1">
<code>$this-&gt;setJSONValue($json, '@type', 'Recipe')</code>
<InvalidOperand>
<code><![CDATA[$this->setJSONValue($json, '@type', 'Recipe')]]></code>
</InvalidOperand>
<InvalidReturnStatement occurrences="1">
<InvalidReturnStatement>
<code>$changed</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<InvalidReturnType>
<code>bool</code>
</InvalidReturnType>
</file>
<file src="lib/Helper/Filter/NormalizeRecipeFileFilter.php">
<InvalidOperand occurrences="1">
<code>$filter-&gt;apply($json, $recipeFile)</code>
<InvalidOperand>
<code><![CDATA[$filter->apply($json, $recipeFile)]]></code>
</InvalidOperand>
</file>
<file src="lib/Helper/HTMLParser/HttpMicrodataParser.php">
<InvalidDocblock occurrences="1"/>
<MissingDocblockType occurrences="1">
<code>$node</code>
</MissingDocblockType>
<UndefinedMethod occurrences="4">
<UndefinedMethod>
<code>getAttribute</code>
<code>getAttribute</code>
<code>getElementsByTagName</code>
@ -123,7 +81,7 @@
</UndefinedMethod>
</file>
<file src="lib/Helper/ImageService/ThumbnailFileHelper.php">
<UndefinedDocblockClass occurrences="8">
<UndefinedDocblockClass>
<code>GenericFileException</code>
<code>GenericFileException</code>
<code>InvalidPathException</code>
@ -135,30 +93,30 @@
</UndefinedDocblockClass>
</file>
<file src="lib/Helper/RestParameterParser.php">
<InvalidReturnType occurrences="1">
<InvalidReturnType>
<code>array</code>
</InvalidReturnType>
</file>
<file src="lib/Helper/UserConfigHelper.php">
<InvalidScalarArgument occurrences="1">
<InvalidScalarArgument>
<code>$value</code>
</InvalidScalarArgument>
</file>
<file src="lib/Helper/UserFolderHelper.php">
<MissingDependency occurrences="4">
<code>$this-&gt;root</code>
<code>$this-&gt;root</code>
<MissingDependency>
<code><![CDATA[$this->root]]></code>
<code><![CDATA[$this->root]]></code>
<code>IRootFolder</code>
<code>IRootFolder</code>
</MissingDependency>
</file>
<file src="lib/Search/Provider.php">
<DuplicateClass occurrences="1">
<DuplicateClass>
<code>Provider</code>
</DuplicateClass>
</file>
<file src="lib/Service/ImageService.php">
<UndefinedDocblockClass occurrences="7">
<UndefinedDocblockClass>
<code>GenericFileException</code>
<code>InvalidPathException</code>
<code>InvalidThumbnailTypeException</code>
@ -168,33 +126,27 @@
<code>RecipeImageExistsException</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Service/RecipeExtractionService.php">
<InvalidDocblock occurrences="1"/>
<MissingDocblockType occurrences="1">
<code>$parser</code>
</MissingDocblockType>
</file>
<file src="lib/Service/RecipeService.php">
<InvalidNullableReturnType occurrences="2">
<InvalidNullableReturnType>
<code>array</code>
<code>int</code>
</InvalidNullableReturnType>
<MissingDependency occurrences="5">
<code>$this-&gt;root</code>
<code>$this-&gt;root</code>
<code>$this-&gt;root</code>
<code>$this-&gt;root</code>
<MissingDependency>
<code><![CDATA[$this->root]]></code>
<code><![CDATA[$this->root]]></code>
<code><![CDATA[$this->root]]></code>
<code><![CDATA[$this->root]]></code>
<code>IRootFolder</code>
</MissingDependency>
<NullableReturnStatement occurrences="3">
<NullableReturnStatement>
<code>null</code>
<code>null</code>
<code>null</code>
</NullableReturnStatement>
<RedundantCondition occurrences="1">
<code>!array_key_exists('dateCreated', $json) &amp;&amp; method_exists($file, 'getCreationTime')</code>
<RedundantCondition>
<code><![CDATA[!array_key_exists('dateCreated', $json) && method_exists($file, 'getCreationTime')]]></code>
</RedundantCondition>
<UndefinedInterfaceMethod occurrences="4">
<UndefinedInterfaceMethod>
<code>newFile</code>
<code>newFile</code>
<code>newFile</code>
@ -202,7 +154,7 @@
</UndefinedInterfaceMethod>
</file>
<file src="lib/Service/ThumbnailService.php">
<MissingDependency occurrences="6">
<MissingDependency>
<code>$img</code>
<code>$img</code>
<code>$img</code>