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

ICanBoogie / Module / 46296416018

29 Nov 2026 06:38PM UTC coverage: 15.309%. First build
46296416018

push

github

olvlvl
refactor: follow the renaming of the Autoconfig config paths

ARG_CONFIG_PATHS is replaced by ARG_CONFIG_PATH_WEIGHTS.

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

62 of 405 relevant lines covered (15.31%)

0.63 hits per line

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

0.0
/lib/Module/Autoconfig/ModuleExtension.php
1
<?php
2

3
namespace ICanBoogie\Module\Autoconfig;
4

5
use DirectoryIterator;
6
use ICanBoogie\Autoconfig\Autoconfig;
7
use ICanBoogie\Autoconfig\AutoconfigGenerator;
8
use ICanBoogie\Autoconfig\ExtensionAbstract;
9

10
use function array_merge;
11
use function getcwd;
12
use function is_dir;
13
use function is_string;
14

15
/**
16
 * Autoconfig extension to handle modules, their config and locale messages.
17
 */
18
final class ModuleExtension extends ExtensionAbstract
19
{
20
    /**
21
     * Identifier for module packages.
22
     */
23
    public const string PACKAGE_TYPE_MODULE = "icanboogie-module";
24

25
    /**
26
     * composer.json extra property for modules path. (root-only)
27
     */
28
    public const string OPTION_MODULES_PATH = 'modules-path';
29

30
    public function __construct(
31
        private readonly AutoconfigGenerator $generator
32
    ) {
33
        parent::__construct($generator);
×
34
    }
35

36
    /**
37
     * @var string[]
38
     */
39
    private array $modules_directories;
40

41
    /**
42
     * @inheritdoc
43
     */
44
    public function alter_schema(callable $set_property): void
45
    {
46
        $set_property(self::OPTION_MODULES_PATH, [
×
47

48
            'type' => "string",
×
49
            'description' => "(root-only) Path to application's custom modules.",
×
50
            'required' => false,
×
51

52
        ]);
×
53
    }
54

55
    /**
56
     * @inheritdoc
57
     */
58
    public function synthesize(array &$autoconfig): void
59
    {
60
        $modules_directories = $this->modules_directories = $this->collect_modules_directories();
×
61

62
        foreach ($modules_directories as $pathname) {
×
63
            if (is_dir("$pathname/config")) {
×
64
                // @phpstan-ignore offsetAccess.nonOffsetAccessible (the shape of the autoconfig array isn't described)
NEW
65
                $autoconfig[Autoconfig::ARG_CONFIG_PATH_WEIGHTS][] = [
×
66

67
                    $this->find_shortest_path_code("$pathname/config"),
×
68
                    Autoconfig::CONFIG_WEIGHT_MODULE
×
69

70
                ];
×
71
            }
72

73
            if (is_dir("$pathname/locale")) {
×
74
                // @phpstan-ignore offsetAccess.nonOffsetAccessible (the shape of the autoconfig array isn't described)
75
                $autoconfig[Autoconfig::ARG_LOCALE_PATHS][] = $this
×
76
                    ->find_shortest_path_code("$pathname/locale");
×
77
            }
78
        }
79
    }
80

81
    public function render(): string
82
    {
83
        return $this->render_array_entry(
×
84
            ModuleAutoconfig::MODULES,
×
85
            $this->modules_directories, // @phpstan-ignore argument.type (the parent expects string keys, this is a list)
×
86
            function (string $directory) {
×
87
                return $this->find_shortest_path_code($directory);
×
88
            }
×
89
        );
×
90
    }
91

92
    /**
93
     * @return string[]
94
     */
95
    private function collect_modules_directories(): array
96
    {
97
        return array_merge(
×
98
            $this->collect_modules_directories_from_packages(),
×
99
            $this->collect_modules_directories_from_root_package()
×
100
        );
×
101
    }
102

103
    /**
104
     * @return string[]
105
     */
106
    private function collect_modules_directories_from_packages(): array
107
    {
108
        $directories = [];
×
109

110
        foreach ($this->generator->packages as $pathname => $package) {
×
111
            if ($package->getType() != self::PACKAGE_TYPE_MODULE) {
×
112
                continue;
×
113
            }
114

115
            $directories[] = $pathname;
×
116
        }
117

118
        return $directories;
×
119
    }
120

121
    /**
122
     * @return string[]
123
     */
124
    private function collect_modules_directories_from_root_package(): array
125
    {
126
        $package = $this->generator->root_package;
×
127
        // @phpstan-ignore offsetAccess.nonOffsetAccessible (the extra of a package is unstructured)
128
        $path = $package->getExtra()['icanboogie'][self::OPTION_MODULES_PATH] ?? null;
×
129

130
        if (!$path) {
×
131
            return [];
×
132
        }
133

134
        assert(is_string($path));
×
135

136
        $directories = [];
×
137
        $iterator = new DirectoryIterator(getcwd() . DIRECTORY_SEPARATOR . $path);
×
138

139
        foreach ($iterator as $file) {
×
140
            if ($file->isDot() || $file->isFile()) {
×
141
                continue;
×
142
            }
143

144
            $directories[] = $file->getPathname();
×
145
        }
146

147
        return $directories;
×
148
    }
149
}
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