Skip to content

Commit 08ceac8

Browse files
committed
Try to fake YAML as NEON
1 parent c14d1f6 commit 08ceac8

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/Drush/Commands/PhpstanDrupalDrushCommands.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace mglaman\PHPStanDrupal\Drush\Commands;
44

5+
use Drupal\Core\Serialization\Yaml;
56
use Drush\Commands\DrushCommands;
67

78
final class PhpstanDrupalDrushCommands extends DrushCommands
@@ -22,31 +23,28 @@ public function setup($options = ['file' => null]): void
2223
'web/themes/custom',
2324
'web/profiles/custom',
2425
],
25-
// @todo can we have this override _everything_ phpstan-drupal provides? or is it a merge.
26-
'entityMapping' => [
26+
'drupal' => [
27+
// @todo can we have this override _everything_ phpstan-drupal provides? or is it a merge.
28+
'entityMapping' => [
29+
],
2730
],
31+
2832
];
2933

3034
$entity_type_manager = \Drupal::entityTypeManager();
3135
foreach ($entity_type_manager->getDefinitions() as $definition) {
32-
$parameters['entityMapping'][$definition->id()] = [
36+
$parameters['drupal']['entityMapping'][$definition->id()] = [
3337
'class' => $definition->getClass(),
3438
'storage' => $definition->getStorageClass(),
3539
];
3640
}
3741

38-
// @todo this is just silly, reinventing NEON encoder so it's not a Drupal dependency.
39-
$output = <<<NEON
40-
parameters:
41-
42-
NEON;
43-
;
44-
foreach ($parameters as $key => $value) {
45-
$output .= "$key:";
46-
if (is_array($value)) {
47-
$output .= "\n\t";
48-
}
49-
}
42+
$config = [
43+
'parameters' => $parameters,
44+
];
45+
$output = Yaml::encode($config);
46+
// Replace 2 spaces with tabs for NEON compatibility.
47+
$output = str_replace(' ', "\t", $output);
5048

5149
if ($options['file'] !== null) {
5250
file_put_contents($options['file'], $output);

0 commit comments

Comments
 (0)