Skip to content

Commit 6b391de

Browse files
committed
Refactored
1 parent 6a1353e commit 6b391de

28 files changed

+62
-165
lines changed

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is copied from config/symfony/.editorconfig in https://github.com/itk-dev/devops_itkdev-docker.
2+
# Feel free to edit the file, but consider making a pull request if you find a general issue with the file.
3+
4+
# EditorConfig is awesome: https://editorconfig.org
5+
6+
# top-most EditorConfig file
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = LF
12+
indent_size = 4
13+
indent_style = space
14+
insert_final_newline = true
15+
trim_trailing_whitespace = true
16+
17+
[*.{js,css,scss}]
18+
indent_size = 2
19+
20+
[*.{yml,yaml}]
21+
indent_size = 2
22+
23+
[config/**/*.{yml,yaml}]
24+
indent_size = 4

drupal_translation_extractor.services.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ services:
1212
- '@Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TransMethodVisitor'
1313
- '@Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TranslatableMarkupVisitor'
1414

15-
Drupal\drupal_translation_extractor\Translation\TwigExtractor:
15+
Drupal\drupal_translation_extractor\Twig\Translation\TwigExtractor:
1616

17-
Drupal\drupal_translation_extractor\ItkTranslationExtractorTwigExtension:
17+
Drupal\drupal_translation_extractor\Twig\Extension\ItkTranslationExtractorTwigExtension:
1818
tags:
1919
- { name: twig.extension }
2020

@@ -32,7 +32,7 @@ services:
3232
"addExtractor",
3333
[
3434
"twig",
35-
'@Drupal\drupal_translation_extractor\Translation\TwigExtractor',
35+
'@Drupal\drupal_translation_extractor\Twig\Translation\TwigExtractor',
3636
],
3737
]
3838

