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

DarkaOnLine / L5-Swagger / 42733457520

10 Nov 2026 01:07AM UTC coverage: 97.124% (-2.7%) from 99.777%
42733457520

Pull #691

github

web-flow
Merge 2127adc72 into e01ec3ff5
Pull Request #691: Default `mode` to hybrid

3 of 9 new or added lines in 2 files covered. (33.33%)

6 existing lines in 2 files now uncovered.

439 of 452 relevant lines covered (97.12%)

10.57 hits per line

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

94.12
/src/SecurityDefinitions.php
1
<?php
2

3
namespace L5Swagger;
4

5
use Illuminate\Contracts\Filesystem\FileNotFoundException;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Collection;
8

9
class SecurityDefinitions
10
{
11
    /**
12
     * @param  array<string,mixed>  $schemasConfig
13
     * @param  array<string,mixed>  $securityConfig
14
     */
15
    public function __construct(
16
        private readonly array $schemasConfig = [],
17
        private readonly array $securityConfig = []
18
    ) {
19
    }
2 ✔
20

21
    /**
22
     * Reads in the l5-swagger configuration and appends security settings to documentation.
23
     *
24
     * @param  string  $filename  The path to the generated json documentation
25
     *
26
     * @throws FileNotFoundException
27
     */
28
    public function generate(string $filename): void
29
    {
30
        $fileSystem = new Filesystem();
2 ✔
31

32
        $documentation = collect(
2 ✔
33
            json_decode($fileSystem->get($filename))
2 ✔
34
        );
2 ✔
35

36
        if (! empty($this->schemasConfig)) {
2 ✔
37
            $documentation = $this->injectSecuritySchemes($documentation, $this->schemasConfig);
2 ✔
38
        }
39

40
        if (! empty($this->securityConfig)) {
2 ✔
41
            $documentation = $this->injectSecurity($documentation, $this->securityConfig);
2 ✔
42
        }
43

44
        $fileSystem->put(
2 ✔
45
            $filename,
2 ✔
46
            $documentation->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
2 ✔
47
        );
2 ✔
48
    }
49

50
    /**
51
     * Inject security schemes settings.
52
     *
53
     * @param  Collection<int|string, mixed>  $documentation  The parse json
54
     * @param  array<string,mixed>  $config  The securityScheme settings from l5-swagger
55
     * @return Collection<int|string, mixed>
56
     */
57
    protected function injectSecuritySchemes(Collection $documentation, array $config): Collection
58
    {
59
        $components = collect();
2 ✔
60
        if ($documentation->has('components')) {
2 ✔
UNCOV
61
            $components = collect($documentation->get('components'));
×
62
        }
63

64
        $securitySchemes = collect();
2 ✔
65
        if ($components->has('securitySchemes')) {
2 ✔
UNCOV
66
            $securitySchemes = collect($components->get('securitySchemes'));
×
67
        }
68

69
        foreach ($config as $key => $cfg) {
2 ✔
70
            $securitySchemes->offsetSet($key, $this->arrayToObject($cfg));
2 ✔
71
        }
72

73
        $components->offsetSet('securitySchemes', $securitySchemes);
2 ✔
74

75
        $documentation->offsetSet('components', $components);
2 ✔
76

77
        return $documentation;
2 ✔
78
    }
79

80
    /**
81
     * Inject security settings.
82
     *
83
     * @param  Collection<int|string, mixed>  $documentation  The parse json
84
     * @param  array<string, mixed>  $config  The security settings from l5-swagger
85
     * @return Collection<int|string, mixed>
86
     */
87
    protected function injectSecurity(Collection $documentation, array $config): Collection
88
    {
89
        $security = collect();
2 ✔
90
        if ($documentation->has('security')) {
2 ✔
91
            $security = collect($documentation->get('security'));
2 ✔
92
        }
93

94
        foreach ($config as $key => $cfg) {
2 ✔
95
            if (! empty($cfg)) {
2 ✔
96
                $security->put($key, $this->arrayToObject($cfg));
1 ✔
97
            }
98
        }
99

100
        if ($security->count()) {
2 ✔
101
            $documentation->offsetSet('security', $security);
2 ✔
102
        }
103

104
        return $documentation;
2 ✔
105
    }
106

107
    /**
108
     * Converts an array to an object.
109
     *
110
     * @param  $array<string,  mixed>
111
     * @return object
112
     */
113
    protected function arrayToObject(mixed $array): mixed
114
    {
115
        return json_decode(json_encode($array) ?: '');
2 ✔
116
    }
117
}
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