зеркало из https://github.com/nextcloud/cookbook.git
Fixed some psalm issues in code
Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Родитель
b7198a7755
Коммит
7113dd48d0
|
@ -27,7 +27,7 @@
|
|||
"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 --no-diff"
|
||||
"psalm:fix": "psalm.phar --alter --no-cache --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
|
|
|
@ -57,6 +57,8 @@
|
|||
},
|
||||
"intelephense.environment.includePaths": [
|
||||
"${workspaceFolder:base}/3rdparty/doctrine/dbal/src"
|
||||
]
|
||||
],
|
||||
"psalm.phpExecutablePath": "",
|
||||
"psalm.psalmScriptPath": "vendor/bin/psalm.phar"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ class RecipeDb {
|
|||
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'];
|
||||
|
|
|
@ -18,7 +18,7 @@ class DownloadHelper {
|
|||
/**
|
||||
* The content of the last download
|
||||
*
|
||||
* @var ?string
|
||||
* @var string
|
||||
*/
|
||||
private $content;
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ class DownloadHelper {
|
|||
/**
|
||||
* The HTTP status of the last download
|
||||
*
|
||||
* @var ?int
|
||||
* @var int
|
||||
*/
|
||||
private $status;
|
||||
|
||||
|
@ -43,6 +43,8 @@ class DownloadHelper {
|
|||
$this->downloaded = false;
|
||||
$this->l = $l;
|
||||
$this->headers = [];
|
||||
$this->status = 0;
|
||||
$this->content = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,6 +96,7 @@ class DownloadHelper {
|
|||
* 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 {
|
||||
|
@ -133,6 +136,7 @@ class DownloadHelper {
|
|||
* 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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -14,6 +14,6 @@ class SchemaConformityFilter extends AbstractJSONFilter {
|
|||
$changed |= $this->setJSONValue($json, '@context', 'http://schema.org');
|
||||
$changed |= $this->setJSONValue($json, '@type', 'Recipe');
|
||||
|
||||
return $changed;
|
||||
return (bool) $changed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ class UserFolderHelper {
|
|||
return $this->cache;
|
||||
}
|
||||
|
||||
private function getOrCreateFolder($path): Folder {
|
||||
private function getOrCreateFolder(string $path): Folder {
|
||||
try {
|
||||
$node = $this->root->get($path);
|
||||
} catch (NotFoundException $ex) {
|
||||
|
|
|
@ -226,7 +226,7 @@ class DbCacheService {
|
|||
|
||||
// private function
|
||||
|
||||
private function isDbEntryUpToDate($id) {
|
||||
private function isDbEntryUpToDate(int $id) {
|
||||
$dbEntry = $this->dbReceipeFiles[$id];
|
||||
$fileEntry = $this->jsonFiles[$id];
|
||||
|
||||
|
|
|
@ -105,8 +105,11 @@ class HtmlDownloadService {
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
|
|
|
@ -14,6 +14,7 @@ use OCA\Cookbook\Helper\Filter\JSONFilter;
|
|||
use OCA\Cookbook\Helper\ImageService\ImageSize;
|
||||
use OCA\Cookbook\Helper\UserConfigHelper;
|
||||
use OCA\Cookbook\Helper\UserFolderHelper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
@ -97,7 +98,7 @@ class RecipeService {
|
|||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return array|null
|
||||
* @return ?array
|
||||
*/
|
||||
public function getRecipeById(int $id) {
|
||||
$file = $this->getRecipeFileByFolderId($id);
|
||||
|
@ -113,10 +114,8 @@ class RecipeService {
|
|||
* Get a recipe's modification time by its folder id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecipeMTime(int $id) {
|
||||
public function getRecipeMTime(int $id): ?int {
|
||||
$file = $this->getRecipeFileByFolderId($id);
|
||||
|
||||
if (!$file) {
|
||||
|
@ -462,7 +461,7 @@ class RecipeService {
|
|||
* @param string $keywords Keywords/tags as a comma-separated string.
|
||||
*
|
||||
* @return array
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
* @throws DoesNotExistException
|
||||
*/
|
||||
public function getRecipesByKeywords($keywords): array {
|
||||
$recipes = $this->db->getRecipesByKeywords($keywords, $this->user_id);
|
||||
|
@ -473,11 +472,14 @@ class RecipeService {
|
|||
/**
|
||||
* Search for recipes by keywords
|
||||
*
|
||||
* @param $keywords_string
|
||||
* @param string $keywords_string
|
||||
*
|
||||
* @return array
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
*
|
||||
* @throws DoesNotExistException
|
||||
*
|
||||
*/
|
||||
public function findRecipesInSearchIndex($keywords_string): array {
|
||||
public function findRecipesInSearchIndex(string $keywords_string): array {
|
||||
$keywords_string = strtolower($keywords_string);
|
||||
$keywords_array = [];
|
||||
preg_match_all('/[^ ,]+/', $keywords_string, $keywords_array);
|
||||
|
@ -535,10 +537,8 @@ class RecipeService {
|
|||
* Get recipe file contents as an array
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parseRecipeFile($file) {
|
||||
public function parseRecipeFile($file): ?array {
|
||||
if (!$file) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -37,16 +37,6 @@
|
|||
<code>is_array($keywords)</code>
|
||||
</RedundantCondition>
|
||||
</file>
|
||||
<file src="lib/Helper/DownloadHelper.php">
|
||||
<InvalidNullableReturnType>
|
||||
<code>int</code>
|
||||
<code>string</code>
|
||||
</InvalidNullableReturnType>
|
||||
<NullableReturnStatement>
|
||||
<code><![CDATA[$this->content]]></code>
|
||||
<code><![CDATA[$this->status]]></code>
|
||||
</NullableReturnStatement>
|
||||
</file>
|
||||
<file src="lib/Helper/Filter/JSON/FixInstructionsFilter.php">
|
||||
<NamedArgumentNotAllowed>
|
||||
<code>$instructions</code>
|
||||
|
@ -60,12 +50,6 @@
|
|||
<InvalidOperand>
|
||||
<code><![CDATA[$this->setJSONValue($json, '@type', 'Recipe')]]></code>
|
||||
</InvalidOperand>
|
||||
<InvalidReturnStatement>
|
||||
<code>$changed</code>
|
||||
</InvalidReturnStatement>
|
||||
<InvalidReturnType>
|
||||
<code>bool</code>
|
||||
</InvalidReturnType>
|
||||
</file>
|
||||
<file src="lib/Helper/Filter/NormalizeRecipeFileFilter.php">
|
||||
<InvalidOperand>
|
||||
|
@ -127,10 +111,6 @@
|
|||
</UndefinedDocblockClass>
|
||||
</file>
|
||||
<file src="lib/Service/RecipeService.php">
|
||||
<InvalidNullableReturnType>
|
||||
<code>array</code>
|
||||
<code>int</code>
|
||||
</InvalidNullableReturnType>
|
||||
<MissingDependency>
|
||||
<code><![CDATA[$this->root]]></code>
|
||||
<code><![CDATA[$this->root]]></code>
|
||||
|
@ -138,11 +118,6 @@
|
|||
<code><![CDATA[$this->root]]></code>
|
||||
<code>IRootFolder</code>
|
||||
</MissingDependency>
|
||||
<NullableReturnStatement>
|
||||
<code>null</code>
|
||||
<code>null</code>
|
||||
<code>null</code>
|
||||
</NullableReturnStatement>
|
||||
<RedundantCondition>
|
||||
<code><![CDATA[!array_key_exists('dateCreated', $json) && method_exists($file, 'getCreationTime')]]></code>
|
||||
</RedundantCondition>
|
||||
|
|
Загрузка…
Ссылка в новой задаче