Skip to content
Open
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
295 changes: 186 additions & 109 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Build_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Build_Command extends \WP_CLI_Command {

/**
* Installs wordpress, plugins and themes.
* Installs WordPress, plugins and themes.
*
* ## OPTIONS
*
Expand Down Expand Up @@ -67,7 +67,7 @@ class Build_Command extends \WP_CLI_Command {
*
* @when before_wp_load
*/
public function __invoke( $args = NULL, $assoc_args = NULL ) {
public function __invoke( $args = null, $assoc_args = null ) {

$build_filename = Utils::get_build_filename( $assoc_args );
WP_CLI::line( WP_CLI::colorize( "%GParsing %W$build_filename%n%G, please wait...%n" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/Build_Generate_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Build_Generate_Command extends \WP_CLI_Command {
* wp build-generate --output=production.yml
*
*/
public function __invoke( $args = NULL, $assoc_args = NULL ) {
public function __invoke( $args = null, $assoc_args = null ) {

// Build file.
$build_filename = Utils::get_build_filename( $assoc_args );
Expand Down
32 changes: 16 additions & 16 deletions src/Build_Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

class Build_Parser {

private $filename = 'build.json';
private $format = 'json';
private $build = [];
private mixed $filename = 'build.json';
private string $format = 'json';
private array $build = [];

public function __construct( $filename, $assoc_args = NULL ) {
public function __construct( $filename, $assoc_args = null ) {
// Set Build file.
$this->filename = empty( $filename ) ? 'build.json' : $filename;
// Set format.
$this->format = ( strpos( $this->filename, 'yml' ) !== FALSE ) ? 'yml' : 'json';
$this->format = (str_contains($this->filename, 'yml')) ? 'yml' : 'json';
// Parse the Build file and Build sure it's valid.
$this->parse();
}

private function parse() {
private function parse(): void
{
// Full Build file path.
$file_path = ( Utils::is_absolute_path( $this->filename ) ) ? $this->filename : realpath( '.' ) . '/' . $this->filename;
// Set specified path with --path argument.
Expand All @@ -28,7 +29,7 @@ private function parse() {
}
// Check if the file exists.
if ( ! file_exists( $file_path ) ) {
return NULL;
return;
}
// Check if the Build file is a valid yaml file.
if ( $this->format == 'yml' ) {
Expand All @@ -37,10 +38,10 @@ private function parse() {
} catch ( \Exception $e ) {
WP_CLI::error( 'Error parsing YAML from Build file (' . $this->filename . ').' );

return FALSE;
return;
}

return TRUE;
return;
}

// Build.json
Expand All @@ -49,13 +50,12 @@ private function parse() {
} catch ( \Exception $e ) {
WP_CLI::error( 'Error parsing JSON from Build file (' . $this->filename . ').' );

return FALSE;
return;
}

return TRUE;
}
}

public function get( $key = NULL, $sub_key = NULL ) {
public function get( $key = null, $sub_key = null ) {

// With subkey.
if ( ! empty( $this->build[ $key ][ $sub_key ] ) ) {
Expand All @@ -75,22 +75,22 @@ public function get_core_version() {
return $this->build['core']['download']['version'];
}

return NULL;
return null;
}

public function get_plugin_version( $slug ) {
if ( ! empty( $this->build['plugins'][ $slug ]['version'] ) ) {
return $this->build['plugins'][ $slug ]['version'];
}

return NULL;
return null;
}

public function get_theme_version( $slug ) {
if ( ! empty( $this->build['themes'][ $slug ]['version'] ) ) {
return $this->build['themes'][ $slug ]['version'];
}

return NULL;
return null;
}
}
51 changes: 32 additions & 19 deletions src/Helper/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

class Utils {

public static function wp_config_exists() {
public static function wp_config_exists(): bool
{
if ( ( file_exists( realpath( '.' ) . '/wp-config.php' ) ) || ( file_exists( ABSPATH . '/wp-config.php' ) ) ) {
return TRUE;
}
Expand All @@ -21,7 +22,8 @@ public static function wp_config_exists() {
}

// Return WP version.
public static function wp_version() {
public static function wp_version(): bool|string
{
$result = self::launch_self( 'core', [ 'version' ], [], FALSE, TRUE, [], FALSE, FALSE );
if ( ! empty( $result->stdout ) ) {
return trim( $result->stdout );
Expand All @@ -31,7 +33,8 @@ public static function wp_version() {
}

// Check if WP is installed.
public static function wp_installed() {
public static function wp_installed(): bool
{
$result = self::launch_self( 'core', [ 'is-installed' ], [], FALSE, TRUE, [], FALSE, FALSE );
if ( ! empty( $result->return_code ) ) {
return FALSE;
Expand All @@ -40,7 +43,8 @@ public static function wp_installed() {
return TRUE;
}

public static function wp_path( $path = NULL ) {
public static function wp_path( $path = null ): string
{
$wp_path = ABSPATH;
if ( ! empty( $path ) ) {
$wp_path = ( ( ! self::is_absolute_path( ABSPATH ) ) || ( $wp_path == '/' ) ) ? getcwd() . '/' . $path : $wp_path . '/' . $path;
Expand All @@ -50,11 +54,12 @@ public static function wp_path( $path = NULL ) {
}

public static function line( $text, $pseudo_tab = FALSE ) {
$spaces = ( $pseudo_tab ) ? ' ' : NULL;
$spaces = ( $pseudo_tab ) ? ' ' : null;
echo $spaces . WP_CLI::colorize( $text );
}

public static function prompt( $question ) {
public static function prompt( $question ): bool|string
{
if ( function_exists( 'readline' ) ) {
return readline( $question );
} else {
Expand All @@ -64,7 +69,8 @@ public static function prompt( $question ) {
}
}

public static function is_absolute_path( $path ) {
public static function is_absolute_path( $path ): bool
{
if ( ! is_string( $path ) ) {
$mess = sprintf( 'String expected but was given %s', gettype( $path ) );
throw new \InvalidArgumentException( $mess );
Expand Down Expand Up @@ -113,7 +119,8 @@ public static function launch_self( $command, $args = [], $assoc_args = [], $exi
return $result;
}

private static function get_launch_self_workaround_command( $command = NULL, $args = [], $assoc_args = [], $runtime_args = [] ) {
private static function get_launch_self_workaround_command( $command = null, $args = [], $assoc_args = [], $runtime_args = [] ): string
{
$reused_runtime_args = [
'path',
'url',
Expand Down Expand Up @@ -142,7 +149,8 @@ private static function get_launch_self_workaround_command( $command = NULL, $ar
return "WP_CLI_CACHE_DIR={$cache_dir} WP_CLI_CONFIG_PATH={$config_path} {$php_bin} {$script_path} {$command} {$args} {$assoc_args}";
}

public static function item_download( $type = NULL, $slug = NULL, $version = NULL ) {
public static function item_download( $type = null, $slug = null, $version = null ): bool|string|null
{
if ( ( ! empty( $slug ) ) && ( $type == 'plugin' || $type == 'theme' ) && ( ! empty( $version ) ) ) {
$info_fn = $type . '_info';
$info = WP_API::$info_fn( $slug, $version );
Expand All @@ -151,9 +159,9 @@ public static function item_download( $type = NULL, $slug = NULL, $version = NUL
}
// Status message.
$status = '';
// Uses custom 'version_link' to download the item.
if ( ! empty( $info->version_link ) ) {
$failed_version_download = FALSE;
$failed_version_download = FALSE;
// Uses custom 'version_link' to download the item.
if ( ! empty( $info->version_link ) ) {
$filename = basename( $info->version_link );
if ( ! empty( $filename ) ) {
$download = Utils::download_url( $info->version_link );
Expand Down Expand Up @@ -199,7 +207,8 @@ public static function item_download( $type = NULL, $slug = NULL, $version = NUL
return NULL;
}

public static function download_url( $url = NULL ) {
public static function download_url( $url = null ): bool|int|string
{
// If we have an URL proceed.
if ( ! empty( $url ) ) {
$filename = basename( $url );
Expand Down Expand Up @@ -228,7 +237,8 @@ public static function download_url( $url = NULL ) {
return FALSE;
}

public static function item_unzip( $type, $filename ) {
public static function item_unzip( $type, $filename ): bool
{
$file_path = self::wp_path( 'wp-content/' . $filename );
if ( file_exists( $file_path ) ) {
if ( self::unzip( $file_path, Utils::wp_path( 'wp-content/' . $type . 's/' ) ) ) {
Expand All @@ -239,7 +249,8 @@ public static function item_unzip( $type, $filename ) {
return FALSE;
}

public static function unzip( $file, $to, $delete = TRUE ) {
public static function unzip( $file, $to, $delete = TRUE ): bool
{
if ( ( ! empty( $file ) ) && ( ! empty( $to ) ) ) {

// Create the directory to extract to.
Expand Down Expand Up @@ -271,7 +282,8 @@ public static function unzip( $file, $to, $delete = TRUE ) {
return FALSE;
}

public static function mkdir( $dir = NULL ) {
public static function mkdir( $dir = null ): bool|string
{
if ( ! empty( $dir ) ) {
if ( ! file_exists( $dir ) ) {
$fs = new Filesystem();
Expand All @@ -293,7 +305,8 @@ public static function mkdir( $dir = NULL ) {
}

// Print success or error message.
public static function result( $result = NULL ) {
public static function result( $result = null ): bool
{
if ( ! empty( $result ) ) {
// Success.
if ( ! empty( $result->stdout ) && ( empty( $result->stderr ) ) ) {
Expand All @@ -314,7 +327,7 @@ public static function result( $result = NULL ) {

public static function convert_to_numeric( $version = NULL ) {
if ( ( ! empty( $version ) ) && ( is_numeric( $version ) ) ) {
return strpos( $version, '.' ) === FALSE ? (int) $version : (float) $version;
return !str_contains($version, '.') ? (int) $version : (float) $version;
}

return $version;
Expand Down Expand Up @@ -408,4 +421,4 @@ public static function determine_version( $item_version, $wporg_latest, $wporg_v
return $item_version;
}

}
}
4 changes: 2 additions & 2 deletions src/Helper/WP_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class WP_API {

public static function core_version_check( $config_version = NULL ) {
public static function core_version_check( $config_version = null ) {
$response = Requests::get( 'http://api.wordpress.org/core/version-check/1.7/' );
if ( ! empty( $response->body ) ) {
$core = json_decode( $response->body );
Expand Down Expand Up @@ -94,4 +94,4 @@ private static function _get_item_download_link( $item, $version ) {

}

}
}
Loading