-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
Signed-off-by: Maxence Lange <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,11 +46,22 @@ class ConfigLexiconEntry implements IConfigLexiconEntry { | |
public function __construct( | ||
private readonly string $key, | ||
private readonly ConfigLexiconValueType $type, | ||
null|string|int|float|bool|array $default = null, | ||
string $definition = '', | ||
private readonly bool $lazy = false, | ||
private readonly bool $sensitive = false, | ||
private readonly bool $deprecated = false | ||
) { | ||
if ($default !== null) { | ||
$this->default = match ($type) { | ||
ConfigLexiconValueType::STRING => $this->convertFromString($default), | ||
Check failure on line 57 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidArgument
Check failure Code scanning / Psalm InvalidArgument Error
Argument 1 of OCP\ConfigLexicon\ConfigLexiconEntry::convertFromString expects string, but array<array-key, mixed>|scalar provided
Check failure on line 57 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysisInvalidArgument
|
||
ConfigLexiconValueType::INT => $this->convertFromInt($default), | ||
Check failure on line 58 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidArgument
Check failure Code scanning / Psalm InvalidArgument Error
Argument 1 of OCP\ConfigLexicon\ConfigLexiconEntry::convertFromInt expects int, but array<array-key, mixed>|scalar provided
Check failure on line 58 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysisInvalidArgument
|
||
ConfigLexiconValueType::FLOAT => $this->convertFromFloat($default), | ||
Check failure on line 59 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidArgument
Check failure Code scanning / Psalm InvalidArgument Error
Argument 1 of OCP\ConfigLexicon\ConfigLexiconEntry::convertFromFloat expects float, but array<array-key, mixed>|scalar provided
Check failure on line 59 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysisInvalidArgument
|
||
ConfigLexiconValueType::BOOL => $this->convertFromBool($default), | ||
Check failure on line 60 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidArgument
Check failure Code scanning / Psalm InvalidArgument Error
Argument 1 of OCP\ConfigLexicon\ConfigLexiconEntry::convertFromBool expects bool, but array<array-key, mixed>|scalar provided
Check failure on line 60 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysisInvalidArgument
|
||
ConfigLexiconValueType::ARRAY => $this->convertFromArray($default) | ||
}; | ||
} | ||
|
||
/** @psalm-suppress UndefinedClass */ | ||
if (\OC::$CLI) { // only store definition if ran from CLI | ||
$this->definition = $definition; | ||
|
@@ -79,68 +90,43 @@ public function getValueType(): ConfigLexiconValueType { | |
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @param string $default | ||
* | ||
* @return self | ||
* @since 30.0.0 | ||
* @return string | ||
*/ | ||
public function withDefaultString(string $default): self { | ||
$this->default = $default; | ||
return $this; | ||
private function convertFromString(string $default): string { | ||
Check failure on line 96 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return $default; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @param int $default | ||
* | ||
* @return self | ||
* @since 30.0.0 | ||
* @return string | ||
*/ | ||
public function withDefaultInt(int $default): self { | ||
$this->default = (string) $default; | ||
return $this; | ||
private function convertFromInt(int $default): string { | ||
Check failure on line 104 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return (string) $default; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @param float $default | ||
* | ||
* @return self | ||
* @since 30.0.0 | ||
* @return string | ||
*/ | ||
public function withDefaultFloat(float $default): self { | ||
$this->default = (string) $default; | ||
return $this; | ||
private function convertFromFloat(float $default): string { | ||
Check failure on line 112 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return (string) $default; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @param bool $default | ||
* | ||
* @return self | ||
* @since 30.0.0 | ||
* @return string | ||
*/ | ||
public function withDefaultBool(bool $default): self { | ||
$this->default = ($default) ? '1' : '0'; | ||
return $this; | ||
private function convertFromBool(bool $default): string { | ||
Check failure on line 120 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return ($default) ? '1' : '0'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @param array $default | ||
* | ||
* @return self | ||
* @since 30.0.0 | ||
* @return string | ||
*/ | ||
public function withDefaultArray(array $default): self { | ||
$this->default = json_encode($default); | ||
return $this; | ||
private function convertFromArray(array $default): string { | ||
Check failure on line 128 in lib/public/ConfigLexicon/ConfigLexiconEntry.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return json_encode($default); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Maxence Lange <[email protected]> | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 or later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCP\ConfigLexicon; | ||
|
||
/** | ||
* Listing of available value type for config lexicon | ||
* | ||
* @see IConfigLexicon | ||
* @since 30.0.0 | ||
*/ | ||
enum ConfigLexiconValueType: string { | ||
/** @since 30.0.0 */ | ||
case STRING = 'string'; | ||
/** @since 30.0.0 */ | ||
case INT = 'int'; | ||
/** @since 30.0.0 */ | ||
case FLOAT = 'float'; | ||
/** @since 30.0.0 */ | ||
case BOOL = 'bool'; | ||
/** @since 30.0.0 */ | ||
case ARRAY = 'array'; | ||
} |