Skip to content

Commit

Permalink
Enhance ShieldsIo class with cache duration feature +semVer: minor (#221
Browse files Browse the repository at this point in the history
)

* Update ShieldsIo.php +semVer: minor

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 8957330 according to the output
from PHP CS Fixer.

Details: #221

* Delete .github/pull_request_template.md

* Update ShieldsIoTest.php

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in b649a6e according to the output
from PHP CS Fixer.

Details: #221

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
guibranco and deepsource-autofix[bot] committed Sep 19, 2024
1 parent 7cfdebe commit 4fae799
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
27 changes: 0 additions & 27 deletions .github/pull_request_template.md

This file was deleted.

8 changes: 8 additions & 0 deletions src/ShieldsIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

class ShieldsIo
{
private $cacheSeconds;

public function __construct($cacheSeconds = 3600)
{
$this->cacheSeconds = $cacheSeconds;
}

private function encodeShieldsIoParameters($input)
{
$input = str_replace("_", "__", $input);
Expand Down Expand Up @@ -42,6 +49,7 @@ public function generateBadgeUrl($label, $content, $color, $style, $labelColor,
$this->addQueryString($style, "style", $queryString);
$this->addQueryString($labelColor, "labelColor", $queryString);
$this->addQueryString($logo, "logo", $queryString);
$this->addQueryString($this->cacheSeconds, "cacheSeconds", $queryString);

return "https://img.shields.io/badge/" . implode("-", $badge) . "?" . http_build_query($queryString);
}
Expand Down
27 changes: 17 additions & 10 deletions tests/ShieldsIoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,76 @@ public function testCanGenerateBadgeUrl(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithCustomCacheSeconds(): void
{
$shieldsIo = new ShieldsIo(7200);
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&labelColor=labelColor&logo=logo&cacheSeconds=7200', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutLabel(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('', 'content', 'color', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/content-color?style=style&labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/content-color?style=style&labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutContent(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', '', 'color', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-color?style=style&labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-color?style=style&labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutColor(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', '', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content?style=style&labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content?style=style&labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutStyle(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', '', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content-color?labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content-color?labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutLabelColor(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', 'style', '', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutLogo(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', 'style', 'labelColor', '');
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&labelColor=labelColor', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&labelColor=labelColor&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutLabelAndContent(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('', '', 'color', 'style', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/color?style=style&labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/color?style=style&labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutColorAndStyle(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', '', '', 'labelColor', 'logo');
$this->assertEquals('https://img.shields.io/badge/label-content?labelColor=labelColor&logo=logo', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content?labelColor=labelColor&logo=logo&cacheSeconds=3600', $badgeUrl);
}

public function testCanGenerateBadgeUrlWithoutLabelColorAndLogo(): void
{
$shieldsIo = new ShieldsIo();
$badgeUrl = $shieldsIo->generateBadgeUrl('label', 'content', 'color', 'style', '', '');
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style', $badgeUrl);
$this->assertEquals('https://img.shields.io/badge/label-content-color?style=style&cacheSeconds=3600', $badgeUrl);
}
}

0 comments on commit 4fae799

Please sign in to comment.