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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

78.57
/src/Api/FormatMatcher.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\Api;
15

16
/**
17
 * Matches a mime type to a format.
18
 *
19
 * @internal
20
 */
21
final class FormatMatcher
22
{
23
    /**
24
     * @var array<string, string[]>
25
     */
26
    private readonly array $formats;
27

28
    /**
29
     * @param array<string, string[]|string> $formats
30
     */
31
    public function __construct(array $formats)
32
    {
33
        $normalizedFormats = [];
42✔
34
        foreach ($formats as $format => $mimeTypes) {
42✔
35
            $normalizedFormats[$format] = (array) $mimeTypes;
42✔
36
        }
37
        $this->formats = $normalizedFormats;
42✔
38
    }
39

40
    /**
41
     * Gets the format associated with the mime type.
42
     *
43
     * Adapted from {@see \Symfony\Component\HttpFoundation\Request::getFormat}.
44
     */
45
    public function getFormat(string $mimeType): ?string
46
    {
47
        $canonicalMimeType = null;
42✔
48
        $pos = strpos($mimeType, ';');
42✔
49
        if (false !== $pos) {
42✔
50
            $canonicalMimeType = trim(substr($mimeType, 0, $pos));
×
51
        }
52

53
        foreach ($this->formats as $format => $mimeTypes) {
42✔
54
            if (\in_array($mimeType, $mimeTypes, true)) {
42✔
55
                return $format;
42✔
56
            }
57
            if (null !== $canonicalMimeType && \in_array($canonicalMimeType, $mimeTypes, true)) {
9✔
58
                return $format;
×
59
            }
60
        }
61

UNCOV
62
        return null;
×
63
    }
64
}
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

© 2026 Coveralls, Inc