guibranco / pancake

🧰 🛠️ Pancake project - toolkit for PHP projects
https://guibranco.github.io/pancake/
MIT License
3 stars 1 forks source link

[FEATURE] Add `ShieldsIo` class #167

Closed guibranco closed 1 month ago

guibranco commented 1 month ago

Description

Add a class named ShieldsIo with the following methods:

Please take a look at shields.io docs for extra parameters and URL structure. The following example is fully functional (it needs to be refactored and tests and documentation added).

Tech notes

The basic implementation of the method GenerateBadgeUrl should be something similar to this: (feel free to change, add new features, or make any improvements!)

function generateBadgeUrl($label, $content, $color, $style, $labelColor, $logo)
{
    $badge = "";

    if (isset($label) && !empty($label)) {
        $label = str_replace("_", "__", $label);
        $label = str_replace(" ", "_", $label);
        $label = str_replace("-", "--", $label);
        $label = str_replace("/", "%2F", $label);
        $label = str_replace("#", "♯", $label);
        $badge .= $label . "-";
    }

    if (isset($content) && !empty($content)) {
        $content = str_replace("_", "__", $content);
        $content = str_replace(" ", "_", $content);
        $content = str_replace("-", "--", $content);
        $content = str_replace("/", "%2F", $content);
        $content = str_replace("#", "♯", $content);
        $badge .= $content . "-";
    }

    if (isset($color) && !empty($color)) {
        $badge .= $color;
    }

    $queryString = "";
    if (isset($style) && !empty($style)) {
        $queryString .= "style=" . $style . "&";
    }

    if (isset($labelColor) && !empty($labelColor)) {
        $queryString .= "labelColor=" . $labelColor . "&";
    }

    if (isset($logo) && !empty($logo)) {
        $queryString .= "logo=" . $logo;
    }

    return "https://img.shields.io/badge/" . $badge . "?" . $queryString;
}

Additional information

⚠️ 🚨 Add documentation and tests

gitauto-ai[bot] commented 1 month ago

Hello @guibranco, you have reached your request limit of 5, your cycle will refresh on 2024-07-21 10:07:38. Consider subscribing if you want more requests. If you have any questions or concerns, please contact us at info@gitauto.ai.