Skip to content
Snippets Groups Projects

Issue #3236264 - Use yaml parser

1 file
+ 6
12
Compare changes
  • Side-by-side
  • Inline
@@ -3,6 +3,7 @@
namespace Drupal\unused_modules;
use Composer\InstalledVersions;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionDiscovery;
@@ -185,18 +186,11 @@ class UnusedModulesHelperService implements UnusedModulesHelperServiceInterface
$error_message = "No .info.yml file found for module '" . $module->getName() . "'";
throw new UnusedModulesException($error_message);
}
$info_file = file($module->getPathname(), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// Traverse all lines in .info and look for the line that starts with
// "project". When found, add the project name to the module object.
foreach ($info_file as $line) {
if (substr($line, 0, 7) === "project") {
// Remove "project = " prefix.
$project = str_replace("project: ", "", $line);
// Remove surrounding single-quotes.
$project = str_replace("'", "", $project);
$module->projectName = $project;
}
// Add the project name to the module object.
$info_file = Yaml::decode(file_get_contents($module->getPathname()));
if (!empty($info_file['project'])) {
$module->projectName = $info_file['project'];
}
if (!$module->projectName) {
Loading