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

Jagepard / Rudra-Annotation / 26450127911

26 May 2026 01:13PM UTC coverage: 95.918% (-2.0%) from 97.917%
26450127911

push

github

web-flow
Merge pull request #83 from Jagepard/wip

update

3 of 4 new or added lines in 2 files covered. (75.0%)

47 of 49 relevant lines covered (95.92%)

2.73 hits per line

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

94.44
/src/ParamsExtractor.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This Source Code Form is subject to the terms of the Mozilla Public
5
 * License, v. 2.0. If a copy of the MPL was not distributed with this
6
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
 *
8
 * @author  Korotkov Danila (Jagepard) <jagepard@yandex.ru>
9
 * @license https://mozilla.org/MPL/2.0/  MPL-2.0
10
 */
11

12
namespace Rudra\Annotation;
13

14
final readonly class ParamsExtractor
15
{
16
    /**
17
     * Parses an array of parameter strings into an associative array.
18
     * --------------------
19
     * Преобразует массив строк с параметрами в ассоциативный массив.
20
     * 
21
     * `from: "param1, param2 = 'param2', param3={param1;param2:'param2'}"`
22
     * `to: ["param1", "param2" => "param2", "param3" => ["param1", "param2" => "param2"]]`
23
     * 
24
     * @param array $exploded
25
     * @param string $assignment
26
     * @return array
27
     */
28
    public function getParams(array $exploded, string $assignment): array
3✔
29
    {
30
        $processed = [];
3✔
31

32
        foreach ($exploded as $key => $item) {
3✔
33
            if (str_contains($item, $assignment)) {
3✔
34
                $item = $this->handleData($item, explode($assignment, $item));
3✔
35
            }
36
            $processed[is_array($item) ? key($item) : $key] = is_array($item) ? $item[key($item)] : $item;
3✔
37
        }
38

39
        return $processed;
3✔
40
    }
41

42

43
    /**
44
     * Parses data into `key => value` pairs
45
     * --------------------
46
     * Преобразует данные в пары `ключ => значение`
47
     *
48
     * @param string $data
49
     * @param array $exploded
50
     * @return array|null
51
     */
52
    private function handleData(string $data, array $exploded): ?array
3✔
53
    {
54
        /**
55
         * If in data an array of type param3={param1;param2:'param2'}
56
         * --------------------
57
         * Если в данных есть массив типа param3={param1;param2:'param2'}
58
         */
59
        if (preg_match("/=\s*{/", $data) && preg_match("/{(.*)}/", $exploded[1], $matches)) {
3✔
60
            return [
3✔
61
                trim($exploded[0]) => $this->getParams(
3✔
62
                    explode(Annotation::DELIMITER["array"], trim($matches[1])),
3✔
63
                    Annotation::ASSIGNMENT["array"]
3✔
64
                ),
3✔
65
            ];
3✔
66
        }
67

68
        /**
69
         * Remove quotation marks around parameter
70
         * --------------------
71
         * Удаляет кавычки вокруг параметра
72
         * 
73
         * matches[1] = 'param2';
74
         */
75
        if (preg_match("/'(.*)'/", $exploded[1], $matches)) {
3✔
76
            return [trim($exploded[0]) => $matches[1]];
3✔
77
        }
78

NEW
79
        return null;
×
80
    } // @codeCoverageIgnore
81
}
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