Skip to content

Commit

Permalink
Merge pull request #15 from pluswerk/feature/grumphp-0.19
Browse files Browse the repository at this point in the history
✨ make compatible with grumphp 0.19
  • Loading branch information
Kanti authored Jun 15, 2020
2 parents 9f8d209 + 7d29e00 commit dc971f6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ git:
php:
- 7.2
- 7.3
- 7.4
- nightly

env:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
}
},
"require": {
"ext-dom": "*",
"php": ">=7.2",
"phpro/grumphp": "0.16.* || 0.17.*"
"phpro/grumphp": "0.19.*"
},
"require-dev": {
"squizlabs/php_codesniffer": ">=3.5.0 <4.0.0"
Expand Down
16 changes: 5 additions & 11 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
parameters:
git_dir: .
bin_dir: vendor/bin
stop_on_failure: false
ignore_unstaged_changes: false #brocken
grumphp:
tasks:
composer:
with_dependencies: false
Expand All @@ -14,16 +10,14 @@ parameters:
- "exit;"
triggered_by: [php]
git_commit_message:
matchers:
- /(\[(!!!|WIP)]|)(\[(BUGFIX|FEATURE|TASK|CLEANUP|SECURITY)]|Merge branch '.+' into) .+/
case_insensitive: false
multiline: true
additional_modifiers: ''
max_subject_width: 120
max_body_width: 120
enforce_capitalized_subject: false
jsonlint:
detect_key_conflicts: true
phpcs:
standard: "PSR12"
warning_severity: 900000
warning_severity: 0
tab_width: 4
yamllint: ~
xlifflint: ~
Expand Down
3 changes: 1 addition & 2 deletions src/ExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ public function load(ContainerBuilder $container)
{
$container->register('linter.xlifflint', XliffLinter::class);
return $container->register('task.xlifflint', XliffLint::class)
->addArgument(new Reference('config'))
->addArgument(new Reference('linter.xlifflint'))
->addArgument(new Reference('process_builder'))
->addArgument(new Reference('formatter.raw_process'))
->addTag('grumphp.task', ['config' => 'xlifflint']);
->addTag('grumphp.task', ['task' => 'xlifflint']);
}
}
19 changes: 7 additions & 12 deletions src/XliffLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ class XliffLint extends AbstractLinterTask
/** @var XliffLinter */
protected $linter;

public function getName(): string
{
return 'xlifflint';
}

public function getConfigurableOptions(): OptionsResolver
public static function getConfigurableOptions(): OptionsResolver
{
$resolver = parent::getConfigurableOptions();
$resolver->setDefaults(
Expand All @@ -48,15 +43,15 @@ public function canRunInContext(ContextInterface $context): bool

public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
$options = $this->getConfig()->getOptions();
$files = $context->getFiles()->extensions($options['triggered_by']);
if (0 === count($files)) {
return TaskResult::createSkipped($this, $context);
}
$this->linter->setLoadFromNet($config['load_from_net']);
$this->linter->setXInclude($config['x_include']);
$this->linter->setDtdValidation($config['dtd_validation']);
$this->linter->setSchemeValidation($config['scheme_validation']);
$this->linter->setLoadFromNet($options['load_from_net']);
$this->linter->setXInclude($options['x_include']);
$this->linter->setDtdValidation($options['dtd_validation']);
$this->linter->setSchemeValidation($options['scheme_validation']);
try {
$lintErrors = $this->lint($files);
} catch (RuntimeException $e) {
Expand Down
9 changes: 5 additions & 4 deletions src/XliffLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PLUS\GrumPHPXliffTask;

use DOMDocument;
use GrumPHP\Collection\LintErrorsCollection;
use GrumPHP\Linter\LintError;
use GrumPHP\Linter\Xml\XmlLinter;
Expand All @@ -15,7 +16,7 @@ public function lint(SplFileInfo $file): LintErrorsCollection
if ($lintErrors->count()) {
return $lintErrors;
}
$document = new \DOMDocument();
$document = new DOMDocument();
if (!$document->load($file->getPathname())) {
$lintErrors->add(
new LintError(
Expand All @@ -29,7 +30,7 @@ public function lint(SplFileInfo $file): LintErrorsCollection
}

$rootElement = $document->documentElement;
/** @var \DOMElement[] $fileTags */
/** @var DOMElement[] $fileTags */
$fileTags = $rootElement->getElementsByTagName('file');
foreach ($fileTags as $fileTag) {
if ($fileTag->attributes->getNamedItem('target')) {
Expand All @@ -44,7 +45,7 @@ public function lint(SplFileInfo $file): LintErrorsCollection
continue;
}
if ($fileTag->attributes->getNamedItem('target-language')) {
/** @var \DOMElement[] $transUnitTags */
/** @var DOMElement[] $transUnitTags */
$transUnitTags = $fileTag->getElementsByTagName('trans-unit');
foreach ($transUnitTags as $transUnitTag) {
if (!$transUnitTag->attributes->getNamedItem('id')) {
Expand All @@ -69,7 +70,7 @@ public function lint(SplFileInfo $file): LintErrorsCollection
}
}
} else {
/** @var \DOMElement[] $transUnitTags */
/** @var DOMElement[] $transUnitTags */
$transUnitTags = $fileTag->getElementsByTagName('trans-unit');
foreach ($transUnitTags as $transUnitTag) {
if (!$transUnitTag->attributes->getNamedItem('id')) {
Expand Down

0 comments on commit dc971f6

Please sign in to comment.