Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
<exclude-pattern>*/src/*(Extractor|Generator|Scanner)\.php$</exclude-pattern>
<exclude-pattern>*/src/ParsedComment\.php$</exclude-pattern>
<exclude-pattern>*/tests/includes/TestIterableCodeExtractor\.php$</exclude-pattern>
</rule>

<!-- Whitelist property name for a a JSON-decoded object. -->
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ parameters:
paths:
- src
- i18n-command.php
- tests
excludePaths:
- tests/data
- tests/phpstan/scan-files.php
scanDirectories:
- vendor/wp-cli/wp-cli/php
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- tests/phpstan/scan-files.php
- vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.php

treatPhpDocTypesAsCertain: false

20 changes: 10 additions & 10 deletions tests/BladeGettextExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ private function extract( $blade, $domain = 'foo-theme' ) {
return $translations;
}

public function test_extracts_bound_prop_with_translation_function() {
public function test_extracts_bound_prop_with_translation_function(): void {
$translations = $this->extract(
'<x-alert :message="__(\'Hello\', \'foo-theme\')" />'
);

$this->assertNotNull( $translations->find( null, 'Hello' ) );
}

public function test_extracts_multiple_bound_props() {
public function test_extracts_multiple_bound_props(): void {
$translations = $this->extract(
'<x-no-results :title="__(\'Not found\', \'foo-theme\')" :subtitle="__(\'Try again\', \'foo-theme\')" />'
);
Expand All @@ -46,7 +46,7 @@ public function test_extracts_multiple_bound_props() {
$this->assertNotNull( $translations->find( null, 'Try again' ) );
}

public function test_extracts_bound_props_from_multiline_component_tag() {
public function test_extracts_bound_props_from_multiline_component_tag(): void {
$blade = <<<'BLADE'
<x-no-results
:title="__('Page not found', 'foo-theme')"
Expand All @@ -60,7 +60,7 @@ public function test_extracts_bound_props_from_multiline_component_tag() {
$this->assertNotNull( $translations->find( null, 'Please try again' ) );
}

public function test_extracts_bound_props_from_open_component_tag() {
public function test_extracts_bound_props_from_open_component_tag(): void {
$blade = <<<'BLADE'
<x-alert :message="__('Warning message', 'foo-theme')">
{!! __('Content inside', 'foo-theme') !!}
Expand All @@ -73,7 +73,7 @@ public function test_extracts_bound_props_from_open_component_tag() {
$this->assertNotNull( $translations->find( null, 'Content inside' ) );
}

public function test_ignores_static_props() {
public function test_ignores_static_props(): void {
$translations = $this->extract(
'<x-alert type="warning" :message="__(\'Hello\', \'foo-theme\')" />'
);
Expand All @@ -82,7 +82,7 @@ public function test_ignores_static_props() {
$this->assertNull( $translations->find( null, 'warning' ) );
}

public function test_does_not_match_non_component_html() {
public function test_does_not_match_non_component_html(): void {
$translations = $this->extract(
'<a href="https://example.com">{{ __(\'Link text\', \'foo-theme\') }}</a>'
);
Expand All @@ -92,7 +92,7 @@ public function test_does_not_match_non_component_html() {
$this->assertCount( 1, $translations );
}

public function test_extracts_context_function_in_prop() {
public function test_extracts_context_function_in_prop(): void {
$translations = $this->extract(
'<x-button :label="_x(\'Read\', \'verb\', \'foo-theme\')" />'
);
Expand All @@ -101,7 +101,7 @@ public function test_extracts_context_function_in_prop() {
$this->assertNotNull( $translation );
}

public function test_extracts_esc_functions_in_props() {
public function test_extracts_esc_functions_in_props(): void {
$blade = <<<'BLADE'
<x-field
:label="esc_html__('Username', 'foo-theme')"
Expand All @@ -115,15 +115,15 @@ public function test_extracts_esc_functions_in_props() {
$this->assertNotNull( $translations->find( null, 'Enter username' ) );
}

public function test_extracts_single_quoted_bound_props() {
public function test_extracts_single_quoted_bound_props(): void {
$translations = $this->extract(
"<x-alert :message='__(\"Single quoted\", \"foo-theme\")' />"
);

$this->assertNotNull( $translations->find( null, 'Single quoted' ) );
}

public function test_existing_blade_extraction_still_works() {
public function test_existing_blade_extraction_still_works(): void {
$blade = <<<'BLADE'
@php
__('PHP block string', 'foo-theme');
Expand Down
10 changes: 5 additions & 5 deletions tests/FileDataExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use WP_CLI\Tests\TestCase;

class FileDataExtractorTest extends TestCase {
public function test_extracts_headers_with_line_numbers() {
public function test_extracts_headers_with_line_numbers(): void {
$text = <<<'TEXT'
<?php
/**
Expand Down Expand Up @@ -38,7 +38,7 @@ public function test_extracts_headers_with_line_numbers() {
$this->assertEquals( 5, $headers['Version']['line'] );
}

public function test_line_numbers_with_different_line_endings() {
public function test_line_numbers_with_different_line_endings(): void {
// Test with different line positions
$text = "<?php\n\n\n/**\n * Plugin Name: Test Plugin\n * Description: Description here\n */";

Expand All @@ -57,7 +57,7 @@ public function test_line_numbers_with_different_line_endings() {
$this->assertEquals( 6, $headers['Description']['line'] );
}

public function test_empty_headers_with_line_numbers() {
public function test_empty_headers_with_line_numbers(): void {
$text = '<?php // No headers here';

$headers = FileDataExtractor::get_file_data_from_string(
Expand All @@ -72,7 +72,7 @@ public function test_empty_headers_with_line_numbers() {
$this->assertEquals( 0, $headers['Plugin Name']['line'] );
}

public function test_theme_headers_with_line_numbers() {
public function test_theme_headers_with_line_numbers(): void {
$text = <<<'TEXT'
/*
Theme Name: My Theme
Expand Down Expand Up @@ -105,7 +105,7 @@ public function test_theme_headers_with_line_numbers() {
$this->assertEquals( 5, $headers['Version']['line'] );
}

public function test_header_with_trailing_comment() {
public function test_header_with_trailing_comment(): void {
$text = <<<'TEXT'
<?php
/**
Expand Down
Loading
Loading