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

michalsn / codeigniter-module-manager / 21144733500

19 Jan 2026 04:25PM UTC coverage: 69.289% (+0.4%) from 68.889%
21144733500

push

github

michalsn
update module validation

27 of 27 new or added lines in 4 files covered. (100.0%)

10 existing lines in 2 files now uncovered.

828 of 1195 relevant lines covered (69.29%)

11.26 hits per line

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

68.42
/src/Commands/BaseModuleCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Michalsn\CodeIgniterModuleManager\Commands;
6

7
use CodeIgniter\CLI\BaseCommand;
8
use CodeIgniter\CLI\CLI;
9
use CodeIgniter\Database\Exceptions\DatabaseException;
10
use Michalsn\CodeIgniterModuleManager\Entities\Module;
11
use Michalsn\CodeIgniterModuleManager\Services\ModuleManager;
12
use Michalsn\CodeIgniterModuleManager\Services\ModuleRegistry;
13

14
abstract class BaseModuleCommand extends BaseCommand
15
{
16
    protected $group = 'Modules';
17
    protected ModuleManager $moduleManager;
18
    protected ModuleRegistry $moduleRegistry;
19

20
    /**
21
     * Convert user input (folder name or namespace) to namespace
22
     */
23
    protected function resolveNamespace(string $identifier): ?string
24
    {
25
        if (str_contains($identifier, '\\')) {
19✔
26
            // If identifier contains backslash, it's already a namespace
UNCOV
27
            $module = $this->moduleRegistry->getByNamespace($identifier);
×
28
        } else {
29
            // Otherwise, it's a folder name - look up the module to get its namespace
30
            $module = $this->moduleRegistry->getByFolderName($identifier);
19✔
31
        }
32

33
        if (! $module instanceof Module) {
19✔
34
            CLI::error("Module not found: {$identifier}");
7✔
35
            CLI::error("Run 'php spark module:scan' to discover modules.", 'yellow');
7✔
36

37
            return null;
7✔
38
        }
39

40
        return $module->namespace;
12✔
41
    }
42

43
    /**
44
     * Initialize services
45
     */
46
    protected function initializeServices(): void
47
    {
48
        $this->ensureMigrationsRan();
35✔
49

50
        $this->moduleManager  = service('moduleManager');
35✔
51
        $this->moduleRegistry = service('moduleRegistry');
35✔
52
    }
53

54
    /**
55
     * Check if the modules table exists (migrations were run)
56
     */
57
    protected function ensureMigrationsRan(): void
58
    {
59
        $db = db_connect();
35✔
60

61
        try {
62
            $tableExists = $db->tableExists('modules');
35✔
UNCOV
63
        } catch (DatabaseException) {
×
UNCOV
64
            $tableExists = false;
×
65
        }
66

67
        if (! $tableExists) {
35✔
UNCOV
68
            CLI::error('The modules table does not exist.');
×
UNCOV
69
            CLI::error('Please run migrations first: php spark migrate --all', 'yellow');
×
70

UNCOV
71
            exit(EXIT_ERROR);
×
72
        }
73
    }
74
}
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