mirror of
https://ghproxy.net/https://github.com/wp-cli/wp-config-transformer.git
synced 2025-10-04 05:21:55 +08:00
PHPStan level 9
This commit is contained in:
parent
844224df72
commit
f1d9f93c65
2 changed files with 32 additions and 17 deletions
11
phpstan.neon.dist
Normal file
11
phpstan.neon.dist
Normal file
|
@ -0,0 +1,11 @@
|
|||
parameters:
|
||||
level: 9
|
||||
paths:
|
||||
- src
|
||||
scanDirectories:
|
||||
- vendor/wp-cli/wp-cli/php
|
||||
scanFiles:
|
||||
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
|
||||
treatPhpDocTypesAsCertain: false
|
||||
ignoreErrors:
|
||||
- identifier: missingType.parameter
|
|
@ -26,7 +26,7 @@ class WPConfigTransformer {
|
|||
/**
|
||||
* Array of parsed configs.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, array<string, array{src: string, value: string, parts: array<string>}>>
|
||||
*/
|
||||
protected $wp_configs = array();
|
||||
|
||||
|
@ -64,7 +64,7 @@ class WPConfigTransformer {
|
|||
* @return bool
|
||||
*/
|
||||
public function exists( $type, $name ) {
|
||||
$wp_config_src = file_get_contents( $this->wp_config_path );
|
||||
$wp_config_src = (string) file_get_contents( $this->wp_config_path );
|
||||
|
||||
if ( ! trim( $wp_config_src ) ) {
|
||||
throw new Exception( 'Config file is empty.' );
|
||||
|
@ -92,7 +92,7 @@ class WPConfigTransformer {
|
|||
* @return string|null
|
||||
*/
|
||||
public function get_value( $type, $name ) {
|
||||
$wp_config_src = file_get_contents( $this->wp_config_path );
|
||||
$wp_config_src = (string) file_get_contents( $this->wp_config_path );
|
||||
|
||||
if ( ! trim( $wp_config_src ) ) {
|
||||
throw new Exception( 'Config file is empty.' );
|
||||
|
@ -114,10 +114,10 @@ class WPConfigTransformer {
|
|||
* @throws Exception If the config value provided is not a string.
|
||||
* @throws Exception If the config placement anchor could not be located.
|
||||
*
|
||||
* @param string $type Config type (constant or variable).
|
||||
* @param string $name Config name.
|
||||
* @param string $value Config value.
|
||||
* @param array $options (optional) Array of special behavior options.
|
||||
* @param string $type Config type (constant or variable).
|
||||
* @param string $name Config name.
|
||||
* @param string $value Config value.
|
||||
* @param array<string, bool|string> $options (optional) Array of special behavior options.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -164,10 +164,10 @@ class WPConfigTransformer {
|
|||
*
|
||||
* @throws Exception If the config value provided is not a string.
|
||||
*
|
||||
* @param string $type Config type (constant or variable).
|
||||
* @param string $name Config name.
|
||||
* @param string $value Config value.
|
||||
* @param array $options (optional) Array of special behavior options.
|
||||
* @param string $type Config type (constant or variable).
|
||||
* @param string $name Config name.
|
||||
* @param string $value Config value.
|
||||
* @param array<string, bool> $options (optional) Array of special behavior options.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -194,6 +194,10 @@ class WPConfigTransformer {
|
|||
|
||||
$old_src = $this->wp_configs[ $type ][ $name ]['src'];
|
||||
$old_value = $this->wp_configs[ $type ][ $name ]['value'];
|
||||
|
||||
/**
|
||||
* @var string $new_value
|
||||
*/
|
||||
$new_value = $this->format_value( $value, $raw );
|
||||
|
||||
if ( $normalize ) {
|
||||
|
@ -204,7 +208,7 @@ class WPConfigTransformer {
|
|||
$new_src = implode( '', $new_parts );
|
||||
}
|
||||
|
||||
$contents = preg_replace(
|
||||
$contents = (string) preg_replace(
|
||||
sprintf( '/(?<=^|;|<\?php\s|<\?\s)(\s*?)%s/m', preg_quote( trim( $old_src ), '/' ) ),
|
||||
'$1' . str_replace( '$', '\$', trim( $new_src ) ),
|
||||
$this->wp_config_src
|
||||
|
@ -238,7 +242,7 @@ class WPConfigTransformer {
|
|||
);
|
||||
}
|
||||
|
||||
$contents = preg_replace( $pattern, '', $this->wp_config_src );
|
||||
$contents = (string) preg_replace( $pattern, '', $this->wp_config_src );
|
||||
|
||||
return $this->save( $contents );
|
||||
}
|
||||
|
@ -251,7 +255,7 @@ class WPConfigTransformer {
|
|||
* @param string $value Config value.
|
||||
* @param bool $raw Display value in raw format without quotes.
|
||||
*
|
||||
* @return mixed
|
||||
* @return bool|float|int|string|null
|
||||
*/
|
||||
protected function format_value( $value, $raw ) {
|
||||
if ( $raw && '' === trim( $value ) ) {
|
||||
|
@ -268,7 +272,7 @@ class WPConfigTransformer {
|
|||
*
|
||||
* @param string $type Config type (constant or variable).
|
||||
* @param string $name Config name.
|
||||
* @param mixed $value Config value.
|
||||
* @param bool|float|int|string|null $value Config value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -289,7 +293,7 @@ class WPConfigTransformer {
|
|||
*
|
||||
* @param string $src Config file source.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string, array<string, array{src: string, value: string, parts: array<string>}>>
|
||||
*/
|
||||
protected function parse_wp_config( $src ) {
|
||||
$configs = array();
|
||||
|
@ -302,7 +306,7 @@ class WPConfigTransformer {
|
|||
if ( '//' === $token[1] ) {
|
||||
// For empty line comments, actually remove empty line comments instead of all double-slashes.
|
||||
// See: https://github.com/wp-cli/wp-config-transformer/issues/47
|
||||
$src = preg_replace( '/' . preg_quote( '//', '/' ) . '$/m', '', $src );
|
||||
$src = (string) preg_replace( '/' . preg_quote( '//', '/' ) . '$/m', '', $src );
|
||||
} else {
|
||||
$src = str_replace( $token[1], '', $src );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue