Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Jun 24, 2023
1 parent 222501a commit b5d6873
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 79 deletions.
2 changes: 2 additions & 0 deletions build-cs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^1.10",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-phpunit": "^1.2",
"slevomat/coding-standard": "^8.9",
"szepeviktor/phpstan-wordpress": "^1.1",
"swissspidy/phpstan-no-private": "^0.2",
"wp-coding-standards/wpcs": "dev-develop#fca9d9e"
},
"config": {
Expand Down
167 changes: 136 additions & 31 deletions build-cs/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"wp-coding-standards/wpcs": "dev-develop",
"yoast/phpunit-polyfills": "^1.0.1"
},
"suggest": {
"ext-json": "Needed for supporting JSON translation files"
},
"minimum-stability": "dev",
"config": {
"allow-plugins": {
Expand Down
13 changes: 2 additions & 11 deletions lib/class-ginger-mo-translation-file-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ protected function parse_file() {
$data = json_decode( $data, true );

if ( ! $data || ! is_array( $data ) ) {
$this->error = true;
if ( function_exists( 'json_last_error_msg' ) ) {
$this->error = 'JSON Error: ' . json_last_error_msg();
} elseif ( function_exists( 'json_last_error' ) ) {
$this->error = 'JSON Error code: ' . json_last_error();
}
$this->error = 'JSON Error: ' . json_last_error_msg();
return;
}

Expand Down Expand Up @@ -68,11 +63,7 @@ protected function create_file( $headers, $entries ) {
// Prefix as the first key.
$entries = array_merge( array( '' => $headers ), $entries );

if ( defined( 'JSON_PRETTY_PRINT' ) ) {
$json = json_encode( (array) $entries, JSON_PRETTY_PRINT );
} else {
$json = json_encode( (array) $entries );
}
$json = json_encode( (array) $entries, JSON_PRETTY_PRINT );

return (bool) file_put_contents( $this->file, $json );
}
Expand Down
14 changes: 7 additions & 7 deletions lib/class-ginger-mo-translation-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ public static function create( $file, $context = 'read', $filetype = null ) {

switch ( $filetype ) {
case 'mo':
$moe = new Ginger_MO_Translation_File_MO( $file, $context );
break;
return new Ginger_MO_Translation_File_MO( $file, $context );
case 'php':
$moe = new Ginger_MO_Translation_File_PHP( $file, $context );
break;
return new Ginger_MO_Translation_File_PHP( $file, $context );
case 'json':
$moe = new Ginger_MO_Translation_File_JSON( $file, $context );
if ( function_exists( 'json_decode' ) ) {
return new Ginger_MO_Translation_File_JSON( $file, $context );
}
break;
default:
$moe = false;
return false;
}

return $moe;
return false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ parameters:
paths:
- ginger-mo.php
- lib/
- tests/phpunit/unit/includes
- tests/phpunit/unit/tests
excludePaths:
- lib/class-plural-forms.php
bootstrapFiles:
Expand Down
3 changes: 3 additions & 0 deletions tests/phpstan/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

define( 'GINGER_MO_TEST_DATA', '' );
Loading

0 comments on commit b5d6873

Please sign in to comment.