-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minor tweaks to the style engine #43111
Conversation
if ( empty( $declarations ) ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If empty, then add_declarations
won't add anything. This check doesn't serve any purpose.
* @param array $declarations An array of properties. | ||
* @param array $properties An array of properties. | ||
* | ||
* @return void | ||
*/ | ||
public function remove_declarations( $declarations = array() ) { | ||
foreach ( $declarations as $property ) { | ||
public function remove_declarations( $properties = array() ) { | ||
foreach ( $properties as $property ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply renamed $declarations
to $properties
since it's more accurate.
if ( isset( $property ) && isset( $value ) ) { | ||
return safecss_filter_attr( "{$property}:{$spacer}{$value}" ); | ||
} | ||
return ''; | ||
return safecss_filter_attr( "{$property}:{$spacer}{$value}" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$property
and $value
will always be set, they are mandatory params of the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there checks somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! We check the property and value when adding them to the object, so we already know they're there 😉
$spacer = $should_prettify ? ' ' : ''; | ||
|
||
foreach ( $declarations_array as $property => $value ) { | ||
$spacer = $should_prettify ? ' ' : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this outside the loop. The $spacer
's value doesn't change on each iteration of the loop so it can be defined outside it.
* @return WP_Style_Engine_CSS_Rule|void Returns the object to allow chaining of methods. | ||
* @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. | ||
*/ | ||
public function set_selector( $selector ) { | ||
if ( empty( $selector ) ) { | ||
return; | ||
} | ||
$this->selector = $selector; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always return the object to avoid fatalities if chaining methods.
@@ -73,7 +73,7 @@ public function add_rules( $css_rules ) { | |||
public function get_css( $options = array() ) { | |||
$defaults = array( | |||
'optimize' => true, | |||
'prettify' => false, | |||
'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SCRIPT_DEBUG
to determine the value of prettify
by default.
if ( empty( $style_value ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
return ! empty( $style_value ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just simplifying code a bit
return $processor->get_css( array( 'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ); | ||
return $processor->get_css(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this check to the get_css()
method itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Nice one, thanks for tidying up @aristath! |
Cherry-picked into the 13.9.0 RC 3 (https://github.com/WordPress/gutenberg/releases/tag/v13.9.0-rc.3) |
What?
Did an extra review of the style-engine code and added some tweaks to improve our code a bit.
Why?
Because code is poetry.