Skip to content

Commit cc06ef5

Browse files
committed
Some small fixtures for next phpstan level
1 parent bd2effb commit cc06ef5

File tree

11 files changed

+21
-29
lines changed

11 files changed

+21
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
![Static Badge](https://img.shields.io/badge/PHPUnit-tests%3A_171-lightgreen)
1111
![Static Badge](https://img.shields.io/badge/PHPUnit-asserts%3A_596-lightgreen)
1212
![Static Badge](https://img.shields.io/badge/PHPStan_6-OK-lightgreen)
13-
![Static Badge](https://img.shields.io/badge/PHPStan_7-16_errors-orange)
13+
![Static Badge](https://img.shields.io/badge/PHPStan_7|8-16_errors-orange)
1414

1515
**F**i**Q**ue**L**a is a powerful PHP library that brings SQL-inspired querying capabilities to structured data formats
1616
like **XML**, **CSV**, **JSON**, **YAML** and **NEON**. Designed for simplicity and modularity, it allows you to filter,
@@ -296,7 +296,7 @@ to load all data into memory. It may cause memory issues for large datasets. But
296296
- [ ] **Next file formats**: Add next file formats like [NDJson](https://github.com/ndjson/ndjson-spec) and [MessagePack](https://msgpack.org/)
297297
- [ ] **Documentation**: Create detailed guides and examples for advanced use cases.
298298
- [ ] **Add explain method**: Add method `explain()` for explaining query execution from actual query debugger and provide more complex information about query.
299-
- [ ] **PHPStan 7**: Fix all PHPStan 7 errors.
299+
- [ ] **PHPStan 8**: Fix all PHPStan 8 errors.
300300
- [ ] **Tests**: Increase test coverage.
301301
- [ ] **Optimize GROUP BY**: Optimize `GROUP BY` for more memory efficient data processing.
302302
- [ ] **Hashmap cache**: Add hashmap cache (Redis, Memcache) for more memory efficient data processing.

src/Enum/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private static function isNumeric(string $value): bool
116116
$value = preg_replace('/[ ,]/', '', $value);
117117

118118
// Replace comma with dot for unified decimal separator
119-
$value = str_replace(',', '.', $value);
119+
$value = str_replace(',', '.', $value ?? '');
120120

121121
return is_numeric($value);
122122
}

src/Functions/String/Base64Decode.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,4 @@ public function __invoke(array $item, array $resultItem): mixed
2020
)
2121
);
2222
}
23-
24-
public function getName(): string
25-
{
26-
return 'FROM_BASE64';
27-
}
2823
}

src/Functions/String/Base64Encode.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,4 @@ public function __invoke(array $item, array $resultItem): mixed
2020
)
2121
);
2222
}
23-
24-
public function getName(): string
25-
{
26-
return 'TO_BASE64';
27-
}
2823
}

src/Query/Debugger.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,12 @@ public static function echoSection(string $text, ?string $color = 'cyan'): void
220220
self::echoLine($colorCallback(self::echoBold(str_repeat('=', strlen($text)))), 0);
221221
}
222222

223-
public static function echoLineNameValue(string $name, mixed $value, int $beginCharRepeat = 1): void
224-
{
225-
self::echoLine(sprintf('%s: %s', self::echoBold($name), self::echoCyan($value)), $beginCharRepeat);
223+
public static function echoLineNameValue(
224+
string $name,
225+
string|bool|float|int|null $value,
226+
int $beginCharRepeat = 1
227+
): void {
228+
self::echoLine(sprintf('%s: %s', self::echoBold($name), self::echoCyan((string) $value)), $beginCharRepeat);
226229
}
227230

228231
public static function echoLine(string $text, int $beginCharRepeat = 1): void

src/Query/Provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function fromFile(string $path, ?Enum\Format $format = null): Inte
2929
public static function fromFileQuery(string $fileQuery): Interface\Query
3030
{
3131
$queryPath = new FileQuery($fileQuery);
32-
$stream = self::fromFile($queryPath->file, $queryPath->extension);
32+
$stream = self::fromFile($queryPath->file ?? '', $queryPath->extension);
3333
if ($queryPath->query === null) {
3434
return $stream;
3535
}

src/Sql/Sql.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function toQuery(): Interface\Query
4444
}
4545

4646
$fileQuery = new Query\FileQuery($this->nextToken());
47-
$stream = Stream\Provider::fromFile($fileQuery->file, $fileQuery->extension);
47+
$stream = Stream\Provider::fromFile($fileQuery->file ?? '', $fileQuery->extension);
4848
break;
4949
}
5050