phpstan.dist.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parameters:
44
- src
55
- tests
66
excludePaths:
7-
- tests/Unit/*/resources/*
7+
- tests/resources/*
88

99
treatPhpDocTypesAsCertain: false
1010

src/ItkTranslationExtractorTwigExtension.php renamed to src/Twig/Extension/ItkTranslationExtractorTwigExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
declare(strict_types=1);
44

5-
namespace Drupal\drupal_translation_extractor;
5+
namespace Drupal\drupal_translation_extractor\Twig\Extension;
66

7-
use Drupal\drupal_translation_extractor\NodeVisitor\TranslationNodeVisitor;
7+
use Drupal\drupal_translation_extractor\Twig\NodeVisitor\TranslationNodeVisitor;
88
use Twig\Extension\AbstractExtension;
99

1010
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace Drupal\drupal_translation_extractor\Translation;
3+
namespace Drupal\drupal_translation_extractor\Twig\Extractor;
44

5-
use Drupal\drupal_translation_extractor\ItkTranslationExtractorTwigExtension;
65
use Drupal\drupal_translation_extractor\Translation\Dumper\PoItem;
6+
use Drupal\drupal_translation_extractor\Twig\Extension\ItkTranslationExtractorTwigExtension;
77
use Symfony\Bridge\Twig\Translation\TwigExtractor as BaseTwigExtractor;
88
use Symfony\Component\DependencyInjection\Attribute\Autowire;
99
use Symfony\Component\Translation\MessageCatalogue;

src/NodeVisitor/TranslationNodeVisitor.php renamed to src/Twig/NodeVisitor/TranslationNodeVisitor.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

3-
namespace Drupal\drupal_translation_extractor\NodeVisitor;
3+
namespace Drupal\drupal_translation_extractor\Twig\NodeVisitor;
44

5-
use Drupal\Core\Template\TwigNodeTrans;
65
use Drupal\Core\Template\TwigNodeTrans as TransNode;
76
use Drupal\drupal_translation_extractor\Translation\Dumper\PoItem;
87
use Twig\Environment;
@@ -66,18 +65,6 @@ public function enterNode(Node $node, Environment $env): Node
6665
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
6766
];
6867
// {{ t('…') }} is not supported in Drupal.
69-
// } elseif (
70-
// $node instanceof FunctionExpression
71-
// && 't' === $node->getAttribute('name')
72-
// ) {
73-
// $nodeArguments = $node->getNode('arguments');
74-
//
75-
// if ($nodeArguments->getIterator()->current() instanceof ConstantExpression) {
76-
// $this->messages[] = [
77-
// $this->getReadMessageFromArguments($nodeArguments, 0),
78-
// $this->getReadDomainFromArguments($nodeArguments, 2),
79-
// ];
80-
// }
8168
} elseif ($node instanceof TransNode) {
8269
// extract trans nodes
8370
$body = $node->getNode('body');
@@ -191,7 +178,7 @@ private function getStringValue(Node $node): string
191178
*
192179
* Return type has been added.
193180
*
194-
* @see TwigNodeTrans::compileString()
181+
* @see TransNode::compileString()
195182
*/
196183
private function compileString(Node $body): array
197184
{

tests/Unit/AbstractTestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
namespace Drupal\drupal_translation_extractor\Test\Unit;
44

55
use Drupal\Core\Template\TwigTransTokenParser;
6-
use Drupal\drupal_translation_extractor\ItkTranslationExtractorTwigExtension;
6+
use Drupal\drupal_translation_extractor\Twig\Extension\ItkTranslationExtractorTwigExtension;
77
use PHPUnit\Framework\TestCase;
88
use Twig;
99
use Twig\Environment;
1010
use Twig\Loader\FilesystemLoader;
1111

1212
abstract class AbstractTestCase extends TestCase
1313
{
14+
protected function getResourcePath(string $path = ''): string
15+
{
16+
return dirname(__DIR__).'/resources/'.$path;
17+
}
18+
1419
protected function createTwig(): Environment
1520
{
1621
$twig = new Environment(new FilesystemLoader());

tests/Unit/Command/TranslationExtractCommandTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Drupal\drupal_translation_extractor\Translation\Extractor\PhpExtractor;
1111
use Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TranslatableMarkupVisitor;
1212
use Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TransMethodVisitor;
13-
use Drupal\drupal_translation_extractor\Translation\TwigExtractor;
13+
use Drupal\drupal_translation_extractor\Twig\Extractor\TwigExtractor;
1414
use Drupal\locale\StringStorageInterface;
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\Input\ArrayInput;
@@ -25,7 +25,7 @@ public function testNoTranslations(): void
2525
$command = $this->createCommand();
2626
$input = new ArrayInput([
2727
'locale' => 'da',
28-
'source' => __DIR__.'/resources/translations/',
28+
'source' => $this->getResourcePath('translations'),
2929
'--dump-messages' => true,
3030
]);
3131
$output = new BufferedOutput();
@@ -42,11 +42,11 @@ public function testNoTranslationsOutput(): void
4242
$command = $this->createCommand();
4343
$input = new ArrayInput([
4444
'locale' => 'da',
45-
'source' => __DIR__.'/resources/templates/',
45+
'source' => $this->getResourcePath('templates/'),
4646
'--force' => true,
4747
'--output' => $outputPath,
4848
]);
49-
$expectedPath = __DIR__.'/resources/expected/'.__FUNCTION__.'.da.po';
49+
$expectedPath = $this->getResourcePath('expected/'.__FUNCTION__.'.da.po');
5050

5151
$output = new BufferedOutput();
5252
$result = $command->run($input, $output);

tests/Unit/Extractor/PhpExtractorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace Drupal\drupal_translation_extractor\Test\Unit\Extractor;
66

7+
use Drupal\drupal_translation_extractor\Test\Unit\AbstractTestCase;
78
use Drupal\drupal_translation_extractor\Translation\Dumper\PoItem;
89
use Drupal\drupal_translation_extractor\Translation\Extractor\PhpExtractor;
910
use Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TranslatableMarkupVisitor;
1011
use Drupal\drupal_translation_extractor\Translation\Extractor\Visitor\TransMethodVisitor;
11-
use PHPUnit\Framework\TestCase;
1212
use Symfony\Component\Translation\MessageCatalogue;
1313

14-
final class PhpExtractorTest extends TestCase
14+
final class PhpExtractorTest extends AbstractTestCase
1515
{
1616
public function testTransMethod(): void
1717
{
@@ -20,7 +20,7 @@ public function testTransMethod(): void
2020
];
2121
$extractor = new PhpExtractor($visitors);
2222
$resource = [
23-
__DIR__.'/resources/src/MyClass.php',
23+
$this->getResourcePath('src/MyClass.php'),
2424
];
2525
$locale = 'da';
2626
$messages = new MessageCatalogue($locale);
@@ -44,7 +44,7 @@ public function testTransMethodDrupal(): void
4444
];
4545
$extractor = new PhpExtractor($visitors);
4646
$resource = [
47-
__DIR__.'/resources/src/MyClassDrupal.php',
47+
$this->getResourcePath('src/MyClassDrupal.php'),
4848
];
4949
$locale = 'da';
5050
$messages = new MessageCatalogue($locale);
@@ -67,7 +67,7 @@ public function testTransMethodDrupalModule(): void
6767
new TransMethodVisitor(),
6868
];
6969
$extractor = new PhpExtractor($visitors);
70-
$resource = __DIR__.'/resources/';
70+
$resource = $this->getResourcePath();
7171
$locale = 'da';
7272
$messages = new MessageCatalogue($locale);
7373
$extractor->extract($resource, $messages);
@@ -83,7 +83,7 @@ public function testTranslatableMarkup(): void
8383
new TranslatableMarkupVisitor(),
8484
];
8585
$resource = [
86-
__DIR__.'/resources/src/MyClass.php',
86+
$this->getResourcePath('src/MyClass.php'),
8787
];
8888
$locale = 'da';
8989

@@ -108,7 +108,7 @@ public function testTranslatableMarkupDrupal(): void
108108
new TranslatableMarkupVisitor(),
109109
];
110110
$resource = [
111-
__DIR__.'/resources/src/MyClassDrupal.php',
111+
$this->getResourcePath('src/MyClassDrupal.php'),
112112
];
113113
$locale = 'da';
114114

