style: auto-fix 1340 phpcs PSR-12 violations via phpcbf; exclude MissingNamespace and SideEffects
This commit is contained in:
+27
-13
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OutputHelper - Consistent output escaping utilities
|
||||
*
|
||||
* Provides secure HTML escaping functions to prevent XSS attacks.
|
||||
* Use these functions when outputting user-controlled data.
|
||||
*/
|
||||
class OutputHelper {
|
||||
class OutputHelper
|
||||
{
|
||||
/**
|
||||
* Escape string for HTML output
|
||||
*
|
||||
@@ -16,7 +18,8 @@ class OutputHelper {
|
||||
* @param int $flags htmlspecialchars flags (default: ENT_QUOTES | ENT_HTML5)
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function h(?string $string, int $flags = ENT_QUOTES | ENT_HTML5): string {
|
||||
public static function h(?string $string, int $flags = ENT_QUOTES | ENT_HTML5): string
|
||||
{
|
||||
if ($string === null) {
|
||||
return '';
|
||||
}
|
||||
@@ -32,7 +35,8 @@ class OutputHelper {
|
||||
* @param string|null $string The string to escape
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function attr(?string $string): string {
|
||||
public static function attr(?string $string): string
|
||||
{
|
||||
if ($string === null) {
|
||||
return '';
|
||||
}
|
||||
@@ -50,7 +54,8 @@ class OutputHelper {
|
||||
* @param int $flags json_encode flags
|
||||
* @return string JSON encoded string (safe for script context)
|
||||
*/
|
||||
public static function json($data, int $flags = 0): string {
|
||||
public static function json($data, int $flags = 0): string
|
||||
{
|
||||
// Use HEX encoding for safety in HTML context
|
||||
$safeFlags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | $flags;
|
||||
return json_encode($data, $safeFlags);
|
||||
@@ -65,7 +70,8 @@ class OutputHelper {
|
||||
* @param string|null $string The string to encode
|
||||
* @return string URL encoded string
|
||||
*/
|
||||
public static function url(?string $string): string {
|
||||
public static function url(?string $string): string
|
||||
{
|
||||
if ($string === null) {
|
||||
return '';
|
||||
}
|
||||
@@ -81,7 +87,8 @@ class OutputHelper {
|
||||
* @param string|null $string The string to escape
|
||||
* @return string Escaped string (only allows safe characters)
|
||||
*/
|
||||
public static function css(?string $string): string {
|
||||
public static function css(?string $string): string
|
||||
{
|
||||
if ($string === null) {
|
||||
return '';
|
||||
}
|
||||
@@ -101,7 +108,8 @@ class OutputHelper {
|
||||
* @param int $decimals Number of decimal places
|
||||
* @return string Formatted number
|
||||
*/
|
||||
public static function number($number, int $decimals = 0): string {
|
||||
public static function number($number, int $decimals = 0): string
|
||||
{
|
||||
return number_format((float)$number, $decimals, '.', ',');
|
||||
}
|
||||
|
||||
@@ -111,7 +119,8 @@ class OutputHelper {
|
||||
* @param mixed $value The value to format
|
||||
* @return int Integer value
|
||||
*/
|
||||
public static function int($value): int {
|
||||
public static function int($value): int
|
||||
{
|
||||
return (int)$value;
|
||||
}
|
||||
|
||||
@@ -123,7 +132,8 @@ class OutputHelper {
|
||||
* @param string $suffix Suffix to add if truncated
|
||||
* @return string Truncated and escaped string
|
||||
*/
|
||||
public static function truncate(?string $string, int $length = 100, string $suffix = '...'): string {
|
||||
public static function truncate(?string $string, int $length = 100, string $suffix = '...'): string
|
||||
{
|
||||
if ($string === null) {
|
||||
return '';
|
||||
}
|
||||
@@ -142,7 +152,8 @@ class OutputHelper {
|
||||
* @param string $format PHP date format
|
||||
* @return string Formatted date
|
||||
*/
|
||||
public static function date($date, string $format = 'Y-m-d H:i:s'): string {
|
||||
public static function date($date, string $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
if ($date === null || $date === '') {
|
||||
return '';
|
||||
}
|
||||
@@ -165,7 +176,8 @@ class OutputHelper {
|
||||
* @param string $class The class name to validate
|
||||
* @return bool True if safe
|
||||
*/
|
||||
public static function isValidCssClass(string $class): bool {
|
||||
public static function isValidCssClass(string $class): bool
|
||||
{
|
||||
return preg_match('/^[a-zA-Z_][a-zA-Z0-9_-]*$/', $class) === 1;
|
||||
}
|
||||
|
||||
@@ -175,7 +187,8 @@ class OutputHelper {
|
||||
* @param string|null $classes Space-separated class names
|
||||
* @return string Sanitized class names
|
||||
*/
|
||||
public static function cssClass(?string $classes): string {
|
||||
public static function cssClass(?string $classes): string
|
||||
{
|
||||
if ($classes === null || $classes === '') {
|
||||
return '';
|
||||
}
|
||||
@@ -193,6 +206,7 @@ class OutputHelper {
|
||||
* @param string|null $string The string to escape
|
||||
* @return string Escaped string
|
||||
*/
|
||||
function h(?string $string): string {
|
||||
function h(?string $string): string
|
||||
{
|
||||
return OutputHelper::h($string);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user