1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace AOE\Crawler\Backend\Helper; |
||||
6 | |||||
7 | /* |
||||
8 | * (c) 2020 AOE GmbH <[email protected]> |
||||
9 | * |
||||
10 | * This file is part of the TYPO3 Crawler Extension. |
||||
11 | * |
||||
12 | * It is free software; you can redistribute it and/or modify it under |
||||
13 | * the terms of the GNU General Public License, either version 2 |
||||
14 | * of the License, or any later version. |
||||
15 | * |
||||
16 | * For the full copyright and license information, please read the |
||||
17 | * LICENSE.txt file that was distributed with this source code. |
||||
18 | * |
||||
19 | * The TYPO3 project - inspiring people to share! |
||||
20 | */ |
||||
21 | |||||
22 | use AOE\Crawler\Converter\JsonCompatibilityConverter; |
||||
23 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
24 | |||||
25 | /** |
||||
26 | * @internal since v9.2.5 |
||||
27 | */ |
||||
28 | class ResultHandler |
||||
29 | { |
||||
30 | /** |
||||
31 | * Extract the log information from the current row and retrieve it as formatted string. |
||||
32 | * |
||||
33 | * @param array $resultRow |
||||
34 | * @return string |
||||
35 | */ |
||||
36 | 6 | public static function getResultLog($resultRow) |
|||
37 | { |
||||
38 | 6 | $content = ''; |
|||
39 | 6 | if (is_array($resultRow) && array_key_exists('result_data', $resultRow)) { |
|||
40 | 5 | $requestContent = self::getJsonCompatibilityConverter()->convert($resultRow['result_data']) ?: []; |
|||
41 | 5 | if (! array_key_exists('content', $requestContent)) { |
|||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
42 | 2 | return $content; |
|||
43 | } |
||||
44 | 3 | $requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
|||
45 | |||||
46 | 3 | if (is_array($requestResult) && array_key_exists('log', $requestResult)) { |
|||
47 | 2 | $content = implode(chr(10), $requestResult['log']); |
|||
48 | } |
||||
49 | } |
||||
50 | 4 | return $content; |
|||
51 | } |
||||
52 | |||||
53 | /** |
||||
54 | * @param array|bool $requestContent |
||||
55 | */ |
||||
56 | 7 | public static function getResStatus($requestContent): string |
|||
57 | { |
||||
58 | 7 | if (empty($requestContent)) { |
|||
59 | 2 | return '-'; |
|||
60 | } |
||||
61 | 5 | if (! array_key_exists('content', $requestContent)) { |
|||
0 ignored issues
–
show
It seems like
$requestContent can also be of type boolean ; however, parameter $array of array_key_exists() does only seem to accept ArrayObject|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
62 | 1 | return 'Content index does not exists in requestContent array'; |
|||
63 | } |
||||
64 | |||||
65 | 4 | $requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
|||
66 | 4 | if (is_array($requestResult)) { |
|||
67 | 3 | if (empty($requestResult['errorlog'])) { |
|||
68 | 1 | return 'OK'; |
|||
69 | } |
||||
70 | 2 | return implode("\n", $requestResult['errorlog']); |
|||
71 | } |
||||
72 | |||||
73 | 1 | if (is_bool($requestResult)) { |
|||
0 ignored issues
–
show
|
|||||
74 | 1 | return 'Error - no info, sorry!'; |
|||
75 | } |
||||
76 | |||||
77 | return 'Error: ' . substr(preg_replace('/\s+/', ' ', strip_tags($requestResult)), 0, 10000) . '...'; |
||||
78 | } |
||||
79 | |||||
80 | /** |
||||
81 | * Find Fe vars |
||||
82 | */ |
||||
83 | 4 | public static function getResFeVars(array $resultData): array |
|||
84 | { |
||||
85 | 4 | if (empty($resultData)) { |
|||
86 | 1 | return []; |
|||
87 | } |
||||
88 | 3 | $requestResult = self::getJsonCompatibilityConverter()->convert($resultData['content']); |
|||
89 | 3 | return $requestResult['vars'] ?? []; |
|||
90 | } |
||||
91 | |||||
92 | 12 | private static function getJsonCompatibilityConverter(): JsonCompatibilityConverter |
|||
93 | { |
||||
94 | 12 | return GeneralUtility::makeInstance(JsonCompatibilityConverter::class); |
|||
95 | } |
||||
96 | } |
||||
97 |