• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iLexN / swoole-psr7 / 28916674119

08 Jul 2026 04:05AM UTC coverage: 81.865% (-6.6%) from 88.489%
28916674119

Pull #198

github

web-flow
Merge 4f01c6522 into d8a316cd9
Pull Request #198: upgrade

87 of 120 new or added lines in 4 files covered. (72.5%)

4 existing lines in 1 file now uncovered.

158 of 193 relevant lines covered (81.87%)

2.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/Utility/ParseUploadedFiles.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Ilex\SwoolePsr7\Utility;
6

7
use Psr\Http\Message\StreamFactoryInterface;
8
use Psr\Http\Message\UploadedFileFactoryInterface;
9

10
final readonly class ParseUploadedFiles
11
{
12

13
    public function __construct(
14
        private UploadedFileFactoryInterface $uploadedFileFactory,
15
        private StreamFactoryInterface $streamFactory
16
    ) {
17
    }
6✔
18

19
    /**
20
     * Parse a non-normalized, i.e. $_FILES super global, tree of uploaded file
21
     * data.
22
     *
23
     * @param array<int|string, mixed> $uploadedFiles The non-normalized tree of uploaded file
24
     *     data.
25
     *
26
     * @return array<int|string, mixed> A normalized tree of UploadedFile instances.
27
     */
28
    public function parseUploadedFiles(array $uploadedFiles): array
29
    {
30
        $parsed = [];
4✔
31
        foreach ($uploadedFiles as $field => $uploadedFile) {
4✔
32
            /** @var array<int|string, mixed> $uploadedFile */
33
            if (!isset($uploadedFile['error'])) {
4✔
NEW
34
                $parsed[$field] = $this->parseUploadedFiles($uploadedFile);
×
35

36
                continue;
×
37
            }
38

39
            if (!is_array($uploadedFile['error'])) {
4✔
40
                /** @var string $tmpName */
41
                $tmpName = $uploadedFile['tmp_name'];
4✔
42
                /** @var int $error */
43
                $error = $uploadedFile['error'];
4✔
44
                /** @var int|string|null $rawSize */
45
                $rawSize = $uploadedFile['size'] ?? null;
4✔
46
                /** @var string|null $rawName */
47
                $rawName = $uploadedFile['name'] ?? null;
4✔
48
                /** @var string|null $rawType */
49
                $rawType = $uploadedFile['type'] ?? null;
4✔
50

51

52
                $parsed[$field] = $this->uploadedFileFactory->createUploadedFile(
4✔
53
                    $this->streamFactory->createStream($tmpName),
4✔
54
                    $rawSize !== null ? (int) $rawSize : null,
4✔
55
                    $error,
4✔
56
                    $rawName,
4✔
57
                    $rawType
4✔
58
                );
4✔
59
            } else {
60
                /** @var array<int|string, mixed> $errorArr */
61
                $errorArr = $uploadedFile['error'];
2✔
62

63
                $nameArr = $uploadedFile['name'] ?? [];
2✔
64
                $typeArr = $uploadedFile['type'] ?? [];
2✔
65
                $tmpNameArr = $uploadedFile['tmp_name'] ?? [];
2✔
66
                $sizeArr = $uploadedFile['size'] ?? [];
2✔
67
                if (!is_array($nameArr)) {
2✔
NEW
68
                    continue;
×
69
                }
70

71
                if (!is_array($typeArr)) {
2✔
NEW
72
                    continue;
×
73
                }
74

75
                if (!is_array($tmpNameArr)) {
2✔
NEW
76
                    continue;
×
77
                }
78

79
                if (!is_array($sizeArr)) {
2✔
NEW
80
                    continue;
×
81
                }
82

83
                $keys = array_keys($errorArr);
2✔
84
                $subArray = [];
2✔
85
                foreach ($keys as $key) {
2✔
86
                    if (!array_key_exists($key, $nameArr)) {
2✔
NEW
87
                        continue;
×
88
                    }
89

90
                    if (!array_key_exists($key, $typeArr)) {
2✔
NEW
91
                        continue;
×
92
                    }
93

94
                    if (!array_key_exists($key, $tmpNameArr)) {
2✔
NEW
95
                        continue;
×
96
                    }
97

98
                    if (!array_key_exists($key, $sizeArr)) {
2✔
NEW
99
                        continue;
×
100
                    }
101

102
                    $subArray[$key]['name'] = is_string($nameArr[$key]) ? $nameArr[$key] : '';
2✔
103
                    $subArray[$key]['type'] = is_string($typeArr[$key]) ? $typeArr[$key] : '';
2✔
104
                    $subArray[$key]['tmp_name'] = is_string($tmpNameArr[$key]) ? $tmpNameArr[$key] : '';
2✔
105
                    $subArray[$key]['error'] = is_int($errorArr[$key]) ? $errorArr[$key] : UPLOAD_ERR_NO_FILE;
2✔
106
                    $subArray[$key]['size'] = is_int($sizeArr[$key]) || is_string($sizeArr[$key]) ? (int)$sizeArr[$key] : 0;
2✔
107
                }
108

109
                $parsed[$field] = $this->parseUploadedFiles($subArray);
2✔
110
            }
111
        }
112

113
        return $parsed;
4✔
114
    }
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc