FOF30\Update\Collection::filterListByPlatform PHP Method

filterListByPlatform() private method

Filters a list of updates, returning only those available for the specified platform version $jVersion
private filterListByPlatform ( array $updates, string $jVersion = null ) : array | null
$updates array An array containing update definitions (categories or extensions)
$jVersion string Joomla! version to fetch updates for, or null to use JVERSION
return array | null The update definition that is compatible, or null if none is compatible
    private function filterListByPlatform($updates, $jVersion = null)
    {
        // Get the target platform
        if (is_null($jVersion)) {
            $jVersion = JVERSION;
        }
        $versionParts = explode('.', $jVersion, 4);
        $platformVersionMajor = $versionParts[0];
        $platformVersionMinor = count($versionParts) > 1 ? $platformVersionMajor . '.' . $versionParts[1] : $platformVersionMajor;
        $platformVersionNormal = count($versionParts) > 2 ? $platformVersionMinor . '.' . $versionParts[2] : $platformVersionMinor;
        $platformVersionFull = count($versionParts) > 3 ? $platformVersionNormal . '.' . $versionParts[3] : $platformVersionNormal;
        $pickedExtension = null;
        $pickedSpecificity = -1;
        foreach ($updates as $update) {
            // Test the target platform
            $targetPlatform = (string) $update['targetplatformversion'];
            if ($targetPlatform === $platformVersionFull) {
                $pickedExtension = $update;
                $pickedSpecificity = 4;
            } elseif ($targetPlatform === $platformVersionNormal && $pickedSpecificity <= 3) {
                $pickedExtension = $update;
                $pickedSpecificity = 3;
            } elseif ($targetPlatform === $platformVersionMinor && $pickedSpecificity <= 2) {
                $pickedExtension = $update;
                $pickedSpecificity = 2;
            } elseif ($targetPlatform === $platformVersionMajor && $pickedSpecificity <= 1) {
                $pickedExtension = $update;
                $pickedSpecificity = 1;
            }
        }
        return $pickedExtension;
    }