Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unnecessary parameter #2495

Merged
merged 3 commits into from
Aug 16, 2024
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
50 changes: 10 additions & 40 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class taoQtiTest_actions_RestQtiTests extends AbstractRestQti
*/
private const OVERWRITE_TEST = 'overwriteTest';

private const SUBCLASS_LABEL = 'subclassLabel';
private const OVERWRITE_TEST_URI = 'overwriteTestUri';
private const PACKAGE_LABEL = 'packageLabel';

Expand Down Expand Up @@ -136,17 +135,16 @@ public function import()
}
}

protected function getItemClassUri(): ?string
/**
* @throws common_exception_RestApi
*/
protected function getItemClassUri(): string
gabrielfs7 marked this conversation as resolved.
Show resolved Hide resolved
{
$itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI);
$subclassLabel = $this->getSubclassLabel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: a52922f

Thanks!

$itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI, TaoOntology::CLASS_URI_ITEM);
$itemClass = $this->getClass($itemClassUri);

if ($subclassLabel) {
foreach ($this->getClass($itemClassUri)->getSubClasses() as $subclass) {
if ($subclass->getLabel() === $subclassLabel) {
$itemClassUri = $subclass->getUri();
}
}
if (!$itemClass->exists()) {
throw new common_exception_RestApi('Class does not exist. Please use valid ' . self::ITEM_CLASS_URI);
}

return $itemClassUri;
Expand All @@ -164,7 +162,7 @@ protected function isOverwriteTest(): bool
}

if (!in_array($isOverwriteTest, ['true', 'false'])) {
throw new \common_exception_RestApi(
throw new common_exception_RestApi(
'isOverwriteTest parameter should be boolean (true or false).'
);
}
Expand Down Expand Up @@ -321,23 +319,6 @@ private function getUploadedPackageData()
return $fileData;
}

/**
* @return string|null
* @throws common_exception_RestApi
*/
private function getSubclassLabel(): ?string
{
$subclassLabel = $this->getPostParameter(self::SUBCLASS_LABEL);

if ($subclassLabel !== null && !is_string($subclassLabel)) {
throw new common_exception_RestApi(
sprintf('%s parameter should be string', self::SUBCLASS_LABEL)
);
}

return $subclassLabel;
}

/**
* @return string|null
* @throws common_exception_RestApi
Expand Down Expand Up @@ -379,18 +360,7 @@ private function getPackageLabel(): ?string
*/
private function getTestClass(): core_kernel_classes_Class
{
$testClass = $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
$subclassLabel = $this->getSubclassLabel();

if ($subclassLabel) {
foreach ($testClass->getSubClasses() as $subClass) {
if ($subClass->getLabel() === $subclassLabel) {
$testClass = $subClass;
}
}
}

return $testClass;
return $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion models/classes/tasks/ImportQtiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __invoke($params)
$params[self::PARAM_ITEM_MUST_EXIST] ?? false,
$params[self::PARAM_ITEM_MUST_BE_OVERWRITTEN] ?? false,
$params[self::PARAM_OVERWRITE_TEST] ?? false,
$params[self::PARAM_ITEM_CLASS_URI] ?? false,
$params[self::PARAM_ITEM_CLASS_URI] ?? null,
$params[self::PARAM_OVERWRITE_TEST_URI] ?? null,
$params[self::PARAM_PACKAGE_LABEL] ?? null,
);
Expand Down
Loading