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

Enhance input validation in ShieldsIo class #215

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions src/ShieldsIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,32 @@
return $input;
}

public function generateBadgeUrl($label, $content, $color, $style, $labelColor, $logo)
private function addComponent($component, &$badge)

Check warning

Code scanning / Phpcs (reported by Codacy)

Missing doc comment for function addComponent() Warning

Missing doc comment for function addComponent()
{
$badge = array();

if (isset($label) && !empty($label)) {
$label = $this->encodeShieldsIoParameters($label);
$badge[] = $label;
}

if (isset($content) && !empty($content)) {
$content = $this->encodeShieldsIoParameters($content);
$badge[] = $content;
}

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

$queryString = array();
if (isset($style) && !empty($style)) {
$queryString["style"] = $style;
if (isset($component) && (empty($component) === false || $component === 0)) {

Check warning

Code scanning / Phpcs (reported by Codacy)

Implicit true comparisons prohibited; use === TRUE instead Warning

Implicit true comparisons prohibited; use === TRUE instead
$value = $this->encodeShieldsIoParameters($component);
$badge[] = $value;
}
}

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected //end addComponent() Warning

Expected //end addComponent()

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected 1 blank line before closing function brace; 0 found Warning

Expected 1 blank line before closing function brace; 0 found

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected 2 blank lines after function; 1 found Warning

Expected 2 blank lines after function; 1 found

if (isset($labelColor) && !empty($labelColor)) {
$queryString["labelColor"] = $labelColor;
private function addQueryString($component, $key, &$queryString)

Check warning

Code scanning / Phpcs (reported by Codacy)

Missing doc comment for function addQueryString() Warning

Missing doc comment for function addQueryString()
{
if (isset($component) && empty($component) === false) {

Check warning

Code scanning / Phpcs (reported by Codacy)

Implicit true comparisons prohibited; use === TRUE instead Warning

Implicit true comparisons prohibited; use === TRUE instead
$queryString[$key] = $component;
}
}

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected 1 blank line before closing function brace; 0 found Warning

Expected 1 blank line before closing function brace; 0 found

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected 2 blank lines after function; 1 found Warning

Expected 2 blank lines after function; 1 found

Check warning

Code scanning / Phpcs (reported by Codacy)

Expected //end addQueryString() Warning

Expected //end addQueryString()

if (isset($logo) && !empty($logo)) {
$queryString["logo"] = $logo;
}
public function generateBadgeUrl($label, $content, $color, $style, $labelColor, $logo)

Check warning

Code scanning / Phpcs (reported by Codacy)

Missing doc comment for function generateBadgeUrl() Warning

Missing doc comment for function generateBadgeUrl()
{
$badge = [];
$this->addComponent($label, $badge);
$this->addComponent($content, $badge);
$this->addComponent($color, $badge);

$queryString = [];
$this->addQueryString($style, "style", $queryString);
$this->addQueryString($labelColor, "labelColor", $queryString);
$this->addQueryString($logo, "logo", $queryString);

return "https://img.shields.io/badge/" . implode("-", $badge) . "?" . http_build_query($queryString);
}
Expand Down
Loading