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
33 changes: 17 additions & 16 deletions components/BlockParser/class-wpblockparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ class WP_Block_Parser {
* parse. In contrast to the specification parser this does not
* return an error on invalid inputs.
*
* @param string $document Input document being parsed.
* @param string $document Input document being parsed.
*
* @return array[]
* @since 5.0.0
*
*/
public function parse( $document ) {
$this->document = $document;
Expand Down Expand Up @@ -210,9 +209,12 @@ public function proceed() {
* block and add it as a new innerBlock to the parent
*/
$stack_top = array_pop( $this->stack );
$html = substr( $this->document, $stack_top->prev_offset,
$start_offset - $stack_top->prev_offset );
$stack_top->block->innerHTML .= $html;
$html = substr(
$this->document,
$stack_top->prev_offset,
$start_offset - $stack_top->prev_offset
);
$stack_top->block->innerHTML .= $html;
$stack_top->block->innerContent[] = $html;
$stack_top->prev_offset = $start_offset + $token_length;

Expand Down Expand Up @@ -289,7 +291,7 @@ public function next_token() {
* are associative arrays. If we use `array()` we get a JSON `[]`
*/
$attrs = $has_attrs
? json_decode( $matches['attrs'][0], /* as-associative */ true )
? json_decode( $matches['attrs'][0], /* as-associative. */ true )
: array();

/*
Expand All @@ -314,12 +316,11 @@ public function next_token() {
/**
* Returns a new block object for freeform HTML
*
* @param string $inner_html HTML content of block.
* @param string $inner_html HTML content of block.
*
* @return WP_Block_Parser_Block freeform block object.
* @internal
* @since 3.9.0
*
*/
public function freeform( $inner_html ) {
return new WP_Block_Parser_Block( null, array(), array(), $inner_html, array( $inner_html ) );
Expand All @@ -329,7 +330,7 @@ public function freeform( $inner_html ) {
* Pushes a length of text from the input document
* to the output list as a freeform block.
*
* @param null $length how many bytes of document text to output.
* @param null $length how many bytes of document text to output.
*
* @since 5.0.0
* @internal
Expand All @@ -348,10 +349,10 @@ public function add_freeform( $length = null ) {
* Given a block structure from memory pushes
* a new block to the output list.
*
* @param WP_Block_Parser_Block $block The block to add to the output.
* @param int $token_start Byte offset into the document where the first token for the block starts.
* @param int $token_length Byte length of entire block from start of opening token to end of closing token.
* @param int|null $last_offset Last byte offset into document if continuing form earlier output.
* @param WP_Block_Parser_Block $block The block to add to the output.
* @param int $token_start Byte offset into the document where the first token for the block starts.
* @param int $token_length Byte length of entire block from start of opening token to end of closing token.
* @param int|null $last_offset Last byte offset into document if continuing form earlier output.
*
* @internal
* @since 5.0.0
Expand All @@ -362,7 +363,7 @@ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $to
$html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );

if ( ! empty( $html ) ) {
$parent->block->innerHTML .= $html;
$parent->block->innerHTML .= $html;
$parent->block->innerContent[] = $html;
}

Expand All @@ -373,7 +374,7 @@ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $to
/**
* Pushes the top block from the parsing stack to the output list.
*
* @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML.
* @param int|null $end_offset byte offset into document for where we should stop sending text output as HTML.
*
* @since 5.0.0
* @internal
Expand All @@ -387,7 +388,7 @@ public function add_block_from_stack( $end_offset = null ) {
: substr( $this->document, $prev_offset );

if ( ! empty( $html ) ) {
$stack_top->block->innerHTML .= $html;
$stack_top->block->innerHTML .= $html;
$stack_top->block->innerContent[] = $html;
}

Expand Down
5 changes: 2 additions & 3 deletions components/BlockParser/class-wpblockparserblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ class WP_Block_Parser_Block {
*
* Will populate object properties from the provided arguments.
*
* @param string $name Name of block.
* @param string $name Name of block.
* @param array $attrs Optional set of attributes from block comment delimiters.
* @param array $inner_blocks List of inner blocks (of this same class).
* @param string $inner_html Resultant HTML from inside block comment delimiters after removing inner blocks.
* @param string $inner_html Resultant HTML from inside block comment delimiters after removing inner blocks.
* @param array $inner_content List of string fragments and null markers where inner blocks were found.
*
* @since 5.0.0
*
*/
public function __construct( $name, $attrs, $inner_blocks, $inner_html, $inner_content ) {
$this->blockName = $name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
Expand Down
4 changes: 2 additions & 2 deletions components/BlockParser/class-wpblockparsererror.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class WP_Block_Parser_Error extends Exception {
private $type;

const TYPE_SUSPICIOUS_DELIMITER = 'suspicious-delimiter';
const TYPE_MISMATCHED_CLOSER = 'mismatched-block-closer';
const TYPE_PARSE_ERROR = 'parse-error';
const TYPE_MISMATCHED_CLOSER = 'mismatched-block-closer';
const TYPE_PARSE_ERROR = 'parse-error';

public function __construct( $message, $type = self::TYPE_PARSE_ERROR, ?Exception $previous = null ) {
$this->type = $type;
Expand Down
13 changes: 6 additions & 7 deletions components/BlockParser/class-wpblockparserframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ class WP_Block_Parser_Frame {
*
* Will populate object properties from the provided arguments.
*
* @param WP_Block_Parser_Block $block Full or partial block.
* @param int $token_start Byte offset into document for start of parse token.
* @param int $token_length Byte length of entire parse token string.
* @param int|null $prev_offset Optional. Byte offset into document for after parse token ends. Default null.
* @param int|null $leading_html_start Optional. Byte offset into document where leading HTML before token starts.
* Default null.
* @param WP_Block_Parser_Block $block Full or partial block.
* @param int $token_start Byte offset into document for start of parse token.
* @param int $token_length Byte length of entire parse token string.
* @param int|null $prev_offset Optional. Byte offset into document for after parse token ends. Default null.
* @param int|null $leading_html_start Optional. Byte offset into document where leading HTML before token starts.
* Default null.
*
* @since 5.0.0
*
*/
public function __construct( $block, $token_start, $token_length, $prev_offset = null, $leading_html_start = null ) {
$this->block = $block;
Expand Down
12 changes: 6 additions & 6 deletions components/Blueprints/DataReference/class-absolutelocalpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class AbsoluteLocalPath extends DataReference {
/**
* Constructor.
*
* @param string $path The path.
* @param string $path The path.
*/
public function __construct( string $path ) {
$this->path = realpath($path);
$this->path = realpath( $path );
parent::__construct();
}

Expand All @@ -40,18 +40,18 @@ public function get_filename(): string {
* Checks if a string is a valid absolute local path. Useful
* for resolving a Blueprint reference to an actual file before
* we know the execution context.
*
*
* Windows paths can be really comples:
*
*
* https://www.fileside.app/blog/2023-03-17_windows-file-paths/
*
*
* Instead of parsing them, we'll just ask the OS whether the path exists.
*
* @param $path The path to check.
* @return bool Whether the path is valid.
*/
public static function is_valid( $path ): bool {
return false !== realpath($path);
return false !== realpath( $path );
}

/**
Expand Down
22 changes: 12 additions & 10 deletions components/Blueprints/DataReference/class-datareference.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ class DataReference {
*/
private static $instance_counter = 0;

public function __construct($original_definition = null) {
$this->id = self::$instance_counter ++;
public function __construct( $original_definition = null ) {
$this->id = self::$instance_counter++;
$this->original_definition = $original_definition;
}

static public function create( $reference, array $additional_reference_classes = [] ) {
$classes = array_merge( [
URLReference::class,
GitPath::class,
InlineDirectory::class,
InlineFile::class,
], $additional_reference_classes );
public static function create( $reference, array $additional_reference_classes = array() ) {
$classes = array_merge(
array(
URLReference::class,
GitPath::class,
InlineDirectory::class,
InlineFile::class,
),
$additional_reference_classes
);
foreach ( $classes as $class ) {
if ( $class::is_valid( $reference ) ) {
return new $class( $reference );
Expand All @@ -54,5 +57,4 @@ public function get_filename(): string {
public function get_human_readable_name(): string {
throw new NotImplementedException( 'get_human_readable_name is not implemented for this data reference' );
}

}
25 changes: 13 additions & 12 deletions components/Blueprints/DataReference/class-datareferenceresolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class DataReferenceResolver {
private $tmp_root;

public function __construct( Client $client, ?string $tmp_root = null ) {
$this->client = $client;
$this->tmp_root = $tmp_root ?: wp_unix_sys_get_temp_dir();
$this->client = $client;
$this->tmp_root = $tmp_root ? $tmp_root : wp_unix_sys_get_temp_dir();
}

public function setExecutionContext( ?Filesystem $execution_context ) {
Expand All @@ -58,8 +58,8 @@ public function setExecutionContext( ?Filesystem $execution_context ) {

public function startEagerResolution( array $data_references, Tracker $data_resolution_tracker ) {
$this->data_resolution_tracker = $data_resolution_tracker;
$this->data_references = $data_references;
$nb_data_references = count( $this->data_references );
$this->data_references = $data_references;
$nb_data_references = count( $this->data_references );
foreach ( $this->data_references as $data_reference ) {
$this->sub_trackers[ $data_reference->id ] = $this->data_resolution_tracker->stage(
1 / $nb_data_references,
Expand All @@ -70,6 +70,7 @@ public function startEagerResolution( array $data_references, Tracker $data_reso
}

/** Core service method shared by runner, target resolvers and steps
*
* @return File|Directory
*/
public function resolve( DataReference $reference ) {
Expand All @@ -80,10 +81,10 @@ public function resolve( DataReference $reference ) {
return $this->resolved_data_references[ $reference->id ];
}

// @TODO: Clean up the semantics of this class. Resolve() and separate resolve_uncached() seem confusing. There's
// a bunch of implicit behaviors related to caching. Ideally we would either have a self-contained resolution
// method, or co-locate the resolution logic with the data reference classes and only use this class for
// caching.
// @TODO: Clean up the semantics of this class. Resolve() and separate resolve_uncached() seem confusing. There's.
// a bunch of implicit behaviors related to caching. Ideally we would either have a self-contained resolution.
// method, or co-locate the resolution logic with the data reference classes and only use this class for.
// caching.
public function resolve_uncached( DataReference $reference ) {
$progress_tracker = $this->sub_trackers[ $reference->id ] ?? new Tracker();

Expand Down Expand Up @@ -122,8 +123,8 @@ public function resolve_uncached( DataReference $reference ) {
$tracked_stream,
$filename
);
// TODO: Consider a clearer name. Some not-so-great ballpark ideas:
// BlueprintParentPath, BlueprintRootPath, BlueprintContextPath, BlueprintRelativePath
// TODO: Consider a clearer name. Some not-so-great ballpark ideas:.
// BlueprintParentPath, BlueprintRootPath, BlueprintContextPath, BlueprintRelativePath.
} elseif ( $reference instanceof ExecutionContextPath ) {
$path = $reference->get_path();
if ( ! $this->execution_context->exists( $path ) ) {
Expand Down Expand Up @@ -175,7 +176,7 @@ public function resolve_uncached( DataReference $reference ) {
$client = $repo->get_remote_client( 'origin' );
$client->pull(
$reference->get_ref(),
// Sparse checkout
// Sparse checkout.
array(
'path' => $reference->get_path(),
'shallow' => true,
Expand All @@ -184,7 +185,7 @@ public function resolve_uncached( DataReference $reference ) {

return new Directory(
new ChrootLayer( GitFilesystem::create( $repo ), $reference->get_path() ),
basename( $reference->get_path() ) ?: 'git-repo'
basename( $reference->get_path() ) ? basename( $reference->get_path() ) : 'git-repo'
);
}

Expand Down
6 changes: 3 additions & 3 deletions components/Blueprints/DataReference/class-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Directory extends DataReference {
/**
* Constructor.
*
* @param Filesystem $filesystem The filesystem representing the directory content.
* @param string $dirname The name of the directory.
* @param Filesystem $filesystem The filesystem representing the directory content.
* @param string $dirname The name of the directory.
*/
public function __construct( Filesystem $filesystem, string $dirname ) {
$this->filesystem = $filesystem;
Expand All @@ -38,6 +38,6 @@ public function __construct( Filesystem $filesystem, string $dirname ) {
* @return string The human-readable name.
*/
public function get_human_readable_name(): string {
return "Directory: " . $this->dirname;
return 'Directory: ' . $this->dirname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ExecutionContextPath extends DataReference {
/**
* Constructor.
*
* @param string $path The path.
* @param string $path The path.
*/
public function __construct( string $path ) {
$this->path = $path;
parent::__construct($path);
parent::__construct( $path );
}

/**
Expand Down Expand Up @@ -48,10 +48,10 @@ public function get_filename(): string {
* @return bool Whether the path is valid.
*/
public static function is_valid( $path ): bool {
if(!is_string($path)) {
if ( ! is_string( $path ) ) {
return false;
}
if(strpos($path, './') === 0 || strpos($path, '/') === 0) {
if ( 0 === strpos( $path, './' ) || 0 === strpos( $path, '/' ) ) {
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions components/Blueprints/DataReference/class-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class File extends DataReference {
/**
* Constructor.
*
* @param ByteReadStream $stream The stream representing the file content.
* @param string $filename The name of the file.
* @param ByteReadStream $stream The stream representing the file content.
* @param string $filename The name of the file.
*/
public function __construct( ByteReadStream $stream, string $filename ) {
$this->stream = $stream;
Expand All @@ -38,7 +38,7 @@ public function __construct( ByteReadStream $stream, string $filename ) {
* @return string The human-readable name.
*/
public function get_human_readable_name(): string {
return "File: " . $this->filename;
return 'File: ' . $this->filename;
}

public function getStream(): ByteReadStream {
Expand Down
8 changes: 4 additions & 4 deletions components/Blueprints/DataReference/class-gitpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
$this->git_repository = $definition['gitRepository'];
$this->ref = $definition['ref'] ?? null;
$this->path = $definition['path'] ?? null;
parent::__construct($definition);
parent::__construct( $definition );
}

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public function get_filename(): string {
/**
* Check if an array represents a valid git path.
*
* @param array $data The array to check.
* @param array $data The array to check.
*
* @return bool Whether the array is valid.
*/
Expand All @@ -87,8 +87,8 @@ public static function is_valid( $data ): bool {
* @return string The human-readable name.
*/
public function get_human_readable_name(): string {
$ref = $this->ref ? "#{$this->ref}" : "";
$path = $this->path ? "/{$this->path}" : "";
$ref = $this->ref ? "#{$this->ref}" : '';
$path = $this->path ? "/{$this->path}" : '';

return "Git: {$this->git_repository}{$ref}{$path}";
}
Expand Down
Loading