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
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
},
"require-dev": {
"wp-cli/extension-command": "^1.2 || ^2",
"wp-cli/wp-cli-tests": "^4"
"wp-cli/wp-cli-tests": "^5"
},
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
"johnpbloch/wordpress-core-installer": true,
"phpstan/extension-installer": true
},
"lock": false
},
Expand Down Expand Up @@ -52,12 +53,14 @@
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpstan": "run-phpstan-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpstan",
"@phpunit",
"@behat"
]
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
level: 9
paths:
- src
- checksum-command.php
scanDirectories:
- vendor/wp-cli/wp-cli/php
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.parameter
- identifier: missingType.return
9 changes: 8 additions & 1 deletion src/Checksum_Base_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
* @return mixed
*/
protected static function _read( $url ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Could be used in classes extending this class.
$headers = array( 'Accept' => 'application/json' );
$headers = array( 'Accept' => 'application/json' );

Check warning on line 31 in src/Checksum_Base_Command.php

View check run for this annotation

Codecov / codecov/patch

src/Checksum_Base_Command.php#L31

Added line #L31 was not covered by tests

/**
* @var \WpOrg\Requests\Response $response
*/
$response = Utils\http_request(
'GET',
$url,
Expand Down Expand Up @@ -64,6 +68,9 @@
),
RecursiveIteratorIterator::CHILD_FIRST
);
/**
* @var \SplFileInfo $file_info
*/
foreach ( $files as $file_info ) {
if ( $file_info->isFile() ) {
$filtered_files[] = self::normalize_directory_separators( substr( $file_info->getPathname(), strlen( $path ) ) );
Expand Down
10 changes: 6 additions & 4 deletions src/Checksum_Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public function __invoke( $args, $assoc_args ) {
}

if ( ! empty( $assoc_args['exclude'] ) ) {
$this->exclude_files = explode( ',', Utils\get_flag_value( $assoc_args, 'exclude', '' ) );
$exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' );

$this->exclude_files = explode( ',', $exclude );
}

if ( empty( $wp_version ) ) {
Expand All @@ -110,7 +112,7 @@ public function __invoke( $args, $assoc_args ) {
}
}

$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );

try {
Expand Down Expand Up @@ -205,7 +207,7 @@ private static function get_wp_details() {
);
}

$version_content = file_get_contents( $versions_path, false, null, 6, 2048 );
$version_content = (string) file_get_contents( $versions_path, false, null, 6, 2048 );

$vars = [ 'wp_version', 'wp_db_version', 'tinymce_version', 'wp_local_package' ];
$result = [];
Expand All @@ -227,7 +229,7 @@ private static function get_wp_details() {
* @param string $var_name Variable name to search for.
* @param string $code PHP code to search in.
*
* @return int|string|null
* @return string|null
*/
private static function find_var( $var_name, $code ) {
$start = strpos( $code, '$' . $var_name . ' = ' );
Expand Down
29 changes: 18 additions & 11 deletions src/Checksum_Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ class Checksum_Plugin_Command extends Checksum_Base_Command {
*/
public function __invoke( $args, $assoc_args ) {

$fetcher = new Fetchers\UnfilteredPlugin();
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
$strict = (bool) Utils\get_flag_value( $assoc_args, 'strict', false );
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
$plugins = $fetcher->get_many( $all ? $this->get_all_plugin_names() : $args );
$fetcher = new Fetchers\UnfilteredPlugin();
$all = Utils\get_flag_value( $assoc_args, 'all', false );
$strict = Utils\get_flag_value( $assoc_args, 'strict', false );
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
$plugins = $fetcher->get_many( $all ? $this->get_all_plugin_names() : $args );

/**
* @var string $exclude
*/
$exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' );
$version_arg = isset( $assoc_args['version'] ) ? $assoc_args['version'] : '';

Expand Down Expand Up @@ -112,6 +116,9 @@ public function __invoke( $args, $assoc_args ) {
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );

try {
/**
* @var array|false $checksums
*/
$checksums = $wp_org_api->get_plugin_checksums( $plugin->name, $version );
} catch ( Exception $exception ) {
WP_CLI::warning( $exception->getMessage() );
Expand Down Expand Up @@ -167,12 +174,12 @@ public function __invoke( $args, $assoc_args ) {
private function verify_hello_dolly_from_core( $assoc_args ) {
$file = 'hello.php';
$wp_version = get_bloginfo( 'version', 'display' );
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
$locale = '';
$locale = 'en_US';

try {
$checksums = $wp_org_api->get_core_checksums( $wp_version, empty( $locale ) ? 'en_US' : $locale );
$checksums = $wp_org_api->get_core_checksums( $wp_version, $locale );
} catch ( Exception $exception ) {
WP_CLI::error( $exception );
}
Expand Down Expand Up @@ -262,7 +269,7 @@ private function get_plugin_files( $path ) {
* integrity of.
* @param array $checksums Array of provided checksums to compare against.
*
* @return true|string
* @return bool|string
*/
private function check_file_checksum( $path, $checksums ) {
if ( $this->supports_sha256()
Expand Down Expand Up @@ -299,7 +306,7 @@ private function supports_sha256() {
* @param string $filepath Absolute path to the file to calculate the SHA-2
* for.
*
* @return string
* @return string|false
*/
private function get_sha256( $filepath ) {
return hash_file( 'sha256', $filepath );
Expand All @@ -311,7 +318,7 @@ private function get_sha256( $filepath ) {
* @param string $filepath Absolute path to the file to calculate the MD5
* for.
*
* @return string
* @return string|false
*/
private function get_md5( $filepath ) {
return hash_file( 'md5', $filepath );
Expand Down
2 changes: 1 addition & 1 deletion src/WP_CLI/Fetchers/UnfilteredPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UnfilteredPlugin extends Base {
/**
* Get a plugin object by name.
*
* @param string $name
* @param string|int $name
*
* @return object|false
*/
Expand Down