Skip to content

Commit

Permalink
Validation PSR-2 : Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed May 12, 2015
1 parent 61b5fa0 commit 95b3fb0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 72 deletions.
69 changes: 39 additions & 30 deletions Classes/PHPExcel/Writer/Excel5/Xf.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function __construct(PHPExcel_Style $style = null)
*
* @return string The XF record
*/
function writeXf()
public function writeXf()
{
// Set the type of the XF record and some of the attributes.
if ($this->_isStyleXf) {
Expand Down Expand Up @@ -249,18 +249,14 @@ function writeXf()
$border2 |= self::_mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
$border2 |= self::_mapFillType($this->_style->getFill()->getFillType()) << 26;

$header = pack("vv", $record, $length);
$header = pack("vv", $record, $length);

//BIFF8 options: identation, shrinkToFit and text direction
$biff8_options = $this->_style->getAlignment()->getIndent();
$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;

$data = pack("vvvC", $ifnt, $ifmt, $style, $align);
$data .= pack("CCC"
, self::_mapTextRotation($this->_style->getAlignment()->getTextRotation())
, $biff8_options
, $used_attrib
);
$data .= pack("CCC", self::_mapTextRotation($this->_style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib);
$data .= pack("VVv", $border1, $border2, $icv);

return($header . $data);
Expand All @@ -282,7 +278,7 @@ public function setIsStyleXf($value)
* @access public
* @param int $colorIndex Color index
*/
function setBottomColor($colorIndex)
public function setBottomColor($colorIndex)
{
$this->_bottom_color = $colorIndex;
}
Expand All @@ -293,7 +289,7 @@ function setBottomColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setTopColor($colorIndex)
public function setTopColor($colorIndex)
{
$this->_top_color = $colorIndex;
}
Expand All @@ -304,7 +300,7 @@ function setTopColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setLeftColor($colorIndex)
public function setLeftColor($colorIndex)
{
$this->_left_color = $colorIndex;
}
Expand All @@ -315,7 +311,7 @@ function setLeftColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setRightColor($colorIndex)
public function setRightColor($colorIndex)
{
$this->_right_color = $colorIndex;
}
Expand All @@ -326,7 +322,7 @@ function setRightColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setDiagColor($colorIndex)
public function setDiagColor($colorIndex)
{
$this->_diag_color = $colorIndex;
}
Expand All @@ -338,7 +334,7 @@ function setDiagColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setFgColor($colorIndex)
public function setFgColor($colorIndex)
{
$this->_fg_color = $colorIndex;
}
Expand All @@ -349,7 +345,7 @@ function setFgColor($colorIndex)
* @access public
* @param int $colorIndex Color index
*/
function setBgColor($colorIndex)
public function setBgColor($colorIndex)
{
$this->_bg_color = $colorIndex;
}
Expand All @@ -361,7 +357,7 @@ function setBgColor($colorIndex)
* @access public
* @param integer $numberFormatIndex Index to format record
*/
function setNumberFormatIndex($numberFormatIndex)
public function setNumberFormatIndex($numberFormatIndex)
{
$this->_numberFormatIndex = $numberFormatIndex;
}
Expand Down Expand Up @@ -403,9 +399,11 @@ public function setFontIndex($value)
* @param string $borderStyle
* @return int
*/
private static function _mapBorderStyle($borderStyle) {
if (isset(self::$_mapBorderStyle[$borderStyle]))
private static function _mapBorderStyle($borderStyle)
{
if (isset(self::$_mapBorderStyle[$borderStyle])) {
return self::$_mapBorderStyle[$borderStyle];
}
return 0x00;
}

Expand Down Expand Up @@ -442,9 +440,11 @@ private static function _mapBorderStyle($borderStyle) {
* @param string $fillType
* @return int
*/
private static function _mapFillType($fillType) {
if (isset(self::$_mapFillType[$fillType]))
private static function _mapFillType($fillType)
{
if (isset(self::$_mapFillType[$fillType])) {
return self::$_mapFillType[$fillType];
}
return 0x00;
}

Expand All @@ -469,8 +469,9 @@ private static function _mapFillType($fillType) {
*/
private function _mapHAlign($hAlign)
{
if (isset(self::$_mapHAlign[$hAlign]))
if (isset(self::$_mapHAlign[$hAlign])) {
return self::$_mapHAlign[$hAlign];
}
return 0;
}

Expand All @@ -491,8 +492,9 @@ private function _mapHAlign($hAlign)
* @return int
*/
private static function _mapVAlign($vAlign) {
if (isset(self::$_mapVAlign[$vAlign]))
if (isset(self::$_mapVAlign[$vAlign])) {
return self::$_mapVAlign[$vAlign];
}
return 2;
}

Expand Down Expand Up @@ -522,10 +524,14 @@ private static function _mapTextRotation($textRotation) {
*/
private static function _mapLocked($locked) {
switch ($locked) {
case PHPExcel_Style_Protection::PROTECTION_INHERIT: return 1;
case PHPExcel_Style_Protection::PROTECTION_PROTECTED: return 1;
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED: return 0;
default: return 1;
case PHPExcel_Style_Protection::PROTECTION_INHERIT:
return 1;
case PHPExcel_Style_Protection::PROTECTION_PROTECTED:
return 1;
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED:
return 0;
default:
return 1;
}
}

Expand All @@ -537,11 +543,14 @@ private static function _mapLocked($locked) {
*/
private static function _mapHidden($hidden) {
switch ($hidden) {
case PHPExcel_Style_Protection::PROTECTION_INHERIT: return 0;
case PHPExcel_Style_Protection::PROTECTION_PROTECTED: return 1;
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED: return 0;
default: return 0;
case PHPExcel_Style_Protection::PROTECTION_INHERIT:
return 0;
case PHPExcel_Style_Protection::PROTECTION_PROTECTED:
return 1;
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED:
return 0;
default:
return 0;
}
}

}
81 changes: 40 additions & 41 deletions Classes/PHPExcel/Writer/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle)
$css['vertical-align'] = $this->_mapVAlign($pStyle->getVertical());
if ($textAlign = $this->_mapHAlign($pStyle->getHorizontal())) {
$css['text-align'] = $textAlign;
if (in_array($textAlign,array('left','right'))) {
if (in_array($textAlign,array('left', 'right'))) {
$css['padding-'.$textAlign] = (string)((int)$pStyle->getIndent() * 9).'px';
}
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle)
{
// Create CSS
// $css = $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
// Create CSS - add !important to non-none border styles for merged cells
// Create CSS - add !important to non-none border styles for merged cells
$borderStyle = $this->_mapBorderStyle($pStyle->getBorderStyle());
$css = $borderStyle . ' #' . $pStyle->getColor()->getRGB() . (($borderStyle == 'none') ? '' : ' !important');

Expand Down Expand Up @@ -1265,10 +1265,9 @@ private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow
}

// General horizontal alignment: Actual horizontal alignment depends on dataType
$sharedStyle = $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() );
$sharedStyle = $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex());
if ($sharedStyle->getAlignment()->getHorizontal() == PHPExcel_Style_Alignment::HORIZONTAL_GENERAL
&& isset($this->_cssStyles['.' . $cell->getDataType()]['text-align']))
{
&& isset($this->_cssStyles['.' . $cell->getDataType()]['text-align'])) {
$cssClass['text-align'] = $this->_cssStyles['.' . $cell->getDataType()]['text-align'];
}
}
Expand Down Expand Up @@ -1303,39 +1302,39 @@ private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow
if ($writeCell) {
// Column start
$html .= ' <' . $cellType;
if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"';
} else {
//** Necessary redundant code for the sake of PHPExcel_Writer_PDF **
// We must explicitly write the width of the <td> element because TCPDF
// does not recognize e.g. <col style="width:42pt">
$width = 0;
$i = $colNum - 1;
$e = $colNum + $colSpan - 1;
while ($i++ < $e) {
if (isset($this->_columnWidths[$sheetIndex][$i])) {
$width += $this->_columnWidths[$sheetIndex][$i];
}
}
$cssClass['width'] = $width . 'pt';

// We must also explicitly write the height of the <td> element because TCPDF
// does not recognize e.g. <tr style="height:50pt">
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) {
$height = $this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'];
$cssClass['height'] = $height;
if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"';
} else {
//** Necessary redundant code for the sake of PHPExcel_Writer_PDF **
// We must explicitly write the width of the <td> element because TCPDF
// does not recognize e.g. <col style="width:42pt">
$width = 0;
$i = $colNum - 1;
$e = $colNum + $colSpan - 1;
while ($i++ < $e) {
if (isset($this->_columnWidths[$sheetIndex][$i])) {
$width += $this->_columnWidths[$sheetIndex][$i];
}
//** end of redundant code **

$html .= ' style="' . $this->_assembleCSS($cssClass) . '"';
}
if ($colSpan > 1) {
$html .= ' colspan="' . $colSpan . '"';
}
if ($rowSpan > 1) {
$html .= ' rowspan="' . $rowSpan . '"';
$cssClass['width'] = $width . 'pt';

// We must also explicitly write the height of the <td> element because TCPDF
// does not recognize e.g. <tr style="height:50pt">
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) {
$height = $this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'];
$cssClass['height'] = $height;
}
$html .= '>';
//** end of redundant code **

$html .= ' style="' . $this->_assembleCSS($cssClass) . '"';
}
if ($colSpan > 1) {
$html .= ' colspan="' . $colSpan . '"';
}
if ($rowSpan > 1) {
$html .= ' rowspan="' . $rowSpan . '"';
}
$html .= '>';

// Image?
$html .= $this->_writeImageInCell($pSheet, $coordinate);
Expand Down Expand Up @@ -1510,13 +1509,13 @@ private function _calculateSpans()

// loop through the individual cells in the individual merge
$r = $fr - 1;
while($r++ < $lr) {
while ($r++ < $lr) {
// also, flag this row as a HTML row that is candidate to be omitted
$candidateSpannedRow[$r] = $r;

$c = $fc - 1;
while($c++ < $lc) {
if ( !($c == $fc && $r == $fr) ) {
while ($c++ < $lc) {
if (!($c == $fc && $r == $fr)) {
// not the upper-left cell (should not be written in HTML)
$this->_isSpannedCell[$sheetIndex][$r][$c] = array(
'baseCell' => array($fr, $fc),
Expand Down Expand Up @@ -1546,15 +1545,15 @@ private function _calculateSpans()
}

// For each of the omitted rows we found above, the affected rowspans should be subtracted by 1
if ( isset($this->_isSpannedRow[$sheetIndex]) ) {
if (isset($this->_isSpannedRow[$sheetIndex])) {
foreach ($this->_isSpannedRow[$sheetIndex] as $rowIndex) {
$adjustedBaseCells = array();
$c = -1;
$e = $countColumns - 1;
while($c++ < $e) {
while ($c++ < $e) {
$baseCell = $this->_isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell'];

if ( !in_array($baseCell, $adjustedBaseCells) ) {
if (!in_array($baseCell, $adjustedBaseCells)) {
// subtract rowspan by 1
--$this->_isBaseCell[$sheetIndex][ $baseCell[0] ][ $baseCell[1] ]['rowspan'];
$adjustedBaseCells[] = $baseCell;
Expand Down
1 change: 0 additions & 1 deletion Classes/PHPExcel/Writer/IWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ interface PHPExcel_Writer_IWriter
* @throws PHPExcel_Writer_Exception
*/
public function save($pFilename = null);

}

0 comments on commit 95b3fb0

Please sign in to comment.