| Total Complexity | 6 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | class SvgSanitizer |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @param string $sourcePath |
||
| 26 | * @param string|null $targetPath |
||
| 27 | * @throws \BadFunctionCallException |
||
| 28 | */ |
||
| 29 | public function sanitizeFile(string $sourcePath, string $targetPath = null): void |
||
| 30 | { |
||
| 31 | if ($targetPath === null) { |
||
| 32 | $targetPath = $sourcePath; |
||
| 33 | } |
||
| 34 | $svg = file_get_contents($sourcePath); |
||
| 35 | if (!is_string($svg)) { |
||
|
|
|||
| 36 | return; |
||
| 37 | } |
||
| 38 | $sanitizedSvg = $this->sanitizeContent($svg); |
||
| 39 | if ($sanitizedSvg !== $svg) { |
||
| 40 | file_put_contents($targetPath, $sanitizedSvg); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $svg |
||
| 46 | * |
||
| 47 | * @return string |
||
| 48 | * @throws \BadFunctionCallException |
||
| 49 | */ |
||
| 50 | public function sanitizeContent(string $svg): string |
||
| 55 | } |
||
| 56 | } |
||
| 57 |