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

[FEATURE] Add ShieldsIo class #167

Closed
guibranco opened this issue Jul 4, 2024 · 1 comment · Fixed by #189
Closed

[FEATURE] Add ShieldsIo class #167

guibranco opened this issue Jul 4, 2024 · 1 comment · Fixed by #189
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers hacktoberfest HACKTOBERFEST acceptable label help wanted Extra attention is needed 🛠 WIP Work In Progress

Comments

@guibranco
Copy link
Owner

Description

Add a class named ShieldsIo with the following methods:

  • generateBadgeUrl

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!)

  • The str_replace calls could be grouped in a single method and reduce the code cyclomatic complexity, reducing operations inside this method.
  • We can handle other (optional) parameters to generate the badge (refer to shields.io docs, but this is not a current requirement).
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

@guibranco guibranco added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers hacktoberfest HACKTOBERFEST acceptable label labels Jul 4, 2024
Copy link
Contributor

gitauto-ai bot commented Jul 4, 2024

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.

@gstraccini gstraccini bot added the 🛠 WIP Work In Progress label Jul 22, 2024
@guibranco guibranco linked a pull request Jul 22, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers hacktoberfest HACKTOBERFEST acceptable label help wanted Extra attention is needed 🛠 WIP Work In Progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant