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

api-platform / core / 6173831445

13 Sep 2023 02:23PM UTC coverage: 36.999% (-0.1%) from 37.094%
6173831445

push

github

soyuka
chore: subtree component descriptions

10101 of 27301 relevant lines covered (37.0%)

19.98 hits per line

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

83.33
/src/Util/ErrorFormatGuesser.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Util;
15

16
use Symfony\Component\HttpFoundation\Request;
17

18
/**
19
 * Guesses the error format to use.
20
 *
21
 * @deprecated since API Platform 3.2
22
 *
23
 * @author Kévin Dunglas <dunglas@gmail.com>
24
 */
25
final class ErrorFormatGuesser
26
{
27
    private function __construct()
28
    {
29
    }
×
30

31
    /**
32
     * Get the error format and its associated MIME type.
33
     */
34
    public static function guessErrorFormat(Request $request, array $errorFormats): array
35
    {
36
        $requestFormat = $request->getRequestFormat('');
69✔
37

38
        if ('' !== $requestFormat && isset($errorFormats[$requestFormat])) {
69✔
39
            return ['key' => $requestFormat, 'value' => $errorFormats[$requestFormat]];
6✔
40
        }
41

42
        $requestMimeTypes = Request::getMimeTypes($request->getRequestFormat());
63✔
43
        $defaultFormat = [];
63✔
44

45
        foreach ($errorFormats as $format => $errorMimeTypes) {
63✔
46
            if (array_intersect($requestMimeTypes, $errorMimeTypes)) {
63✔
47
                return ['key' => $format, 'value' => $errorMimeTypes];
×
48
            }
49

50
            if (!$defaultFormat) {
63✔
51
                $defaultFormat = ['key' => $format, 'value' => $errorMimeTypes];
63✔
52
            }
53
        }
54

55
        return $defaultFormat;
63✔
56
    }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc