Skip to content

Commit a85bb99

Browse files
authored
Merge pull request #8 from aporat/analysis-MPvEyj
Apply fixes from StyleCI
2 parents 7329bfe + 0e482a7 commit a85bb99

14 files changed

+78
-64
lines changed

src/Contracts/Filter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ interface Filter
77
/**
88
* Apply the filter to the given value.
99
*
10-
* @param mixed $value The value to filter
11-
* @param array<string, mixed> $options Optional configuration for the filter
10+
* @param mixed $value The value to filter
11+
* @param array<string, mixed> $options Optional configuration for the filter
12+
*
1213
* @return mixed The filtered value
1314
*/
1415
public function apply(mixed $value, array $options = []): mixed;

src/FilterVar.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FilterVar
1919
/**
2020
* Create a new FilterVar instance.
2121
*
22-
* @param array<string, mixed> $config Configuration array, optionally containing 'custom_filters'
22+
* @param array<string, mixed> $config Configuration array, optionally containing 'custom_filters'
2323
*/
2424
public function __construct(array $config = [])
2525
{
@@ -35,47 +35,49 @@ protected function getDefaultFilters(): array
3535
{
3636
return [
3737
'Capitalize' => Filters\Capitalize::class,
38-
'Cast' => Filters\Cast::class,
39-
'Escape' => Filters\EscapeHTML::class,
38+
'Cast' => Filters\Cast::class,
39+
'Escape' => Filters\EscapeHTML::class,
4040
'FormatDate' => Filters\FormatDate::class,
41-
'Lowercase' => Filters\Lowercase::class,
42-
'Uppercase' => Filters\Uppercase::class,
43-
'Trim' => Filters\Trim::class,
44-
'StripTags' => Filters\StripTags::class,
45-
'Digit' => Filters\Digit::class,
46-
'FilterIf' => Filters\FilterIf::class,
41+
'Lowercase' => Filters\Lowercase::class,
42+
'Uppercase' => Filters\Uppercase::class,
43+
'Trim' => Filters\Trim::class,
44+
'StripTags' => Filters\StripTags::class,
45+
'Digit' => Filters\Digit::class,
46+
'FilterIf' => Filters\FilterIf::class,
4747
];
4848
}
4949

5050
/**
5151
* Apply a single filter to a value.
5252
*
53-
* @param array{0: string, 1?: array<string, mixed>} $rule Filter name and optional options
54-
* @param mixed $value The value to filter
55-
* @return mixed The filtered value
53+
* @param array{0: string, 1?: array<string, mixed>} $rule Filter name and optional options
54+
* @param mixed $value The value to filter
5655
*
5756
* @throws InvalidArgumentException If the filter name is not registered
57+
*
58+
* @return mixed The filtered value
5859
*/
5960
protected function applyFilter(array $rule, mixed $value): mixed
6061
{
6162
$name = $rule[0];
6263
$options = $rule[1] ?? [];
6364

64-
if (! isset($this->filters[$name])) {
65+
if (!isset($this->filters[$name])) {
6566
throw new InvalidArgumentException("No filter registered for the name '$name'.");
6667
}
6768

6869
/** @var Filter $filter */
69-
$filter = new $this->filters[$name];
70+
$filter = new $this->filters[$name]();
7071

7172
return $filter->apply($value, $options);
7273
}
7374

7475
/**
7576
* Apply a chain of filters to a value based on a rule string.
7677
*
77-
* @param string $ruleString Filter rules (e.g., "trim|uppercase")
78-
* @param mixed $value The value to filter
78+
* @param string $ruleString Filter rules (e.g., "trim|uppercase")
79+
* @param mixed $value The value to filter
80+
*
7981
* @return mixed The filtered value
8082
*/
8183
public function filterValue(string $ruleString, mixed $value): mixed

src/Filters/Capitalize.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ class Capitalize implements Filter
1212
* This filter converts the input to lowercase first, then applies title case
1313
* capitalization using multibyte-safe functions. Non-string inputs are returned unchanged.
1414
*
15-
* @param mixed $value The value to capitalize
16-
* @param array<string, mixed> $options Optional filter options (currently unused)
15+
* @param mixed $value The value to capitalize
16+
* @param array<string, mixed> $options Optional filter options (currently unused)
17+
*
1718
* @return mixed The capitalized string or original value if not a string
1819
*/
1920
public function apply(mixed $value, array $options = []): mixed
2021
{
21-
if (! is_string($value)) {
22+
if (!is_string($value)) {
2223
return $value;
2324
}
2425

src/Filters/Cast.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ class Cast implements Filter
1515
* Supported types: int, integer, float, real, double, string, bool, boolean, object,
1616
* array, collection. If an unsupported type is provided, an exception is thrown.
1717
*
18-
* @param mixed $value The value to cast
19-
* @param array $options Options array where the first element specifies the target type
20-
* @return mixed The value cast to the specified type
18+
* @param mixed $value The value to cast
19+
* @param array $options Options array where the first element specifies the target type
2120
*
2221
* @throws InvalidArgumentException If the type is invalid or not provided
22+
*
23+
* @return mixed The value cast to the specified type
2324
*/
2425
public function apply(mixed $value, array $options = []): mixed
2526
{

src/Filters/Digit.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class Digit implements Filter
1414
* inputs are implicitly converted to strings by preg_replace, and an empty string
1515
* is returned if no digits are present or if the input is null.
1616
*
17-
* @param mixed $value The value to filter (typically a string)
18-
* @param array<string, mixed> $options Optional filter options (currently unused)
17+
* @param mixed $value The value to filter (typically a string)
18+
* @param array<string, mixed> $options Optional filter options (currently unused)
19+
*
1920
* @return string The filtered value containing only digits
2021
*/
2122
public function apply(mixed $value, array $options = []): string

src/Filters/EscapeHTML.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class EscapeHTML implements Filter
1313
* using htmlspecialchars. If the input is a string, it’s escaped; non-string inputs
1414
* are returned unchanged.
1515
*
16-
* @param mixed $value The value to escape (typically a string)
17-
* @param array<string, mixed> $options Optional filter options (currently unused)
16+
* @param mixed $value The value to escape (typically a string)
17+
* @param array<string, mixed> $options Optional filter options (currently unused)
18+
*
1819
* @return mixed The escaped string or original value if not a string
1920
*/
2021
public function apply(mixed $value, array $options = []): mixed

src/Filters/FilterIf.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class FilterIf implements Filter
1515
*
1616
* Example: If $value = ['status' => 'active'], $options = ['status', 'active'], returns true.
1717
*
18-
* @param mixed $value The input value (expected to be an array)
19-
* @param array<int, mixed> $options Array where $options[0] is the key and $options[1] is the expected value
18+
* @param mixed $value The input value (expected to be an array)
19+
* @param array<int, mixed> $options Array where $options[0] is the key and $options[1] is the expected value
20+
*
2021
* @return mixed Returns bool (true if condition matches, false otherwise)
2122
*/
2223
public function apply(mixed $value, array $options = []): mixed

src/Filters/FormatDate.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ class FormatDate implements Filter
1919
*
2020
* Example: $value = "2023-01-15", $options = ["Y-m-d", "d/m/Y"] => "15/01/2023"
2121
*
22-
* @param mixed $value The date string to reformat
23-
* @param array<int, string> $options Array with [0 => current format, 1 => target format]
24-
* @return mixed The reformatted date string or original value if empty
22+
* @param mixed $value The date string to reformat
23+
* @param array<int, string> $options Array with [0 => current format, 1 => target format]
2524
*
2625
* @throws InvalidArgumentException If $options doesn’t contain exactly two formats
27-
* @throws InvalidFormatException If the date cannot be parsed
26+
* @throws InvalidFormatException If the date cannot be parsed
27+
*
28+
* @return mixed The reformatted date string or original value if empty
2829
*/
2930
public function apply(mixed $value, array $options = []): mixed
3031
{
31-
if (! $value) {
32+
if (!$value) {
3233
return $value;
3334
}
3435
if (count($options) != 2) {

src/Filters/Lowercase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class Lowercase implements Filter
1313
* mb_strtolower with UTF-8 encoding. If the input is not a string, it is returned
1414
* unchanged.
1515
*
16-
* @param mixed $value The value to convert (typically a string)
17-
* @param array<string, mixed> $options Optional filter options (currently unused)
16+
* @param mixed $value The value to convert (typically a string)
17+
* @param array<string, mixed> $options Optional filter options (currently unused)
18+
*
1819
* @return mixed The lowercase string or original value if not a string
1920
*/
2021
public function apply(mixed $value, array $options = []): mixed

src/Filters/StripTags.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class StripTags implements Filter
1212
* This filter uses strip_tags to eliminate all HTML and PHP tags from the input string,
1313
* leaving only plain text. If the input is not a string, it is returned unchanged.
1414
*
15-
* @param mixed $value The value to process (typically a string)
16-
* @param array<string, mixed> $options Optional filter options (currently unused)
15+
* @param mixed $value The value to process (typically a string)
16+
* @param array<string, mixed> $options Optional filter options (currently unused)
17+
*
1718
* @return mixed The tag-stripped string or original value if not a string
1819
*/
1920
public function apply(mixed $value, array $options = []): mixed

0 commit comments

Comments
 (0)