Skip to content

Commit 0166739

Browse files
committed
Formatting PHP doc comments and params that describe associative arrays
Updating test function names and annotations.
1 parent 30b3afe commit 0166739

File tree

8 files changed

+323
-178
lines changed

8 files changed

+323
-178
lines changed

src/wp-includes/style-engine.php

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@
2525
* @access public
2626
* @since 6.1.0
2727
*
28-
* @param array $block_styles The style object.
29-
* @param array<string|boolean> $options array(
30-
* 'context' => (string|null) An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is 'block-supports'.
31-
* When set, the style engine will attempt to store the CSS rules, where a selector is also passed.
32-
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
33-
* 'selector' => (string) When a selector is passed, `generate()` will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
34-
* );.
35-
*
36-
* @return array<string|array> array(
37-
* 'css' => (string) A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
38-
* 'declarations' => (array) An array of property/value pairs representing parsed CSS declarations.
39-
* 'classnames' => (string) Classnames separated by a space.
40-
* );
28+
* @param array $block_styles The style object.
29+
* @param array $options {
30+
* Optional. An array of options. Default empty array.
31+
*
32+
* @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is `null`.
33+
* When set, the style engine will attempt to store the CSS rules, where a selector is also passed.
34+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
35+
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
36+
* otherwise, the value will be a concatenated string of CSS declarations.
37+
* }
38+
*
39+
* @return array {
40+
* @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
41+
* @type array<string, string> $declarations An array of property/value pairs representing parsed CSS declarations.
42+
* @type string $classnames Classnames separated by a space.
43+
* }
4144
*/
4245
function wp_style_engine_get_styles( $block_styles, $options = array() ) {
4346
if ( ! class_exists( 'WP_Style_Engine' ) ) {
@@ -75,23 +78,32 @@ function wp_style_engine_get_styles( $block_styles, $options = array() ) {
7578

7679
/**
7780
* Returns compiled CSS from a collection of selectors and declarations.
78-
* This won't add to any store, but is useful for returning a compiled style sheet from any CSS selector + declarations combos.
81+
* Useful for returning a compiled stylesheet from any collection of CSS selector + declarations.
82+
*
83+
* Example usage:
84+
* $css_rules = array( array( 'selector' => '.elephant-are-cool', 'declarations' => array( 'color' => 'gray', 'width' => '3em' ) ) );
85+
* $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
86+
* // Returns `.elephant-are-cool{color:gray;width:3em}`.
7987
*
8088
* @access public
8189
* @since 6.1.0
8290
*
83-
* @param array<array> $css_rules array(
84-
* array(
85-
* 'selector' => (string) A CSS selector.
86-
* declarations' => (boolean) An array of CSS definitions, e.g., array( "$property" => "$value" ).
87-
* )
88-
* );.
89-
* @param array<string> $options array(
90-
* 'context' => (string|null) An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is 'block-supports'.
91-
* When set, the style engine will attempt to store the CSS rules.
92-
* 'optimize' => (boolean) Whether to optimize the CSS output, e.g., combine rules.
93-
* 'prettify' => (boolean) Whether to add new lines to output.
94-
* );.
91+
* @param array $css_rules {
92+
* Required. A collection of CSS rules.
93+
*
94+
* @type array ...$0 {
95+
* @type string $selector A CSS selector.
96+
* @type array<string, string> $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
97+
* }
98+
* }
99+
* @param array $options {
100+
* Optional. An array of options. Default empty array.
101+
*
102+
* @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is 'block-supports'.
103+
* When set, the style engine will attempt to store the CSS rules.
104+
* @type boolean $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
105+
* @type boolean $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
106+
* }
95107
*
96108
* @return string A compiled CSS string.
97109
*/
@@ -133,18 +145,20 @@ function wp_style_engine_get_stylesheet_from_css_rules( $css_rules, $options = a
133145
* @access public
134146
* @since 6.1.0
135147
*
136-
* @param string $store_name A valid store name.
137-
* @param array $options array(
138-
* 'optimize' => (boolean) Whether to optimize the CSS output, e.g., combine rules.
139-
* 'prettify' => (boolean) Whether to add new lines to output.
140-
* );.
148+
* @param string $context A valid context name, corresponding to an existing store key.
149+
* @param array $options {
150+
* Optional. An array of options. Default empty array.
151+
*
152+
* @type boolean $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
153+
* @type boolean $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
154+
* }
141155
*
142156
* @return string A compiled CSS string.
143157
*/
144-
function wp_style_engine_get_stylesheet_from_context( $store_name, $options = array() ) {
145-
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $store_name ) ) {
158+
function wp_style_engine_get_stylesheet_from_context( $context, $options = array() ) {
159+
if ( ! class_exists( 'WP_Style_Engine' ) || empty( $context ) ) {
146160
return '';
147161
}
148162

149-
return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $store_name )->get_all_rules(), $options );
163+
return WP_Style_Engine::compile_stylesheet_from_css_rules( WP_Style_Engine::get_store( $context )->get_all_rules(), $options );
150164
}

src/wp-includes/style-engine/class-wp-style-engine-processor.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function add_rules( $css_rules ) {
6363
if ( ! is_array( $css_rules ) ) {
6464
$css_rules = array( $css_rules );
6565
}
66+
6667
foreach ( $css_rules as $rule ) {
6768
$selector = $rule->get_selector();
6869
if ( isset( $this->css_rules[ $selector ] ) ) {
@@ -80,10 +81,12 @@ public function add_rules( $css_rules ) {
8081
*
8182
* @since 6.1.0
8283
*
83-
* @param array $options array(
84-
* 'optimize' => (boolean) Whether to optimize the CSS output, e.g., combine rules.
85-
* 'prettify' => (boolean) Whether to add new lines to output.
86-
* );.
84+
* @param array $options {
85+
* Optional. An array of options. Default empty array.
86+
*
87+
* @type boolean $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
88+
* @type boolean $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
89+
* }
8790
*
8891
* @return string The computed CSS.
8992
*/

src/wp-includes/style-engine/class-wp-style-engine.php

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ protected static function is_valid_style_value( $style_value ) {
275275
*
276276
* @since 6.1.0
277277
*
278-
* @param string $store_name A valid store key.
279-
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
280-
* @param array $css_declarations An array of parsed CSS property => CSS value pairs.
278+
* @param string $store_name A valid store key.
279+
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
280+
* @param array<string, string> $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
281281
*
282282
* @return void.
283283
*/
@@ -308,15 +308,18 @@ public static function get_store( $store_name ) {
308308
* @since 6.1.0
309309
*
310310
* @param array $block_styles The style object.
311-
* @param array $options array(
312-
* 'selector' => (string) When a selector is passed, `generate()` will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
313-
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
314-
* );.
315-
*
316-
* @return array array(
317-
* 'declarations' => (array) An array of parsed CSS property => CSS value pairs.
318-
* 'classnames' => (array) A flat array of classnames.
319-
* );
311+
* @param array $options {
312+
* Optional. An array of options. Default empty array.
313+
*
314+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
315+
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
316+
* otherwise, the value will be a concatenated string of CSS declarations.
317+
* }
318+
*
319+
* @return array {
320+
* @type string $classnames Classnames separated by a space.
321+
* @type array<string, string> $declarations An array of property/value pairs representing parsed CSS declarations.
322+
* }
320323
*/
321324
public static function parse_block_styles( $block_styles, $options ) {
322325
$parsed_styles = array(
@@ -348,14 +351,14 @@ public static function parse_block_styles( $block_styles, $options ) {
348351
}
349352

350353
/**
351-
* Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., 'var:preset|color|heavenly-blue'.
354+
* Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., '`var:preset|<PRESET_TYPE>|<PRESET_SLUG>`'.
352355
*
353356
* @since 6.1.0
354357
*
355-
* @param array $style_value A single raw style value or css preset property from the generate() $block_styles array.
356-
* @param array<string> $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
358+
* @param array $style_value A single raw style value or css preset property from the $block_styles array.
359+
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
357360
*
358-
* @return array An array of CSS classnames.
361+
* @return array<string> An array of CSS classnames.
359362
*/
360363
protected static function get_classnames( $style_value, $style_definition ) {
361364
if ( empty( $style_value ) ) {
@@ -389,15 +392,17 @@ protected static function get_classnames( $style_value, $style_definition ) {
389392
*
390393
* @since 6.1.0
391394
*
392-
* @param array $style_value A single raw style value from the generate() $block_styles array.
393-
* @param array<string> $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
394-
* @param array $options array(
395-
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
396-
* );.
395+
* @param array $style_value A single raw style value from $block_styles array.
396+
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
397+
* @param array $options {
398+
* Optional. An array of options. Default empty array.
397399
*
398-
* @return array An array of CSS definitions, e.g., array( "$property" => "$value" ).
400+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
401+
* }
402+
*
403+
* @return array<string, string> An array of CSS definitions, e.g., array( "$property" => "$value" ).
399404
*/
400-
protected static function get_css_declarations( $style_value, $style_definition, $options ) {
405+
protected static function get_css_declarations( $style_value, $style_definition, $options = array() ) {
401406
if ( isset( $style_definition['value_func'] ) && is_callable( $style_definition['value_func'] ) ) {
402407
return call_user_func( $style_definition['value_func'], $style_value, $style_definition, $options );
403408
}
@@ -406,7 +411,7 @@ protected static function get_css_declarations( $style_value, $style_definition,
406411
$style_property_keys = $style_definition['property_keys'];
407412
$should_skip_css_vars = isset( $options['convert_vars_to_classnames'] ) && true === $options['convert_vars_to_classnames'];
408413

409-
// Build CSS var values from var:? values, e.g, `var(--wp--css--rule-slug )`
414+
// Build CSS var values from `var:preset|<PRESET_TYPE>|<PRESET_SLUG>` values, e.g, `var(--wp--css--rule-slug )`.
410415
// Check if the value is a CSS preset and there's a corresponding css_var pattern in the style definition.
411416
if ( is_string( $style_value ) && str_contains( $style_value, 'var:' ) ) {
412417
if ( ! $should_skip_css_vars && ! empty( $style_definition['css_vars'] ) ) {
@@ -455,15 +460,17 @@ protected static function get_css_declarations( $style_value, $style_definition,
455460
*
456461
* @since 6.1.0
457462
*
458-
* @param array $style_value A single raw Gutenberg style attributes value for a CSS property.
459-
* @param array $individual_property_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
460-
* @param array $options array(
461-
* 'convert_vars_to_classnames' => (boolean) Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
462-
* );.
463+
* @param array $style_value A single raw style value from $block_styles array.
464+
* @param array $individual_property_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA representing an individual property of a CSS property, e.g., 'top' in 'border-top'.
465+
* @param array $options {
466+
* Optional. An array of options. Default empty array.
467+
*
468+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
469+
* }
463470
*
464-
* @return array An array of CSS definitions, e.g., array( "$property" => "$value" ).
471+
* @return array<string, string> An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
465472
*/
466-
protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options ) {
473+
protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options = array() ) {
467474
if ( ! is_array( $style_value ) || empty( $style_value ) || empty( $individual_property_definition['path'] ) ) {
468475
return array();
469476
}
@@ -502,8 +509,8 @@ protected static function get_individual_property_css_declarations( $style_value
502509
*
503510
* @since 6.1.0
504511
*
505-
* @param array $css_declarations An array of parsed CSS property => CSS value pairs.
506-
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
512+
* @param array<string, string> $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
513+
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
507514
*
508515
* @return string A compiled CSS string.
509516
*/
@@ -528,10 +535,12 @@ public static function compile_css( $css_declarations, $css_selector ) {
528535
* @since 6.1.0
529536
*
530537
* @param WP_Style_Engine_CSS_Rule[] $css_rules An array of WP_Style_Engine_CSS_Rule objects from a store or otherwise.
531-
* @param array $options array(
532-
* 'optimize' => (boolean) Whether to optimize the CSS output, e.g., combine rules.
533-
* 'prettify' => (boolean) Whether to add new lines to output.
534-
* );.
538+
* @param array $options {
539+
* Optional. An array of options. Default empty array.
540+
*
541+
* @type boolean $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
542+
* @type boolean $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
543+
* }
535544
*
536545
* @return string A compiled stylesheet from stored CSS rules.
537546
*/

0 commit comments

Comments
 (0)