Skip to content

Commit b292b55

Browse files
authored
[CodeBuilder] (bugfix) Indentation not taken into account (phpactor#425)
1 parent 1aaf4aa commit b292b55

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Bug fixes:
2121
itself, not the class it's used in, #412
2222
- [WorseReflection] Do not evaluate assignments with missing tokens.
2323
- [SourceCodeFilesystem] Non-existing paths not ignored.
24+
- [CodeTransform] Indentation not being taken into account for code
25+
updates (fixes #423).
2426

2527
## 0.2.0
2628

composer.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/integrations.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ play nicely with Phpactor, for the others there is this page.
1010
Drupal 8
1111
--------
1212

13+
### Bootstrapping
14+
1315
Drupal automatically adds its modules to the autoloader during the kernel
1416
boot process. It is therefore necessary to either 1) boot the kernel to have a fully
1517
useful autoloader *or* 2) to use a different mechanism to add the modules to the Composer autoloader.
1618

1719
Depending on your setup option 1 or 2 will be preferable.
1820

19-
### Option 1: Bootstrap Drupal on the fly to generate the autoloader
21+
In both cases deregister the autoloader in `.phpactor.yml`:
22+
23+
```yaml
24+
# Bootstrapping Drupal creates lots of implicit global
25+
# dependencies, so we will just keep the Drupal autoloader
26+
# registered and hope for the best.
27+
autoload.deregister: false
28+
```
29+
30+
#### Option 1: Bootstrap Drupal on the fly to generate the autoloader
2031
2132
Create the following bootstrap file `autoload_phpactor.php`, in (for example)
2233
`web/`:
@@ -58,19 +69,11 @@ Then edit `.phpactor.yml` to use that:
5869
```yaml
5970
# Use the special autoloader above
6071
autoload: web/phpactor_autoload.php
61-
62-
# Drupal CS is 2 spaces
63-
code_transform.indentation: 2
64-
65-
# Bootstrapping Drupal creates lots of implicit global
66-
# dependencies, so we will just keep the Drupal autoloader
67-
# registered and hope for the best.
68-
autoload.deregister: false
6972
```
7073

7174
The downside to this option is that it requires access to the DB from your current environment which may be tricky if you are running Drupal inside a VM.
7275

73-
### Option 2: Add the modules into the Composer autoloader
76+
#### Option 2: Add the modules into the Composer autoloader
7477

7578
This option requires merging in any modules (Drupal, contrib, custom) into the Composer autoloader via a discovery mechanism offered by the [Drupal Autoloader](https://github.com/fenetikm/autoload-drupal) composer plugin.
7679

@@ -100,3 +103,18 @@ composer autoload-dump
100103
```
101104

102105
The upside to this option is that it won't require the relatively slow Drupal bootstrap (which will hit the DB) but the downside is that you will have to regenerate the autoloader every time you add / remove a module.
106+
107+
#### Coding Standards
108+
109+
Change your local `.phpactor.yml` to use 2 spaces for indentation:
110+
111+
```
112+
# Drupal CS is 2 spaces
113+
code_transform.indentation: " "
114+
```
115+
116+
<div class="alert alert-info">
117+
Code will still be generated using the PSR-2 standard. It would be necessary
118+
to override twig templates in `.phpactor/templates` to rectify this (or just
119+
use a CS fixer).
120+
</div>

lib/Extension/CodeTransform/CodeTransformExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ private function registerRefactorings(ContainerBuilder $container)
269269
private function registerUpdater(ContainerBuilder $container)
270270
{
271271
$container->register('code_transform.updater', function (Container $container) {
272-
return new TolerantUpdater($container->get('code_transform.renderer'));
272+
return new TolerantUpdater(
273+
$container->get('code_transform.renderer'),
274+
$container->get('code_transform.text_format')
275+
);
273276
});
274277
$container->register('code_transform.builder_factory', function (Container $container) {
275278
return new WorseBuilderFactory($container->get('reflection.reflector'));

0 commit comments

Comments
 (0)