Skip to content

Commit

Permalink
Revert "Downgrade code to be PHP 7.0 compliant."
Browse files Browse the repository at this point in the history
This reverts commit edb2b85.

This partially reverts some code that was done long ago to
keep compatibility with PHP 7.0.

As far as moodle-cs now only supports PHP 7.4 and up, we
can move back to use return types.

Fixes moodlehq#107
  • Loading branch information
stronk7 committed Feb 16, 2024
1 parent da7aa56 commit 0d48d28
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions moodle/Util/MoodleUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected static function loadCoreComponent(string $moodleRoot): bool {
* @param string $moodleRoot Full path to a valid moodle.root
* @return array Associative array of components as keys and paths as values or null if not found.
*/
protected static function calculateAllComponents(string $moodleRoot) {
protected static function calculateAllComponents(string $moodleRoot): ?array {
// If we have calculated the components already, straight return them.
if (!empty(self::$moodleComponents)) {
return self::$moodleComponents;
Expand Down Expand Up @@ -205,7 +205,7 @@ protected static function calculateAllComponents(string $moodleRoot) {
*
* @return string|null a valid moodle component for the file or null if not found.
*/
public static function getMoodleComponent(File $file, $selfPath = true) {
public static function getMoodleComponent(File $file, $selfPath = true): ?string {
if (defined('PHPUNIT_TEST') && PHPUNIT_TEST && !empty(self::$mockedComponentMappings)) {
$components = self::$mockedComponentMappings; // @codeCoverageIgnore
} else {
Expand Down Expand Up @@ -252,7 +252,7 @@ public static function getMoodleComponent(File $file, $selfPath = true) {
*
* @return int|null the numeric branch in moodle root version.php or null if not found
*/
public static function getMoodleBranch(File $file = null, bool $selfPath = true) {
public static function getMoodleBranch(?File $file = null, bool $selfPath = true): ?int {

// Return already calculated value if available.
if (self::$moodleBranch !== false) {
Expand All @@ -270,7 +270,7 @@ public static function getMoodleBranch(File $file = null, bool $selfPath = true)
throw new DeepExitException(
"ERROR: Incorrect 'moodleBranch' config/runtime option. Value must be 4 digit max.: '$branch'", 3);
}
self::$moodleBranch = (int)$branch;
self::$moodleBranch = $branch;
return self::$moodleBranch;
}

Expand All @@ -288,7 +288,7 @@ public static function getMoodleBranch(File $file = null, bool $selfPath = true)
// Find the $branch value.
if ($valueToken = $versionFile->findNext(T_CONSTANT_ENCAPSED_STRING, $varToken)) {
$branch = trim($versionFile->getTokens()[$valueToken]['content'], "\"'");
self::$moodleBranch = (int)$branch;
self::$moodleBranch = $branch;
return self::$moodleBranch;
}
}
Expand All @@ -313,7 +313,7 @@ public static function getMoodleBranch(File $file = null, bool $selfPath = true)
*
* @return string|null the full path to moodle root or null if not found.
*/
public static function getMoodleRoot(File $file = null, bool $selfPath = true) {
public static function getMoodleRoot(?File $file = null, bool $selfPath = true): ?string {
// Return already calculated value if available.
if (self::$moodleRoot !== false) {
return self::$moodleRoot;
Expand Down

0 comments on commit 0d48d28

Please sign in to comment.