Skip to content

Commit 3426e8f

Browse files
committed
Refactored
1 parent 6a1353e commit 3426e8f

28 files changed

+64
-167
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\Extractor\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\Extractor\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
/**

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
{

src/Translation/TwigExtractor.php renamed to src/Twig/Translation/Extractor/TwigExtractor.php

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\Translation\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;

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\Translation\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/resources/my_module.install

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/Unit/Extractor/resources/my_module.module

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)