Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Apr 1, 2024
1 parent 7aa55bd commit 1e0f0e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
1 change: 0 additions & 1 deletion moodle/Tests/Util/MoodleUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public function testGetMoodleComponent(
}
} elseif (array_key_exists('value', $return)) {
// Normal asserting result.
error_log("Getting component for file: {$file->getFilename()}: {$selfPath} => {$return['value']}");
$this->assertSame($return['value'], MoodleUtil::getMoodleComponent($file, $selfPath));
}

Expand Down
6 changes: 1 addition & 5 deletions moodle/Util/MoodleUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,13 @@ public static function getMoodleComponent(File $file, $selfPath = true): ?string
} else {
// Verify that we are able to find a valid moodle root.
if (!$moodleRoot = self::getMoodleRoot($file, $selfPath)) {
error_log("No Moodle root found");
return null;
}

// Load all components, associative array with keys as component and paths as values.
$components = self::calculateAllComponents($moodleRoot);
// Have been unable to load components, done.
if (empty($components)) {
error_log("No components found");
return null;
}
}
Expand All @@ -252,10 +250,8 @@ public static function getMoodleComponent(File $file, $selfPath = true): ?string
continue;
}

$componentPath = str_replace('\\', '/', $componentPath . DIRECTORY_SEPARATOR);
error_log("Checking {$componentPath} against {$filepath}");

// Look for component paths matching the file path.
$componentPath = str_replace('\\', '/', $componentPath . DIRECTORY_SEPARATOR);
if (strpos($filepath, $componentPath) === 0) {
// First match found should be the better one always. We are done.
return $component;
Expand Down

0 comments on commit 1e0f0e5

Please sign in to comment.