tests/Unit/Extractor/PoFileDumperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Drupal\drupal_translation_extractor\Test\Unit\AbstractTestCase;
88
use Drupal\drupal_translation_extractor\Translation\Dumper\PoFileDumper;
9-
use Drupal\drupal_translation_extractor\Translation\TwigExtractor;
9+
use Drupal\drupal_translation_extractor\Twig\Extractor\TwigExtractor;
1010
use Symfony\Component\Translation\MessageCatalogue;
1111

1212
final class PoFileDumperTest extends AbstractTestCase
1313
{
1414
public function testFormatCatalogDa(): void
1515
{
16-
$resource = __DIR__.'/resources/';
16+
$resource = $this->getResourcePath();
1717
$locale = 'da';
1818

1919
$extractor = new TwigExtractor($this->createTwig());
@@ -48,7 +48,7 @@ public function testFormatCatalogDa(): void
4848

4949
public function testFormatCatalogDaWithPrefix(): void
5050
{
51-
$resource = __DIR__.'/resources/';
51+
$resource = $this->getResourcePath();
5252
$locale = 'da';
5353

5454
$extractor = new TwigExtractor($this->createTwig());
@@ -89,7 +89,7 @@ public function testFormatCatalogDaWithPrefix(): void
8989

9090
public function testFormatCatalogPl(): void
9191
{
92-
$resource = __DIR__.'/resources/';
92+
$resource = $this->getResourcePath();
9393
$locale = 'pl';
9494

9595
$extractor = new TwigExtractor($this->createTwig());

0 commit comments

Comments
 (0)