GH-554 - Whitespace after toRichTextObject() - abide by coding standards

This commit is contained in:
MarkBaker 2015-07-12 23:25:34 +01:00
parent 879f86c235
commit 78378f1c88

View File

@ -573,7 +573,8 @@ class PHPExcel_Helper_HTML
protected $richTextObject;
protected function initialise() {
protected function initialise()
{
$this->face = $this->size = $this->color = null;
$this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false;
@ -582,7 +583,8 @@ class PHPExcel_Helper_HTML
$this->stringData = '';
}
public function toRichTextObject($html) {
public function toRichTextObject($html)
{
$this->initialise();
// Create a new DOM object
@ -603,7 +605,8 @@ class PHPExcel_Helper_HTML
return $this->richTextObject;
}
protected function cleanWhitespace() {
protected function cleanWhitespace()
{
foreach ($this->richTextObject->getRichTextElements() as $key => $element) {
$text = $element->getText();
// Trim any leading spaces on the first run
@ -616,10 +619,12 @@ class PHPExcel_Helper_HTML
}
}
protected function buildTextRun() {
protected function buildTextRun()
{
$text = $this->stringData;
if (trim($text) === '')
if (trim($text) === '') {
return;
}
$richtextRun = $this->richTextObject->createTextRun($this->stringData);
if ($this->face) {
@ -652,7 +657,8 @@ class PHPExcel_Helper_HTML
$this->stringData = '';
}
protected function rgbToColour($rgb) {
protected function rgbToColour($rgb)
{
preg_match_all('/\d+/', $rgb, $values);
foreach ($values[0] as &$value) {
$value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
@ -660,11 +666,13 @@ class PHPExcel_Helper_HTML
return implode($values[0]);
}
protected function colourNameLookup($rgb) {
protected function colourNameLookup($rgb)
{
return self::$colourMap[$rgb];
}
protected function startFontTag($tag) {
protected function startFontTag($tag)
{
foreach ($tag->attributes as $attribute) {
$attributeName = strtolower($attribute->name);
$attributeValue = $attribute->value;
@ -683,69 +691,89 @@ class PHPExcel_Helper_HTML
}
}
protected function endFontTag() {
protected function endFontTag()
{
$this->face = $this->size = $this->color = null;
}
protected function startBoldTag() {
protected function startBoldTag()
{
$this->bold = true;
}
protected function endBoldTag() {
protected function endBoldTag()
{
$this->bold = false;
}
protected function startItalicTag() {
protected function startItalicTag()
{
$this->italic = true;
}
protected function endItalicTag() {
protected function endItalicTag()
{
$this->italic = false;
}
protected function startUnderlineTag() {
protected function startUnderlineTag()
{
$this->underline = true;
}
protected function endUnderlineTag() {
protected function endUnderlineTag()
{
$this->underline = false;
}
protected function startSubscriptTag() {
protected function startSubscriptTag()
{
$this->subscript = true;
}
protected function endSubscriptTag() {
protected function endSubscriptTag()
{
$this->subscript = false;
}
protected function startSuperscriptTag() {
protected function startSuperscriptTag()
{
$this->superscript = true;
}
protected function endSuperscriptTag() {
protected function endSuperscriptTag()
{
$this->superscript = false;
}
protected function startStrikethruTag() {
protected function startStrikethruTag()
{
$this->strikethrough = true;
}
protected function endStrikethruTag() {
protected function endStrikethruTag()
{
$this->strikethrough = false;
}
protected function breakTag() {
protected function breakTag()
{
$this->stringData .= "\n";
}
protected function parseTextNode(DOMText $textNode) {
$domText = preg_replace('/\s+/u', ' ', str_replace(["\r", "\n"], ' ', $textNode->nodeValue));
protected function parseTextNode(DOMText $textNode)
{
$domText = preg_replace(
'/\s+/u',
' ',
str_replace(["\r", "\n"], ' ', $textNode->nodeValue)
);
$this->stringData .= $domText;
$this->buildTextRun();
}
protected function handleCallback($element, $callbackTag, $callbacks) {
protected function handleCallback($element, $callbackTag, $callbacks)
{
if (isset($callbacks[$callbackTag])) {
$elementHandler = $callbacks[$callbackTag];
if (method_exists($this, $elementHandler)) {
@ -754,20 +782,21 @@ class PHPExcel_Helper_HTML
}
}
protected function parseElementNode(DOMElement $element) {
protected function parseElementNode(DOMElement $element)
{
$callbackTag = strtolower($element->nodeName);
$this->stack[] = $callbackTag;
$this->handleCallback($element, $callbackTag, $this->startTagCallbacks);
$this->parseElements($element);
// $this->stringData .= ' ';
array_pop($this->stack);
$this->handleCallback($element, $callbackTag, $this->endTagCallbacks);
}
protected function parseElements(DOMNode $element) {
protected function parseElements(DOMNode $element)
{
foreach ($element->childNodes as $child) {
if ($child instanceof DOMText) {
$this->parseTextNode($child);