From b39d76be080fb835f7342020e3caa559e8764b7b Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Wed, 20 Apr 2016 23:07:36 -0600 Subject: [PATCH] General cleanup of CSSRenderer * Add phpdoc comments * Rename some variables to be a bit more clear for new readers * Break up render() to make things more readable and reduce cyclomatic complexity Change-Id: Iceeb1f6eb09b61efe6b81f359d28741f54fe88ad --- CSSRenderer.php | 134 ++++++++++++++++++--------- tests/phpunit/CSSParseRenderTest.php | 17 +++- 2 files changed, 104 insertions(+), 47 deletions(-) diff --git a/CSSRenderer.php b/CSSRenderer.php index 70d2631..40d7614 100644 --- a/CSSRenderer.php +++ b/CSSRenderer.php @@ -1,6 +1,4 @@ bymedia = []; + $this->byMedia = []; } /** * Adds (and merge) a parsed CSS tree to the render list. * * @param array $rules The parsed tree as created by CSSParser::rules() - * @param string $media Forcibly specified @media block selector. Normally unspecified - * and defaults to the empty string. + * @param string $media Forcibly specified @media block selector. */ function add( $rules, $media = '' ) { - if ( !array_key_exists( $media, $this->bymedia ) ) { - $this->bymedia[$media] = []; + if ( !array_key_exists( $media, $this->byMedia ) ) { + $this->byMedia[$media] = []; } - foreach ( $rules as $at ) { - switch ( strtolower( $at['name'] ) ) { + foreach ( $rules as $rule ) { + switch ( strtolower( $rule['name'] ) ) { case '@media': if ( $media == '' ) { - $this->add( $at['rules'], "@media ".$at['text'] ); + $this->add( + $rule['rules'], "@media {$rule['text']}" + ); } break; case '': - $this->bymedia[$media] = array_merge( $this->bymedia[$media], $at['rules'] ); + $this->byMedia[$media] = array_merge( + $this->byMedia[$media], $rule['rules'] + ); break; } } } /** - * Renders the collected CSS trees into a string suitable for inclusion + * Render the collected CSS trees into a string suitable for inclusion * in a