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

contributte / utils / 6877995345

15 Nov 2023 01:31PM UTC coverage: 91.765% (+0.6%) from 91.124%
6877995345

push

github

f3l1x
Composer: require PHP 8.1+

312 of 340 relevant lines covered (91.76%)

0.92 hits per line

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

71.43
/src/Http.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Utils;
4

5
use LogicException;
6
use Nette\StaticClass;
7

8
class Http
9
{
10

11
        use StaticClass;
12

13
        private static string $metadataPattern = '
14
                ~<\s*meta\s
15

16
                # using lookahead to capture type to $1
17
                (?=[^>]*?
18
                        \b(?:name|property|http-equiv)\s*=\s*
19
                        (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
20
                        ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
21
                )
22

23
                # capture content to $2
24
                [^>]*?\bcontent\s*=\s*
25
                        (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
26
                        ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
27
                [^>]*>
28

29
                ~ix';
30

31
        /**
32
         * Gets http metadata from string
33
         *
34
         * @return string[] [name => content]
35
         */
36
        public static function metadata(string $content): array
1✔
37
        {
38
                if (preg_match_all(self::$metadataPattern, $content, $matches) !== false) {
1✔
39
                        $combine = array_combine($matches[1], $matches[2]);
1✔
40

41
                        if ($combine === []) {
1✔
42
                                throw new LogicException('Matches count is not equal.');
×
43
                        }
44

45
                        return $combine;
1✔
46
                }
47

48
                return [];
×
49
        }
50

51
}
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