Skip to content

Commit

Permalink
Better phpdoc and fixed a possibly null warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Nov 15, 2024
1 parent 49fe8b7 commit f270363
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/MahoAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

class MahoAutoload
{
protected static $modules = null;
protected static $paths = null;
/** @var array<string, array<string, bool|string>>|null */
protected static ?array $modules = null;

/** @var string[]|null */
protected static ?array $paths = null;

/**
* @return array<string, array<string, bool|string>>
*/
public static function getInstalledModules(string $projectDir): array
{
if (self::$modules !== null) {
Expand All @@ -17,7 +23,6 @@ public static function getInstalledModules(string $projectDir): array
self::$modules = [];

$datasets = InstalledVersions::getAllRawData();

foreach ($datasets as $dataset) {
foreach ($dataset['versions'] as $package => $info) {
if (isset(self::$modules[$package])) {
Expand Down Expand Up @@ -45,6 +50,9 @@ public static function getInstalledModules(string $projectDir): array
return self::$modules;
}

/**
* @return string[]
*/
public static function generatePaths(string $projectDir): array
{
if (self::$paths !== null) {
Expand All @@ -70,7 +78,7 @@ public static function generatePaths(string $projectDir): array
$addIfExists($projectDir, 'app/code/local');
$addIfExists($projectDir, 'app/code/community');

if ($modules['mahocommerce/maho']['isChildProject']) {
if (isset($modules['mahocommerce/maho']) && $modules['mahocommerce/maho']['isChildProject']) {
$addIfExists($projectDir, 'app/code/core');
$addIfExists($projectDir, 'lib');
}
Expand All @@ -84,7 +92,7 @@ public static function generatePaths(string $projectDir): array
}
}

if ($modules['mahocommerce/maho']['isChildProject']) {
if (isset($modules['mahocommerce/maho']) && $modules['mahocommerce/maho']['isChildProject']) {
$addIfExists($modules['mahocommerce/maho']['path'], 'app/code/core');
$addIfExists($modules['mahocommerce/maho']['path'], 'lib');
} else {
Expand All @@ -95,13 +103,16 @@ public static function generatePaths(string $projectDir): array
return self::$paths = array_merge(...array_values($codePools));
}

/**
* @return array<string, array<int, string>>
*/
public static function generatePsr0(string $projectDir): array
{
$paths = self::generatePaths($projectDir);

$prefixes = [];
foreach ($paths as $path) {
foreach (glob("$path/*/*") as $file) {
foreach (glob("$path/*/*") ?: [] as $file) {
$prefix = str_replace('/', '_', substr($file, strlen($path) + 1));
if (is_file($file) && str_ends_with($file, '.php')) {
$prefix = str_replace('.php', '', $prefix);
Expand All @@ -118,13 +129,16 @@ public static function generatePsr0(string $projectDir): array
return $prefixes;
}

/**
* @return string[]
*/
public static function generateControllerClassMap(string $projectDir): array
{
$paths = self::generatePaths($projectDir);

$classmaps = [];
foreach ($paths as $path) {
foreach (glob("$path/*/*/controllers", GLOB_ONLYDIR) as $dir) {
foreach (glob("$path/*/*/controllers", GLOB_ONLYDIR) ?: [] as $dir) {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
foreach ($files as $file) {
if (!$file->isFile() || !str_ends_with($file->getFileName(), 'Controller.php')) {
Expand Down

0 comments on commit f270363

Please sign in to comment.