@@ -175,7 +175,7 @@ private function isFunction(string $token): bool
175175

176176
private function getFunction(string $token): string
177177
{
178-
return preg_replace('/(\b(?!_)[A-Z0-9_]{2,}(?<!_))\(.*?\)/i', '$1', $token);
178+
return preg_replace('/(\b(?!_)[A-Z0-9_]{2,}(?<!_))\(.*?\)/i', '$1', $token) ?? '';
179179
}
180180

181181
/**

src/Stream/XmlProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private function itemToArray(\SimpleXMLElement $element): string|array
139139
// If the element has no children and attributes, return a simple value
140140
$value = trim((string) $element);
141141
if ($value !== '' && empty($result)) {
142-
return Enum\Type::matchByString($value);
142+
return Enum\Type::castValue($value, Enum\Type::STRING);
143143
}
144144

145145
// If the element has children or attributes but also a text value, add it as 'value'

src/Traits/Conditions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function endGroup(): Query
114114
throw new Exception\UnexpectedValueException('No group to end');
115115
}
116116

117-
$this->currentGroup = $this->currentGroup->getParent();
117+
$this->currentGroup = $this->currentGroup->getParent() ?? $this->whereConditions;
118118
return $this;
119119
}
120120

src/Traits/Helpers/StringOperations.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public function camelCaseToUpperSnakeCase(string $input): string
1212
}
1313

1414
// Add underscores before uppercase letters, unless at the start or after an underscore
15-
$snake = preg_replace('/(?<!^|_|[A-Z])([A-Z])/', '_$1', $input);
15+
$snake = preg_replace('/(?<!^|_|[A-Z])([A-Z])/', '_$1', $input) ?? '';
1616

1717
// Consolidate multiple underscores into one
18-
$snake = preg_replace('/_+/', '_', $snake);
18+
$snake = preg_replace('/_+/', '_', $snake) ?? '';
1919

2020
// Convert to uppercase and return the result
2121
return strtoupper($snake);
@@ -37,7 +37,7 @@ public function extractPlainText(string $input): string
3737
$cleaned = preg_replace([
3838
'/```[\s\S]*?```/m', // multi-line code blocks: ```code```
3939
'/`{1,2}(.*?)`{1,2}/', // single-line code: `inline code`
40-
], '', $input);
40+
], '', $input) ?? '';
4141

4242
// remove all HTML tags
4343
$cleaned = strip_tags($cleaned);
@@ -54,13 +54,13 @@ public function extractPlainText(string $input): string
5454
'/^\d+\.\s+(.*)$/m', // Ordered list: 1. item
5555
'/\|.*?\|/m', // Table rows: | col1 | col2 |
5656
'/-{3,}/', // Horizontal rules: ---
57-
], '$1', $cleaned);
57+
], '$1', $cleaned) ?? '';
5858

5959
// allowed characters: letters, numbers, spaces, common punctuation
60-
$cleaned = preg_replace('/[^\p{L}\p{N}\s.,!?;:\'\"-]/u', '', $cleaned);
60+
$cleaned = preg_replace('/[^\p{L}\p{N}\s.,!?;:\'\"-]/u', '', $cleaned) ?? '';
6161

6262
// normalize multiple spaces to one
63-
$cleaned = preg_replace('/\s+/', ' ', $cleaned);
63+
$cleaned = preg_replace('/\s+/', ' ', $cleaned) ?? '';
6464
return strtolower(trim($cleaned));
6565
}
6666
}

0 commit comments

Comments
 (0)