diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5a70bf9..fc89780 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -3,15 +3,9 @@ return (new PhpCsFixer\Config()) ->setRules([ '@PER-CS' => true, - 'array_syntax' => false, - 'concat_space' => false, 'visibility_required' => ['elements' => ['property', 'method']], // Exclude 'const' for PHP 5.6 compatibility 'trailing_comma_in_multiline' => ['elements' => ['arrays']], 'method_argument_space' => false, - 'array_indentation' => false, - 'braces_position' => false, - 'statement_indentation' => false, - 'binary_operator_spaces' => false, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/Spreadsheet/Excel/Writer/BIFFwriter.php b/Spreadsheet/Excel/Writer/BIFFwriter.php index 511fcb4..4dd8d07 100644 --- a/Spreadsheet/Excel/Writer/BIFFwriter.php +++ b/Spreadsheet/Excel/Writer/BIFFwriter.php @@ -128,11 +128,11 @@ protected function _setByteOrder() $number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); if ($number == $teststr) { $byte_order = 0; // Little Endian - } elseif ($number == strrev($teststr)){ + } elseif ($number == strrev($teststr)) { $byte_order = 1; // Big Endian } else { // Give up. I'll fix this in a later version. - return $this->raiseError("Required floating point format ". + return $this->raiseError("Required floating point format " . "not supported on this platform."); } $this->_byte_order = $byte_order; @@ -149,7 +149,7 @@ protected function _prepend($data) if (strlen($data) > $this->_limit) { $data = $this->_addContinue($data); } - $this->_data = $data.$this->_data; + $this->_data = $data . $this->_data; $this->_datasize += strlen($data); } @@ -232,7 +232,7 @@ protected function _addContinue($data) // The first 2080/8224 bytes remain intact. However, we have to change // the length field of the record. - $tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4); + $tmp = substr($data, 0, 2) . pack("v", $limit - 4) . substr($data, 4, $limit - 4); $header = pack("vv", $record, $limit); // Headers for continue records diff --git a/Spreadsheet/Excel/Writer/Format.php b/Spreadsheet/Excel/Writer/Format.php index cd8af1f..a872faf 100644 --- a/Spreadsheet/Excel/Writer/Format.php +++ b/Spreadsheet/Excel/Writer/Format.php @@ -267,7 +267,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR * @param integer $index the XF index for the format. * @param array $properties array with properties to be set on initialization. */ - public function __construct($BIFF_version, $index = 0, $properties = array()) + public function __construct($BIFF_version, $index = 0, $properties = []) { $this->_xf_index = $index; $this->_BIFF_version = $BIFF_version; @@ -314,10 +314,9 @@ public function __construct($BIFF_version, $index = 0, $properties = array()) $this->_diag_color = 0x40; // Set properties passed to Spreadsheet_Excel_Writer_Workbook::addFormat() - foreach ($properties as $property => $value) - { - if (method_exists($this, 'set'.ucwords($property))) { - $method_name = 'set'.ucwords($property); + foreach ($properties as $property => $value) { + if (method_exists($this, 'set' . ucwords($property))) { + $method_name = 'set' . ucwords($property); $this->$method_name($value); } } @@ -409,8 +408,8 @@ public function getXf($style) $header = pack("vv", $record, $length); $data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align, - $icv, $fill, - $border1, $border2); + $icv, $fill, + $border1, $border2); } elseif ($this->_BIFF_version == 0x0600) { $align = $this->_text_h_align; // Alignment $align |= $this->_text_wrap << 3; @@ -497,12 +496,12 @@ public function getFont() $header = pack("vv", $record, $length); if ($this->_BIFF_version == 0x0500) { $data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls, - $sss, $uls, $bFamily, - $bCharSet, $reserved, $cch); + $sss, $uls, $bFamily, + $bCharSet, $reserved, $cch); } elseif ($this->_BIFF_version == 0x0600) { $data = pack("vvvvvCCCCCC", $dyHeight, $grbit, $icv, $bls, - $sss, $uls, $bFamily, - $bCharSet, $reserved, $cch, $encoding); + $sss, $uls, $bFamily, + $bCharSet, $reserved, $cch, $encoding); } return ($header . $data . $this->_font_name); } @@ -549,26 +548,26 @@ public function getXfIndex() */ protected function _getColor($name_color = '') { - $colors = array( - 'aqua' => 0x07, - 'cyan' => 0x07, - 'black' => 0x00, - 'blue' => 0x04, - 'brown' => 0x10, - 'magenta' => 0x06, - 'fuchsia' => 0x06, - 'gray' => 0x17, - 'grey' => 0x17, - 'green' => 0x11, - 'lime' => 0x03, - 'navy' => 0x12, - 'orange' => 0x35, - 'purple' => 0x14, - 'red' => 0x02, - 'silver' => 0x16, - 'white' => 0x01, - 'yellow' => 0x05, - ); + $colors = [ + 'aqua' => 0x07, + 'cyan' => 0x07, + 'black' => 0x00, + 'blue' => 0x04, + 'brown' => 0x10, + 'magenta' => 0x06, + 'fuchsia' => 0x06, + 'gray' => 0x17, + 'grey' => 0x17, + 'green' => 0x11, + 'lime' => 0x03, + 'navy' => 0x12, + 'orange' => 0x35, + 'purple' => 0x14, + 'red' => 0x02, + 'silver' => 0x16, + 'white' => 0x01, + 'yellow' => 0x05, + ]; // Return the default color, 0x7FFF, if undef, if ($name_color === '') { @@ -998,35 +997,34 @@ public function setTextWrap() */ public function setTextRotation($angle) { - switch ($angle) - { + switch ($angle) { case 0: $this->_rotation = 0; break; case 90: if ($this->_BIFF_version == 0x0500) { - $this->_rotation = 3; + $this->_rotation = 3; } elseif ($this->_BIFF_version == 0x0600) { $this->_rotation = 180; } break; case 270: if ($this->_BIFF_version == 0x0500) { - $this->_rotation = 2; + $this->_rotation = 2; } elseif ($this->_BIFF_version == 0x0600) { $this->_rotation = 90; } break; case -1: if ($this->_BIFF_version == 0x0500) { - $this->_rotation = 1; + $this->_rotation = 1; } elseif ($this->_BIFF_version == 0x0600) { $this->_rotation = 255; } break; default: - return $this->raiseError("Invalid value for angle.". - " Possible values are: 0, 90, 270 and -1 ". + return $this->raiseError("Invalid value for angle." . + " Possible values are: 0, 90, 270 and -1 " . "for stacking top-to-bottom."); $this->_rotation = 0; break; @@ -1087,15 +1085,15 @@ public function setScript($script) $this->_font_script = $script; } - /** - * Locks a cell. - * - * @access public - */ - public function setLocked() - { - $this->_locked = 1; - } + /** + * Locks a cell. + * + * @access public + */ + public function setLocked() + { + $this->_locked = 1; + } /** * Unlocks a cell. Useful for unprotecting particular cells of a protected sheet. diff --git a/Spreadsheet/Excel/Writer/Parser.php b/Spreadsheet/Excel/Writer/Parser.php index 6d40601..65ebda0 100644 --- a/Spreadsheet/Excel/Writer/Parser.php +++ b/Spreadsheet/Excel/Writer/Parser.php @@ -192,8 +192,8 @@ public function __construct($byte_order, $biff_version) $this->_parse_tree = ''; // The parse tree to be generated. $this->_initializeHashes(); // Initialize the hashes: ptg's and public function's ptg's $this->_byte_order = $byte_order; // Little Endian or Big Endian - $this->_ext_sheets = array(); - $this->_references = array(); + $this->_ext_sheets = []; + $this->_references = []; } /** @@ -204,7 +204,7 @@ public function __construct($byte_order, $biff_version) protected function _initializeHashes() { // The Excel ptg indices - $this->ptg = array( + $this->ptg = [ 'ptgExp' => 0x01, 'ptgTbl' => 0x02, 'ptgAdd' => 0x03, @@ -300,7 +300,7 @@ protected function _initializeHashes() 'ptgArea3dA' => 0x7B, 'ptgRefErr3dA' => 0x7C, 'ptgAreaErr3d' => 0x7D, - ); + ]; // Thanks to Michael Meeks and Gnumeric for the initial arg values. // @@ -315,234 +315,234 @@ protected function _initializeHashes() // class: The reference, value or array class of the public function args. // vol: The public function is volatile. // - $this->_functions = array( - // public function ptg args class vol - 'COUNT' => array(0, -1, 0, 0), - 'IF' => array(1, -1, 1, 0), - 'ISNA' => array(2, 1, 1, 0), - 'ISERROR' => array(3, 1, 1, 0), - 'SUM' => array(4, -1, 0, 0), - 'AVERAGE' => array(5, -1, 0, 0), - 'MIN' => array(6, -1, 0, 0), - 'MAX' => array(7, -1, 0, 0), - 'ROW' => array(8, -1, 0, 0), - 'COLUMN' => array(9, -1, 0, 0), - 'NA' => array(10, 0, 0, 0), - 'NPV' => array(11, -1, 1, 0), - 'STDEV' => array(12, -1, 0, 0), - 'DOLLAR' => array(13, -1, 1, 0), - 'FIXED' => array(14, -1, 1, 0), - 'SIN' => array(15, 1, 1, 0), - 'COS' => array(16, 1, 1, 0), - 'TAN' => array(17, 1, 1, 0), - 'ATAN' => array(18, 1, 1, 0), - 'PI' => array(19, 0, 1, 0), - 'SQRT' => array(20, 1, 1, 0), - 'EXP' => array(21, 1, 1, 0), - 'LN' => array(22, 1, 1, 0), - 'LOG10' => array(23, 1, 1, 0), - 'ABS' => array(24, 1, 1, 0), - 'INT' => array(25, 1, 1, 0), - 'SIGN' => array(26, 1, 1, 0), - 'ROUND' => array(27, 2, 1, 0), - 'LOOKUP' => array(28, -1, 0, 0), - 'INDEX' => array(29, -1, 0, 1), - 'REPT' => array(30, 2, 1, 0), - 'MID' => array(31, 3, 1, 0), - 'LEN' => array(32, 1, 1, 0), - 'VALUE' => array(33, 1, 1, 0), - 'TRUE' => array(34, 0, 1, 0), - 'FALSE' => array(35, 0, 1, 0), - 'AND' => array(36, -1, 0, 0), - 'OR' => array(37, -1, 0, 0), - 'NOT' => array(38, 1, 1, 0), - 'MOD' => array(39, 2, 1, 0), - 'DCOUNT' => array(40, 3, 0, 0), - 'DSUM' => array(41, 3, 0, 0), - 'DAVERAGE' => array(42, 3, 0, 0), - 'DMIN' => array(43, 3, 0, 0), - 'DMAX' => array(44, 3, 0, 0), - 'DSTDEV' => array(45, 3, 0, 0), - 'VAR' => array(46, -1, 0, 0), - 'DVAR' => array(47, 3, 0, 0), - 'TEXT' => array(48, 2, 1, 0), - 'LINEST' => array(49, -1, 0, 0), - 'TREND' => array(50, -1, 0, 0), - 'LOGEST' => array(51, -1, 0, 0), - 'GROWTH' => array(52, -1, 0, 0), - 'PV' => array(56, -1, 1, 0), - 'FV' => array(57, -1, 1, 0), - 'NPER' => array(58, -1, 1, 0), - 'PMT' => array(59, -1, 1, 0), - 'RATE' => array(60, -1, 1, 0), - 'MIRR' => array(61, 3, 0, 0), - 'IRR' => array(62, -1, 0, 0), - 'RAND' => array(63, 0, 1, 1), - 'MATCH' => array(64, -1, 0, 0), - 'DATE' => array(65, 3, 1, 0), - 'TIME' => array(66, 3, 1, 0), - 'DAY' => array(67, 1, 1, 0), - 'MONTH' => array(68, 1, 1, 0), - 'YEAR' => array(69, 1, 1, 0), - 'WEEKDAY' => array(70, -1, 1, 0), - 'HOUR' => array(71, 1, 1, 0), - 'MINUTE' => array(72, 1, 1, 0), - 'SECOND' => array(73, 1, 1, 0), - 'NOW' => array(74, 0, 1, 1), - 'AREAS' => array(75, 1, 0, 1), - 'ROWS' => array(76, 1, 0, 1), - 'COLUMNS' => array(77, 1, 0, 1), - 'OFFSET' => array(78, -1, 0, 1), - 'SEARCH' => array(82, -1, 1, 0), - 'TRANSPOSE' => array(83, 1, 1, 0), - 'TYPE' => array(86, 1, 1, 0), - 'ATAN2' => array(97, 2, 1, 0), - 'ASIN' => array(98, 1, 1, 0), - 'ACOS' => array(99, 1, 1, 0), - 'CHOOSE' => array(100, -1, 1, 0), - 'HLOOKUP' => array(101, -1, 0, 0), - 'VLOOKUP' => array(102, -1, 0, 0), - 'ISREF' => array(105, 1, 0, 0), - 'LOG' => array(109, -1, 1, 0), - 'CHAR' => array(111, 1, 1, 0), - 'LOWER' => array(112, 1, 1, 0), - 'UPPER' => array(113, 1, 1, 0), - 'PROPER' => array(114, 1, 1, 0), - 'LEFT' => array(115, -1, 1, 0), - 'RIGHT' => array(116, -1, 1, 0), - 'EXACT' => array(117, 2, 1, 0), - 'TRIM' => array(118, 1, 1, 0), - 'REPLACE' => array(119, 4, 1, 0), - 'SUBSTITUTE' => array(120, -1, 1, 0), - 'CODE' => array(121, 1, 1, 0), - 'FIND' => array(124, -1, 1, 0), - 'CELL' => array(125, -1, 0, 1), - 'ISERR' => array(126, 1, 1, 0), - 'ISTEXT' => array(127, 1, 1, 0), - 'ISNUMBER' => array(128, 1, 1, 0), - 'ISBLANK' => array(129, 1, 1, 0), - 'T' => array(130, 1, 0, 0), - 'N' => array(131, 1, 0, 0), - 'DATEVALUE' => array(140, 1, 1, 0), - 'TIMEVALUE' => array(141, 1, 1, 0), - 'SLN' => array(142, 3, 1, 0), - 'SYD' => array(143, 4, 1, 0), - 'DDB' => array(144, -1, 1, 0), - 'INDIRECT' => array(148, -1, 1, 1), - 'CALL' => array(150, -1, 1, 0), - 'CLEAN' => array(162, 1, 1, 0), - 'MDETERM' => array(163, 1, 2, 0), - 'MINVERSE' => array(164, 1, 2, 0), - 'MMULT' => array(165, 2, 2, 0), - 'IPMT' => array(167, -1, 1, 0), - 'PPMT' => array(168, -1, 1, 0), - 'COUNTA' => array(169, -1, 0, 0), - 'PRODUCT' => array(183, -1, 0, 0), - 'FACT' => array(184, 1, 1, 0), - 'DPRODUCT' => array(189, 3, 0, 0), - 'ISNONTEXT' => array(190, 1, 1, 0), - 'STDEVP' => array(193, -1, 0, 0), - 'VARP' => array(194, -1, 0, 0), - 'DSTDEVP' => array(195, 3, 0, 0), - 'DVARP' => array(196, 3, 0, 0), - 'TRUNC' => array(197, -1, 1, 0), - 'ISLOGICAL' => array(198, 1, 1, 0), - 'DCOUNTA' => array(199, 3, 0, 0), - 'ROUNDUP' => array(212, 2, 1, 0), - 'ROUNDDOWN' => array(213, 2, 1, 0), - 'RANK' => array(216, -1, 0, 0), - 'ADDRESS' => array(219, -1, 1, 0), - 'DAYS360' => array(220, -1, 1, 0), - 'TODAY' => array(221, 0, 1, 1), - 'VDB' => array(222, -1, 1, 0), - 'MEDIAN' => array(227, -1, 0, 0), - 'SUMPRODUCT' => array(228, -1, 2, 0), - 'SINH' => array(229, 1, 1, 0), - 'COSH' => array(230, 1, 1, 0), - 'TANH' => array(231, 1, 1, 0), - 'ASINH' => array(232, 1, 1, 0), - 'ACOSH' => array(233, 1, 1, 0), - 'ATANH' => array(234, 1, 1, 0), - 'DGET' => array(235, 3, 0, 0), - 'INFO' => array(244, 1, 1, 1), - 'DB' => array(247, -1, 1, 0), - 'FREQUENCY' => array(252, 2, 0, 0), - 'ERROR.TYPE' => array(261, 1, 1, 0), - 'REGISTER.ID' => array(267, -1, 1, 0), - 'AVEDEV' => array(269, -1, 0, 0), - 'BETADIST' => array(270, -1, 1, 0), - 'GAMMALN' => array(271, 1, 1, 0), - 'BETAINV' => array(272, -1, 1, 0), - 'BINOMDIST' => array(273, 4, 1, 0), - 'CHIDIST' => array(274, 2, 1, 0), - 'CHIINV' => array(275, 2, 1, 0), - 'COMBIN' => array(276, 2, 1, 0), - 'CONFIDENCE' => array(277, 3, 1, 0), - 'CRITBINOM' => array(278, 3, 1, 0), - 'EVEN' => array(279, 1, 1, 0), - 'EXPONDIST' => array(280, 3, 1, 0), - 'FDIST' => array(281, 3, 1, 0), - 'FINV' => array(282, 3, 1, 0), - 'FISHER' => array(283, 1, 1, 0), - 'FISHERINV' => array(284, 1, 1, 0), - 'FLOOR' => array(285, 2, 1, 0), - 'GAMMADIST' => array(286, 4, 1, 0), - 'GAMMAINV' => array(287, 3, 1, 0), - 'CEILING' => array(288, 2, 1, 0), - 'HYPGEOMDIST' => array(289, 4, 1, 0), - 'LOGNORMDIST' => array(290, 3, 1, 0), - 'LOGINV' => array(291, 3, 1, 0), - 'NEGBINOMDIST' => array(292, 3, 1, 0), - 'NORMDIST' => array(293, 4, 1, 0), - 'NORMSDIST' => array(294, 1, 1, 0), - 'NORMINV' => array(295, 3, 1, 0), - 'NORMSINV' => array(296, 1, 1, 0), - 'STANDARDIZE' => array(297, 3, 1, 0), - 'ODD' => array(298, 1, 1, 0), - 'PERMUT' => array(299, 2, 1, 0), - 'POISSON' => array(300, 3, 1, 0), - 'TDIST' => array(301, 3, 1, 0), - 'WEIBULL' => array(302, 4, 1, 0), - 'SUMXMY2' => array(303, 2, 2, 0), - 'SUMX2MY2' => array(304, 2, 2, 0), - 'SUMX2PY2' => array(305, 2, 2, 0), - 'CHITEST' => array(306, 2, 2, 0), - 'CORREL' => array(307, 2, 2, 0), - 'COVAR' => array(308, 2, 2, 0), - 'FORECAST' => array(309, 3, 2, 0), - 'FTEST' => array(310, 2, 2, 0), - 'INTERCEPT' => array(311, 2, 2, 0), - 'PEARSON' => array(312, 2, 2, 0), - 'RSQ' => array(313, 2, 2, 0), - 'STEYX' => array(314, 2, 2, 0), - 'SLOPE' => array(315, 2, 2, 0), - 'TTEST' => array(316, 4, 2, 0), - 'PROB' => array(317, -1, 2, 0), - 'DEVSQ' => array(318, -1, 0, 0), - 'GEOMEAN' => array(319, -1, 0, 0), - 'HARMEAN' => array(320, -1, 0, 0), - 'SUMSQ' => array(321, -1, 0, 0), - 'KURT' => array(322, -1, 0, 0), - 'SKEW' => array(323, -1, 0, 0), - 'ZTEST' => array(324, -1, 0, 0), - 'LARGE' => array(325, 2, 0, 0), - 'SMALL' => array(326, 2, 0, 0), - 'QUARTILE' => array(327, 2, 0, 0), - 'PERCENTILE' => array(328, 2, 0, 0), - 'PERCENTRANK' => array(329, -1, 0, 0), - 'MODE' => array(330, -1, 2, 0), - 'TRIMMEAN' => array(331, 2, 0, 0), - 'TINV' => array(332, 2, 1, 0), - 'CONCATENATE' => array(336, -1, 1, 0), - 'POWER' => array(337, 2, 1, 0), - 'RADIANS' => array(342, 1, 1, 0), - 'DEGREES' => array(343, 1, 1, 0), - 'SUBTOTAL' => array(344, -1, 0, 0), - 'SUMIF' => array(345, -1, 0, 0), - 'COUNTIF' => array(346, 2, 0, 0), - 'COUNTBLANK' => array(347, 1, 0, 0), - 'ROMAN' => array(354, -1, 1, 0), - ); + $this->_functions = [ + // public function ptg args class vol + 'COUNT' => [0, -1, 0, 0], + 'IF' => [1, -1, 1, 0], + 'ISNA' => [2, 1, 1, 0], + 'ISERROR' => [3, 1, 1, 0], + 'SUM' => [4, -1, 0, 0], + 'AVERAGE' => [5, -1, 0, 0], + 'MIN' => [6, -1, 0, 0], + 'MAX' => [7, -1, 0, 0], + 'ROW' => [8, -1, 0, 0], + 'COLUMN' => [9, -1, 0, 0], + 'NA' => [10, 0, 0, 0], + 'NPV' => [11, -1, 1, 0], + 'STDEV' => [12, -1, 0, 0], + 'DOLLAR' => [13, -1, 1, 0], + 'FIXED' => [14, -1, 1, 0], + 'SIN' => [15, 1, 1, 0], + 'COS' => [16, 1, 1, 0], + 'TAN' => [17, 1, 1, 0], + 'ATAN' => [18, 1, 1, 0], + 'PI' => [19, 0, 1, 0], + 'SQRT' => [20, 1, 1, 0], + 'EXP' => [21, 1, 1, 0], + 'LN' => [22, 1, 1, 0], + 'LOG10' => [23, 1, 1, 0], + 'ABS' => [24, 1, 1, 0], + 'INT' => [25, 1, 1, 0], + 'SIGN' => [26, 1, 1, 0], + 'ROUND' => [27, 2, 1, 0], + 'LOOKUP' => [28, -1, 0, 0], + 'INDEX' => [29, -1, 0, 1], + 'REPT' => [30, 2, 1, 0], + 'MID' => [31, 3, 1, 0], + 'LEN' => [32, 1, 1, 0], + 'VALUE' => [33, 1, 1, 0], + 'TRUE' => [34, 0, 1, 0], + 'FALSE' => [35, 0, 1, 0], + 'AND' => [36, -1, 0, 0], + 'OR' => [37, -1, 0, 0], + 'NOT' => [38, 1, 1, 0], + 'MOD' => [39, 2, 1, 0], + 'DCOUNT' => [40, 3, 0, 0], + 'DSUM' => [41, 3, 0, 0], + 'DAVERAGE' => [42, 3, 0, 0], + 'DMIN' => [43, 3, 0, 0], + 'DMAX' => [44, 3, 0, 0], + 'DSTDEV' => [45, 3, 0, 0], + 'VAR' => [46, -1, 0, 0], + 'DVAR' => [47, 3, 0, 0], + 'TEXT' => [48, 2, 1, 0], + 'LINEST' => [49, -1, 0, 0], + 'TREND' => [50, -1, 0, 0], + 'LOGEST' => [51, -1, 0, 0], + 'GROWTH' => [52, -1, 0, 0], + 'PV' => [56, -1, 1, 0], + 'FV' => [57, -1, 1, 0], + 'NPER' => [58, -1, 1, 0], + 'PMT' => [59, -1, 1, 0], + 'RATE' => [60, -1, 1, 0], + 'MIRR' => [61, 3, 0, 0], + 'IRR' => [62, -1, 0, 0], + 'RAND' => [63, 0, 1, 1], + 'MATCH' => [64, -1, 0, 0], + 'DATE' => [65, 3, 1, 0], + 'TIME' => [66, 3, 1, 0], + 'DAY' => [67, 1, 1, 0], + 'MONTH' => [68, 1, 1, 0], + 'YEAR' => [69, 1, 1, 0], + 'WEEKDAY' => [70, -1, 1, 0], + 'HOUR' => [71, 1, 1, 0], + 'MINUTE' => [72, 1, 1, 0], + 'SECOND' => [73, 1, 1, 0], + 'NOW' => [74, 0, 1, 1], + 'AREAS' => [75, 1, 0, 1], + 'ROWS' => [76, 1, 0, 1], + 'COLUMNS' => [77, 1, 0, 1], + 'OFFSET' => [78, -1, 0, 1], + 'SEARCH' => [82, -1, 1, 0], + 'TRANSPOSE' => [83, 1, 1, 0], + 'TYPE' => [86, 1, 1, 0], + 'ATAN2' => [97, 2, 1, 0], + 'ASIN' => [98, 1, 1, 0], + 'ACOS' => [99, 1, 1, 0], + 'CHOOSE' => [100, -1, 1, 0], + 'HLOOKUP' => [101, -1, 0, 0], + 'VLOOKUP' => [102, -1, 0, 0], + 'ISREF' => [105, 1, 0, 0], + 'LOG' => [109, -1, 1, 0], + 'CHAR' => [111, 1, 1, 0], + 'LOWER' => [112, 1, 1, 0], + 'UPPER' => [113, 1, 1, 0], + 'PROPER' => [114, 1, 1, 0], + 'LEFT' => [115, -1, 1, 0], + 'RIGHT' => [116, -1, 1, 0], + 'EXACT' => [117, 2, 1, 0], + 'TRIM' => [118, 1, 1, 0], + 'REPLACE' => [119, 4, 1, 0], + 'SUBSTITUTE' => [120, -1, 1, 0], + 'CODE' => [121, 1, 1, 0], + 'FIND' => [124, -1, 1, 0], + 'CELL' => [125, -1, 0, 1], + 'ISERR' => [126, 1, 1, 0], + 'ISTEXT' => [127, 1, 1, 0], + 'ISNUMBER' => [128, 1, 1, 0], + 'ISBLANK' => [129, 1, 1, 0], + 'T' => [130, 1, 0, 0], + 'N' => [131, 1, 0, 0], + 'DATEVALUE' => [140, 1, 1, 0], + 'TIMEVALUE' => [141, 1, 1, 0], + 'SLN' => [142, 3, 1, 0], + 'SYD' => [143, 4, 1, 0], + 'DDB' => [144, -1, 1, 0], + 'INDIRECT' => [148, -1, 1, 1], + 'CALL' => [150, -1, 1, 0], + 'CLEAN' => [162, 1, 1, 0], + 'MDETERM' => [163, 1, 2, 0], + 'MINVERSE' => [164, 1, 2, 0], + 'MMULT' => [165, 2, 2, 0], + 'IPMT' => [167, -1, 1, 0], + 'PPMT' => [168, -1, 1, 0], + 'COUNTA' => [169, -1, 0, 0], + 'PRODUCT' => [183, -1, 0, 0], + 'FACT' => [184, 1, 1, 0], + 'DPRODUCT' => [189, 3, 0, 0], + 'ISNONTEXT' => [190, 1, 1, 0], + 'STDEVP' => [193, -1, 0, 0], + 'VARP' => [194, -1, 0, 0], + 'DSTDEVP' => [195, 3, 0, 0], + 'DVARP' => [196, 3, 0, 0], + 'TRUNC' => [197, -1, 1, 0], + 'ISLOGICAL' => [198, 1, 1, 0], + 'DCOUNTA' => [199, 3, 0, 0], + 'ROUNDUP' => [212, 2, 1, 0], + 'ROUNDDOWN' => [213, 2, 1, 0], + 'RANK' => [216, -1, 0, 0], + 'ADDRESS' => [219, -1, 1, 0], + 'DAYS360' => [220, -1, 1, 0], + 'TODAY' => [221, 0, 1, 1], + 'VDB' => [222, -1, 1, 0], + 'MEDIAN' => [227, -1, 0, 0], + 'SUMPRODUCT' => [228, -1, 2, 0], + 'SINH' => [229, 1, 1, 0], + 'COSH' => [230, 1, 1, 0], + 'TANH' => [231, 1, 1, 0], + 'ASINH' => [232, 1, 1, 0], + 'ACOSH' => [233, 1, 1, 0], + 'ATANH' => [234, 1, 1, 0], + 'DGET' => [235, 3, 0, 0], + 'INFO' => [244, 1, 1, 1], + 'DB' => [247, -1, 1, 0], + 'FREQUENCY' => [252, 2, 0, 0], + 'ERROR.TYPE' => [261, 1, 1, 0], + 'REGISTER.ID' => [267, -1, 1, 0], + 'AVEDEV' => [269, -1, 0, 0], + 'BETADIST' => [270, -1, 1, 0], + 'GAMMALN' => [271, 1, 1, 0], + 'BETAINV' => [272, -1, 1, 0], + 'BINOMDIST' => [273, 4, 1, 0], + 'CHIDIST' => [274, 2, 1, 0], + 'CHIINV' => [275, 2, 1, 0], + 'COMBIN' => [276, 2, 1, 0], + 'CONFIDENCE' => [277, 3, 1, 0], + 'CRITBINOM' => [278, 3, 1, 0], + 'EVEN' => [279, 1, 1, 0], + 'EXPONDIST' => [280, 3, 1, 0], + 'FDIST' => [281, 3, 1, 0], + 'FINV' => [282, 3, 1, 0], + 'FISHER' => [283, 1, 1, 0], + 'FISHERINV' => [284, 1, 1, 0], + 'FLOOR' => [285, 2, 1, 0], + 'GAMMADIST' => [286, 4, 1, 0], + 'GAMMAINV' => [287, 3, 1, 0], + 'CEILING' => [288, 2, 1, 0], + 'HYPGEOMDIST' => [289, 4, 1, 0], + 'LOGNORMDIST' => [290, 3, 1, 0], + 'LOGINV' => [291, 3, 1, 0], + 'NEGBINOMDIST' => [292, 3, 1, 0], + 'NORMDIST' => [293, 4, 1, 0], + 'NORMSDIST' => [294, 1, 1, 0], + 'NORMINV' => [295, 3, 1, 0], + 'NORMSINV' => [296, 1, 1, 0], + 'STANDARDIZE' => [297, 3, 1, 0], + 'ODD' => [298, 1, 1, 0], + 'PERMUT' => [299, 2, 1, 0], + 'POISSON' => [300, 3, 1, 0], + 'TDIST' => [301, 3, 1, 0], + 'WEIBULL' => [302, 4, 1, 0], + 'SUMXMY2' => [303, 2, 2, 0], + 'SUMX2MY2' => [304, 2, 2, 0], + 'SUMX2PY2' => [305, 2, 2, 0], + 'CHITEST' => [306, 2, 2, 0], + 'CORREL' => [307, 2, 2, 0], + 'COVAR' => [308, 2, 2, 0], + 'FORECAST' => [309, 3, 2, 0], + 'FTEST' => [310, 2, 2, 0], + 'INTERCEPT' => [311, 2, 2, 0], + 'PEARSON' => [312, 2, 2, 0], + 'RSQ' => [313, 2, 2, 0], + 'STEYX' => [314, 2, 2, 0], + 'SLOPE' => [315, 2, 2, 0], + 'TTEST' => [316, 4, 2, 0], + 'PROB' => [317, -1, 2, 0], + 'DEVSQ' => [318, -1, 0, 0], + 'GEOMEAN' => [319, -1, 0, 0], + 'HARMEAN' => [320, -1, 0, 0], + 'SUMSQ' => [321, -1, 0, 0], + 'KURT' => [322, -1, 0, 0], + 'SKEW' => [323, -1, 0, 0], + 'ZTEST' => [324, -1, 0, 0], + 'LARGE' => [325, 2, 0, 0], + 'SMALL' => [326, 2, 0, 0], + 'QUARTILE' => [327, 2, 0, 0], + 'PERCENTILE' => [328, 2, 0, 0], + 'PERCENTRANK' => [329, -1, 0, 0], + 'MODE' => [330, -1, 2, 0], + 'TRIMMEAN' => [331, 2, 0, 0], + 'TINV' => [332, 2, 1, 0], + 'CONCATENATE' => [336, -1, 1, 0], + 'POWER' => [337, 2, 1, 0], + 'RADIANS' => [342, 1, 1, 0], + 'DEGREES' => [343, 1, 1, 0], + 'SUBTOTAL' => [344, -1, 0, 0], + 'SUMIF' => [345, -1, 0, 0], + 'COUNTIF' => [346, 2, 0, 0], + 'COUNTBLANK' => [347, 1, 0, 0], + 'ROMAN' => [354, -1, 1, 0], + ]; } /** @@ -561,45 +561,45 @@ protected function _convert($token) } elseif (is_numeric($token)) { return $this->_convertNumber($token); - // match references like A1 or $A$1 + // match references like A1 or $A$1 } elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token)) { return $this->_convertRef2d($token); - // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 + // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 } elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z](\d+)$/u",$token)) { return $this->_convertRef3d($token); - // match external references like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1 + // match external references like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1 } elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z](\d+)$/u",$token)) { return $this->_convertRef3d($token); - // match ranges like A1:B2 + // match ranges like A1:B2 } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) { return $this->_convertRange2d($token); - // match ranges like A1..B2 + // match ranges like A1..B2 } elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) { return $this->_convertRange2d($token); - // match external ranges like Sheet1!A1 or Sheet1:Sheet2!A1:B2 + // match external ranges like Sheet1!A1 or Sheet1:Sheet2!A1:B2 } elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/u",$token)) { return $this->_convertRange3d($token); - // match external ranges like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 + // match external ranges like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 } elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/u",$token)) { return $this->_convertRange3d($token); - // operators (including parentheses) + // operators (including parentheses) } elseif (isset($this->ptg[$token])) { return pack("C", $this->ptg[$token]); - // commented so argument number can be processed correctly. See toReversePolish(). - /*elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token)) - { - return($this->_convertFunction($token,$this->_func_args)); - }*/ + // commented so argument number can be processed correctly. See toReversePolish(). + /*elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token)) + { + return($this->_convertFunction($token,$this->_func_args)); + }*/ - // if it's an argument, ignore the token (the argument remains) + // if it's an argument, ignore the token (the argument remains) } elseif ($token == 'arg') { return ''; } @@ -643,10 +643,10 @@ protected function _convertString($string) } if ($this->_BIFF_version == 0x0500) { - return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string; + return pack("CC", $this->ptg['ptgStr'], strlen($string)) . $string; } elseif ($this->_BIFF_version == 0x0600) { $encoding = 0; // TODO: Unicode support - return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding).$string; + return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding) . $string; } } @@ -682,7 +682,7 @@ protected function _convertFunction($token, $num_args) * @access private * @param string $range An Excel range in the A1:A2 or A1..A2 format. */ - protected function _convertRange2d($range, $class=0) + protected function _convertRange2d($range, $class = 0) { // TODO: possible class value 0,1,2 check Formula.pm @@ -720,7 +720,7 @@ protected function _convertRange2d($range, $class=0) // TODO: use real error codes return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } - return $ptgArea . $row1 . $row2 . $col1. $col2; + return $ptgArea . $row1 . $row2 . $col1 . $col2; } /** @@ -745,10 +745,10 @@ protected function _convertRange3d($token) return $ext_ref; } } elseif ($this->_BIFF_version == 0x0600) { - $ext_ref = $this->_getRefIndex($ext_ref); - if (PEAR::isError($ext_ref)) { - return $ext_ref; - } + $ext_ref = $this->_getRefIndex($ext_ref); + if (PEAR::isError($ext_ref)) { + return $ext_ref; + } } // Split the range into 2 cell refs @@ -767,11 +767,11 @@ protected function _convertRange3d($token) } list($row2, $col2) = $cell_array2; } else { // It's a rows range (like 26:27) - $cells_array = $this->_rangeToPackedRange($cell1.':'.$cell2); - if (PEAR::isError($cells_array)) { - return $cells_array; - } - list($row1, $col1, $row2, $col2) = $cells_array; + $cells_array = $this->_rangeToPackedRange($cell1 . ':' . $cell2); + if (PEAR::isError($cells_array)) { + return $cells_array; + } + list($row1, $col1, $row2, $col2) = $cells_array; } // The ptg value depends on the class of the ptg. @@ -785,7 +785,7 @@ protected function _convertRange3d($token) return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } - return $ptgArea . $ext_ref . $row1 . $row2 . $col1. $col2; + return $ptgArea . $ext_ref . $row1 . $row2 . $col1 . $col2; } /** @@ -817,7 +817,7 @@ protected function _convertRef2d($cell) // TODO: use real error codes return $this->raiseError("Unknown class $class"); } - return $ptgRef.$row.$col; + return $ptgRef . $row . $col; } /** @@ -862,7 +862,7 @@ protected function _convertRef3d($cell) return $this->raiseError("Unknown class $class", 0, PEAR_ERROR_DIE); } - return $ptgRef . $ext_ref. $row . $col; + return $ptgRef . $ext_ref . $row . $col; } /** @@ -893,7 +893,7 @@ protected function _packExtRef($ext_ref) // Reverse max and min sheet numbers if necessary if ($sheet1 > $sheet2) { - list($sheet1, $sheet2) = array($sheet2, $sheet1); + list($sheet1, $sheet2) = [$sheet2, $sheet1]; } } else { // Single sheet name only. $sheet1 = $this->_getSheetIndex($ext_ref); @@ -939,7 +939,7 @@ protected function _getRefIndex($ext_ref) // Reverse max and min sheet numbers if necessary if ($sheet1 > $sheet2) { - list($sheet1, $sheet2) = array($sheet2, $sheet1); + list($sheet1, $sheet2) = [$sheet2, $sheet1]; } } else { // Single sheet name only. $sheet1 = $this->_getSheetIndex($ext_ref); @@ -1032,7 +1032,7 @@ protected function _cellToPackedRowcol($cell) } $row = pack('v', $row); - return array($row, $col); + return [$row, $col]; } /** @@ -1078,7 +1078,7 @@ protected function _rangeToPackedRange($range) $row1 = pack('v', $row1); $row2 = pack('v', $row2); - return array($row1, $col1, $row2, $col2); + return [$row1, $col1, $row2, $col2]; } /** @@ -1112,7 +1112,7 @@ protected function _cellToRowcol($cell) $row--; $col--; - return array($row, $col, $row_rel, $col_rel); + return [$row, $col, $row_rel, $col_rel]; } /** @@ -1131,7 +1131,7 @@ protected function _advance() } if ($i < ($formula_length - 1)) { - $this->_lookahead = $this->_formula[$i+1]; + $this->_lookahead = $this->_formula[$i + 1]; } $token = ''; } @@ -1139,7 +1139,7 @@ protected function _advance() while ($i < $formula_length) { $token .= $this->_formula[$i]; if ($i < ($formula_length - 1)) { - $this->_lookahead = $this->_formula[$i+1]; + $this->_lookahead = $this->_formula[$i + 1]; } else { $this->_lookahead = ''; } @@ -1154,7 +1154,7 @@ protected function _advance() } if ($i < ($formula_length - 2)) { - $this->_lookahead = $this->_formula[$i+2]; + $this->_lookahead = $this->_formula[$i + 2]; } else { // if we run out of characters _lookahead becomes empty $this->_lookahead = ''; } @@ -1230,63 +1230,53 @@ protected function _match($token) if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and !preg_match("/[0-9]/",$this->_lookahead) and ($this->_lookahead != ':') and ($this->_lookahead != '.') and - ($this->_lookahead != '!')) - { + ($this->_lookahead != '!')) { return $token; } // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and !preg_match("/[0-9]/",$this->_lookahead) and - ($this->_lookahead != ':') and ($this->_lookahead != '.')) - { + ($this->_lookahead != ':') and ($this->_lookahead != '.')) { return $token; } // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1) elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and !preg_match("/[0-9]/",$this->_lookahead) and - ($this->_lookahead != ':') and ($this->_lookahead != '.')) - { + ($this->_lookahead != ':') and ($this->_lookahead != '.')) { return $token; } // if it's a range (A1:A2) elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and - !preg_match("/[0-9]/",$this->_lookahead)) - { + !preg_match("/[0-9]/",$this->_lookahead)) { return $token; } // if it's a range (A1..A2) elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and - !preg_match("/[0-9]/",$this->_lookahead)) - { + !preg_match("/[0-9]/",$this->_lookahead)) { return $token; } // If it's an external range like Sheet1!A1 or Sheet1:Sheet2!A1:B2 elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and - !preg_match("/[0-9]/",$this->_lookahead)) - { + !preg_match("/[0-9]/",$this->_lookahead)) { return $token; } // If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2 elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and - !preg_match("/[0-9]/",$this->_lookahead)) - { + !preg_match("/[0-9]/",$this->_lookahead)) { return $token; } // If it's a number (check that it's not a sheet name or range) elseif (is_numeric($token) and - (!is_numeric($token.$this->_lookahead) or ($this->_lookahead == '')) and - ($this->_lookahead != '!') and ($this->_lookahead != ':')) - { + (!is_numeric($token . $this->_lookahead) or ($this->_lookahead == '')) and + ($this->_lookahead != '!') and ($this->_lookahead != ':')) { return $token; } // If it's a string (of maximum 255 characters) - elseif (preg_match("/^\"[^\"]{0,255}\"$/",$token)) - { + elseif (preg_match("/^\"[^\"]{0,255}\"$/",$token)) { return $token; } // if it's a public function call - elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "(")) - { + elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "(")) { return $token; } return ''; @@ -1374,7 +1364,7 @@ protected function _condition() $result2 = $this->_expression(); if (PEAR::isError($result2)) { return $result2; - } + } $result = $this->_createTree('ptgConcat', $result, $result2); } return $result; @@ -1409,7 +1399,7 @@ protected function _expression() } while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) or ($this->_current_token == SPREADSHEET_EXCEL_WRITER_SUB)) { - /**/ + /**/ if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_ADD) { $this->_advance(); $result2 = $this->_term(); @@ -1458,7 +1448,7 @@ protected function _term() } while (($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) or ($this->_current_token == SPREADSHEET_EXCEL_WRITER_DIV)) { - /**/ + /**/ if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_MUL) { $this->_advance(); $result2 = $this->_fact(); @@ -1501,62 +1491,54 @@ protected function _fact() return $result; } // if it's a reference - if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token)) - { + if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; } // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1) - elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/u",$this->_current_token)) - { + elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/u",$this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; } // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1) - elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/u",$this->_current_token)) - { + elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/u",$this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; } // if it's a range elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or - preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token)) - { + preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token)) { $result = $this->_current_token; $this->_advance(); return $result; } // If it's an external range (Sheet1!A1 or Sheet1!A1:B2) - elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$this->_current_token)) - { + elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$this->_current_token)) { $result = $this->_current_token; $this->_advance(); return $result; } // If it's an external range ('Sheet1'!A1 or 'Sheet1'!A1:B2) - elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$this->_current_token)) - { + elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$this->_current_token)) { $result = $this->_current_token; $this->_advance(); return $result; - } elseif (is_numeric($this->_current_token)) - { + } elseif (is_numeric($this->_current_token)) { $result = $this->_createTree($this->_current_token, '', ''); $this->_advance(); return $result; } // if it's a public function call - elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token)) - { + elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token)) { $result = $this->_func(); return $result; } - return $this->raiseError("Syntax error: ".$this->_current_token. - ", lookahead: ".$this->_lookahead. - ", current char: ".$this->_current_char); + return $this->raiseError("Syntax error: " . $this->_current_token . + ", lookahead: " . $this->_lookahead . + ", current char: " . $this->_current_char); } /** @@ -1574,14 +1556,13 @@ protected function _func() $this->_advance(); $this->_advance(); // eat the "(" while ($this->_current_token != ')') { - /**/ + /**/ if ($num_args > 0) { if ($this->_current_token == SPREADSHEET_EXCEL_WRITER_COMA or - $this->_current_token == SPREADSHEET_EXCEL_WRITER_SEMICOLON) - { + $this->_current_token == SPREADSHEET_EXCEL_WRITER_SEMICOLON) { $this->_advance(); // eat the "," or ";" } else { - return $this->raiseError("Syntax error: comma expected in ". + return $this->raiseError("Syntax error: comma expected in " . "public function $function, arg #{$num_args}"); } $result2 = $this->_condition(); @@ -1624,7 +1605,7 @@ protected function _func() */ protected function _createTree($value, $left, $right) { - return array('value' => $value, 'left' => $left, 'right' => $right); + return ['value' => $value, 'left' => $left, 'right' => $right]; } /** @@ -1654,7 +1635,7 @@ protected function _createTree($value, $left, $right) * @param array $tree The optional tree to convert. * @return string The tree in reverse polish notation */ - public function toReversePolish($tree = array()) + public function toReversePolish($tree = []) { $polish = ""; // the string we are going to return if (empty($tree)) { // If it's the first call use _parse_tree @@ -1691,8 +1672,7 @@ public function toReversePolish($tree = array()) !preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']) and !preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']) and !is_numeric($tree['value']) and - !isset($this->ptg[$tree['value']])) - { + !isset($this->ptg[$tree['value']])) { // left subtree for a public function is always an array. if ($tree['left'] != '') { $left_tree = $this->toReversePolish($tree['left']); @@ -1703,7 +1683,7 @@ public function toReversePolish($tree = array()) return $left_tree; } // add it's left subtree and return. - return $left_tree.$this->_convertFunction($tree['value'], $tree['right']); + return $left_tree . $this->_convertFunction($tree['value'], $tree['right']); } else { $converted_tree = $this->_convert($tree['value']); if (PEAR::isError($converted_tree)) { diff --git a/Spreadsheet/Excel/Writer/Validator.php b/Spreadsheet/Excel/Writer/Validator.php index 36123e1..a4ed077 100644 --- a/Spreadsheet/Excel/Writer/Validator.php +++ b/Spreadsheet/Excel/Writer/Validator.php @@ -48,20 +48,20 @@ */ class Spreadsheet_Excel_Writer_Validator { - public $_type; - public $_style; - public $_fixedList; - public $_blank; - public $_incell; - public $_showprompt; - public $_showerror; - public $_title_prompt; - public $_descr_prompt; - public $_title_error; - public $_descr_error; - public $_operator; - public $_formula1; - public $_formula2; + public $_type; + public $_style; + public $_fixedList; + public $_blank; + public $_incell; + public $_showprompt; + public $_showerror; + public $_title_prompt; + public $_descr_prompt; + public $_title_error; + public $_descr_error; + public $_operator; + public $_formula1; + public $_formula2; /** * The parser from the workbook. Used to parse validation formulas also * @var Spreadsheet_Excel_Writer_Parser @@ -87,29 +87,29 @@ public function __construct($parser) $this->_formula2 = ''; } - public function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true) - { - $this->_showprompt = $showPrompt; - $this->_title_prompt = $promptTitle; - $this->_descr_prompt = $promptDescription; - } + public function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true) + { + $this->_showprompt = $showPrompt; + $this->_title_prompt = $promptTitle; + $this->_descr_prompt = $promptDescription; + } - public function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true) - { - $this->_showerror = $showError; - $this->_title_error = $errorTitle; - $this->_descr_error = $errorDescription; - } + public function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true) + { + $this->_showerror = $showError; + $this->_title_error = $errorTitle; + $this->_descr_error = $errorDescription; + } - public function allowBlank() - { - $this->_blank = true; - } + public function allowBlank() + { + $this->_blank = true; + } - public function onInvalidStop() - { - $this->_style = 0x00; - } + public function onInvalidStop() + { + $this->_style = 0x00; + } public function onInvalidWarn() { @@ -170,32 +170,32 @@ protected function _getOptions() if ($this->_showerror) { $options |= 0x80000; } - $options |= $this->_operator << 20; + $options |= $this->_operator << 20; - return $options; - } + return $options; + } - protected function _getData() - { - $title_prompt_len = strlen($this->_title_prompt); - $descr_prompt_len = strlen($this->_descr_prompt); - $title_error_len = strlen($this->_title_error); - $descr_error_len = strlen($this->_descr_error); + protected function _getData() + { + $title_prompt_len = strlen($this->_title_prompt); + $descr_prompt_len = strlen($this->_descr_prompt); + $title_error_len = strlen($this->_title_error); + $descr_error_len = strlen($this->_descr_error); - $formula1_size = strlen($this->_formula1); - $formula2_size = strlen($this->_formula2); + $formula1_size = strlen($this->_formula1); + $formula2_size = strlen($this->_formula2); - $data = pack("V", $this->_getOptions()); - $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt; - $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error; - $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt; - $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error; + $data = pack("V", $this->_getOptions()); + $data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt; + $data .= pack("vC", $title_error_len, 0x00) . $this->_title_error; + $data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt; + $data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error; - $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1; - $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2; + $data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1; + $data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2; - return $data; - } + return $data; + } } /*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation diff --git a/Spreadsheet/Excel/Writer/Workbook.php b/Spreadsheet/Excel/Writer/Workbook.php index fbc5e11..5b97fe5 100644 --- a/Spreadsheet/Excel/Writer/Workbook.php +++ b/Spreadsheet/Excel/Writer/Workbook.php @@ -228,19 +228,19 @@ public function __construct($filename) $this->_biffsize = 0; $this->_sheetname = 'Sheet'; $this->_tmp_format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version); - $this->_worksheets = array(); - $this->_sheetnames = array(); - $this->_formats = array(); - $this->_palette = array(); + $this->_worksheets = []; + $this->_sheetnames = []; + $this->_formats = []; + $this->_palette = []; $this->_codepage = 0x04E4; // FIXME: should change for BIFF8 $this->_country_code = -1; $this->_string_sizeinfo = 3; // Add the default format for hyperlinks - $this->_url_format = $this->addFormat(array('color' => 'blue', 'underline' => 1)); + $this->_url_format = $this->addFormat(['color' => 'blue', 'underline' => 1]); $this->_str_total = 0; $this->_str_unique = 0; - $this->_str_table = array(); + $this->_str_table = []; $this->_timestamp = time(); $this->_setPaletteXl97(); @@ -356,12 +356,11 @@ public function addWorksheet($name = '') $sheetname = $this->_sheetname; if ($name == '') { - $name = $sheetname.($index+1); + $name = $sheetname . ($index + 1); } // Check that sheetname is <= 31 chars (Excel limit before BIFF8). - if ($this->_BIFF_version != 0x0600) - { + if ($this->_BIFF_version != 0x0600) { if (strlen($name) > 31) { return $this->raiseError("Sheetname $name must be <= 31 chars"); } @@ -380,11 +379,11 @@ public function addWorksheet($name = '') } $worksheet = new Spreadsheet_Excel_Writer_Worksheet($this->_BIFF_version, - $name, $index, - $this->_activesheet, $this->_firstsheet, - $this->_str_total, $this->_str_unique, - $this->_str_table, $this->_url_format, - $this->_parser, $this->_tmp_dir); + $name, $index, + $this->_activesheet, $this->_firstsheet, + $this->_str_total, $this->_str_unique, + $this->_str_table, $this->_url_format, + $this->_parser, $this->_tmp_dir); $this->_worksheets[$index] = $worksheet; // Store ref for iterator $this->_sheetnames[$index] = $name; // Store EXTERNSHEET names @@ -400,7 +399,7 @@ public function addWorksheet($name = '') * @param array $properties array with properties for initializing the format. * @return Spreadsheet_Excel_Writer_Format */ - public function addFormat($properties = array()) + public function addFormat($properties = []) { $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties); $this->_xf_index += 1; @@ -450,15 +449,14 @@ public function setCustomColor($index, $red, $green, $blue) // Check that the colour components are in the right range if (($red < 0 or $red > 255) || ($green < 0 or $green > 255) || - ($blue < 0 or $blue > 255)) - { + ($blue < 0 or $blue > 255)) { return $this->raiseError("Color component outside range: 0 <= color <= 255"); } $index -= 8; // Adjust colour index (wingless dragonfly) // Set the RGB value - $this->_palette[$index] = array($red, $green, $blue, 0); + $this->_palette[$index] = [$red, $green, $blue, 0]; return ($index + 8); } @@ -469,64 +467,64 @@ public function setCustomColor($index, $red, $green, $blue) */ protected function _setPaletteXl97() { - $this->_palette = array( - array(0x00, 0x00, 0x00, 0x00), // 8 - array(0xff, 0xff, 0xff, 0x00), // 9 - array(0xff, 0x00, 0x00, 0x00), // 10 - array(0x00, 0xff, 0x00, 0x00), // 11 - array(0x00, 0x00, 0xff, 0x00), // 12 - array(0xff, 0xff, 0x00, 0x00), // 13 - array(0xff, 0x00, 0xff, 0x00), // 14 - array(0x00, 0xff, 0xff, 0x00), // 15 - array(0x80, 0x00, 0x00, 0x00), // 16 - array(0x00, 0x80, 0x00, 0x00), // 17 - array(0x00, 0x00, 0x80, 0x00), // 18 - array(0x80, 0x80, 0x00, 0x00), // 19 - array(0x80, 0x00, 0x80, 0x00), // 20 - array(0x00, 0x80, 0x80, 0x00), // 21 - array(0xc0, 0xc0, 0xc0, 0x00), // 22 - array(0x80, 0x80, 0x80, 0x00), // 23 - array(0x99, 0x99, 0xff, 0x00), // 24 - array(0x99, 0x33, 0x66, 0x00), // 25 - array(0xff, 0xff, 0xcc, 0x00), // 26 - array(0xcc, 0xff, 0xff, 0x00), // 27 - array(0x66, 0x00, 0x66, 0x00), // 28 - array(0xff, 0x80, 0x80, 0x00), // 29 - array(0x00, 0x66, 0xcc, 0x00), // 30 - array(0xcc, 0xcc, 0xff, 0x00), // 31 - array(0x00, 0x00, 0x80, 0x00), // 32 - array(0xff, 0x00, 0xff, 0x00), // 33 - array(0xff, 0xff, 0x00, 0x00), // 34 - array(0x00, 0xff, 0xff, 0x00), // 35 - array(0x80, 0x00, 0x80, 0x00), // 36 - array(0x80, 0x00, 0x00, 0x00), // 37 - array(0x00, 0x80, 0x80, 0x00), // 38 - array(0x00, 0x00, 0xff, 0x00), // 39 - array(0x00, 0xcc, 0xff, 0x00), // 40 - array(0xcc, 0xff, 0xff, 0x00), // 41 - array(0xcc, 0xff, 0xcc, 0x00), // 42 - array(0xff, 0xff, 0x99, 0x00), // 43 - array(0x99, 0xcc, 0xff, 0x00), // 44 - array(0xff, 0x99, 0xcc, 0x00), // 45 - array(0xcc, 0x99, 0xff, 0x00), // 46 - array(0xff, 0xcc, 0x99, 0x00), // 47 - array(0x33, 0x66, 0xff, 0x00), // 48 - array(0x33, 0xcc, 0xcc, 0x00), // 49 - array(0x99, 0xcc, 0x00, 0x00), // 50 - array(0xff, 0xcc, 0x00, 0x00), // 51 - array(0xff, 0x99, 0x00, 0x00), // 52 - array(0xff, 0x66, 0x00, 0x00), // 53 - array(0x66, 0x66, 0x99, 0x00), // 54 - array(0x96, 0x96, 0x96, 0x00), // 55 - array(0x00, 0x33, 0x66, 0x00), // 56 - array(0x33, 0x99, 0x66, 0x00), // 57 - array(0x00, 0x33, 0x00, 0x00), // 58 - array(0x33, 0x33, 0x00, 0x00), // 59 - array(0x99, 0x33, 0x00, 0x00), // 60 - array(0x99, 0x33, 0x66, 0x00), // 61 - array(0x33, 0x33, 0x99, 0x00), // 62 - array(0x33, 0x33, 0x33, 0x00), // 63 - ); + $this->_palette = [ + [0x00, 0x00, 0x00, 0x00], // 8 + [0xff, 0xff, 0xff, 0x00], // 9 + [0xff, 0x00, 0x00, 0x00], // 10 + [0x00, 0xff, 0x00, 0x00], // 11 + [0x00, 0x00, 0xff, 0x00], // 12 + [0xff, 0xff, 0x00, 0x00], // 13 + [0xff, 0x00, 0xff, 0x00], // 14 + [0x00, 0xff, 0xff, 0x00], // 15 + [0x80, 0x00, 0x00, 0x00], // 16 + [0x00, 0x80, 0x00, 0x00], // 17 + [0x00, 0x00, 0x80, 0x00], // 18 + [0x80, 0x80, 0x00, 0x00], // 19 + [0x80, 0x00, 0x80, 0x00], // 20 + [0x00, 0x80, 0x80, 0x00], // 21 + [0xc0, 0xc0, 0xc0, 0x00], // 22 + [0x80, 0x80, 0x80, 0x00], // 23 + [0x99, 0x99, 0xff, 0x00], // 24 + [0x99, 0x33, 0x66, 0x00], // 25 + [0xff, 0xff, 0xcc, 0x00], // 26 + [0xcc, 0xff, 0xff, 0x00], // 27 + [0x66, 0x00, 0x66, 0x00], // 28 + [0xff, 0x80, 0x80, 0x00], // 29 + [0x00, 0x66, 0xcc, 0x00], // 30 + [0xcc, 0xcc, 0xff, 0x00], // 31 + [0x00, 0x00, 0x80, 0x00], // 32 + [0xff, 0x00, 0xff, 0x00], // 33 + [0xff, 0xff, 0x00, 0x00], // 34 + [0x00, 0xff, 0xff, 0x00], // 35 + [0x80, 0x00, 0x80, 0x00], // 36 + [0x80, 0x00, 0x00, 0x00], // 37 + [0x00, 0x80, 0x80, 0x00], // 38 + [0x00, 0x00, 0xff, 0x00], // 39 + [0x00, 0xcc, 0xff, 0x00], // 40 + [0xcc, 0xff, 0xff, 0x00], // 41 + [0xcc, 0xff, 0xcc, 0x00], // 42 + [0xff, 0xff, 0x99, 0x00], // 43 + [0x99, 0xcc, 0xff, 0x00], // 44 + [0xff, 0x99, 0xcc, 0x00], // 45 + [0xcc, 0x99, 0xff, 0x00], // 46 + [0xff, 0xcc, 0x99, 0x00], // 47 + [0x33, 0x66, 0xff, 0x00], // 48 + [0x33, 0xcc, 0xcc, 0x00], // 49 + [0x99, 0xcc, 0x00, 0x00], // 50 + [0xff, 0xcc, 0x00, 0x00], // 51 + [0xff, 0x99, 0x00, 0x00], // 52 + [0xff, 0x66, 0x00, 0x00], // 53 + [0x66, 0x66, 0x99, 0x00], // 54 + [0x96, 0x96, 0x96, 0x00], // 55 + [0x00, 0x33, 0x66, 0x00], // 56 + [0x33, 0x99, 0x66, 0x00], // 57 + [0x00, 0x33, 0x00, 0x00], // 58 + [0x33, 0x33, 0x00, 0x00], // 59 + [0x99, 0x33, 0x00, 0x00], // 60 + [0x99, 0x33, 0x66, 0x00], // 61 + [0x33, 0x33, 0x99, 0x00], // 62 + [0x33, 0x33, 0x33, 0x00], // 63 + ]; } /** @@ -624,7 +622,7 @@ protected function _storeOLEFile() } $res = $OLE->init(); if ($this->isError($res)) { - return $this->raiseError("OLE Error: ".$res->getMessage()); + return $this->raiseError("OLE Error: " . $res->getMessage()); } $OLE->append($this->_data); @@ -635,14 +633,14 @@ protected function _storeOLEFile() } } - $root = new OLE_PPS_Root($this->_timestamp, $this->_timestamp, array($OLE)); + $root = new OLE_PPS_Root($this->_timestamp, $this->_timestamp, [$OLE]); if ($this->_tmp_dir != '') { $root->setTempDir($this->_tmp_dir); } $res = $root->save($this->_filename); if ($this->isError($res)) { - return $this->raiseError("OLE Error: ".$res->getMessage()); + return $this->raiseError("OLE Error: " . $res->getMessage()); } return true; } @@ -700,14 +698,14 @@ protected function _storeAllFonts() // Note: Fonts are 0-indexed. According to the SDK there is no index 4, // so the following fonts are 0, 1, 2, 3, 5 // - for ($i = 1; $i <= 5; $i++){ + for ($i = 1; $i <= 5; $i++) { $this->_append($font); } // Iterate through the XF objects and write a FONT record if it isn't the // same as the default FONT and if it hasn't already been used. // - $fonts = array(); + $fonts = []; $index = 6; // The first user defined FONT $key = $format->getFontKey(); // The default font from _tmp_format @@ -738,8 +736,8 @@ protected function _storeAllFonts() protected function _storeAllNumFormats() { // Leaning num_format syndrome - $hash_num_formats = array(); - $num_formats = array(); + $hash_num_formats = []; + $num_formats = []; $index = 164; // Iterate through the XF objects and write a FORMAT record if it isn't a @@ -822,7 +820,6 @@ protected function _storeAllStyles() * @access private */ protected function _storeExterns() - { // Create EXTERNCOUNT with number of worksheets $this->_storeExterncount(count($this->_worksheets)); @@ -852,7 +849,7 @@ protected function _storeNames() $this->_worksheets[$i]->print_rowmax, $this->_worksheets[$i]->print_colmin, $this->_worksheets[$i]->print_colmax - ); + ); } } @@ -877,7 +874,7 @@ protected function _storeNames() $rowmax, $colmin, $colmax - ); + ); } elseif (isset($rowmin)) { // Row title has been defined. $this->_storeNameShort( @@ -887,7 +884,7 @@ protected function _storeNames() $rowmax, 0x00, 0xff - ); + ); } elseif (isset($colmin)) { // Column title has been defined. $this->_storeNameShort( @@ -897,7 +894,7 @@ protected function _storeNames() 0x3fff, $colmin, $colmax - ); + ); } else { // Print title hasn't been defined. } @@ -951,9 +948,9 @@ protected function _storeWindow1() $header = pack("vv", $record, $length); $data = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn, - $grbit, - $itabCur, $itabFirst, - $ctabsel, $wTabRatio); + $grbit, + $itabCur, $itabFirst, + $ctabsel, $wTabRatio); $this->_append($header . $data); } @@ -987,7 +984,7 @@ protected function _storeBoundsheet($sheetname,$offset) } else { $data = pack("VvC", $offset, $grbit, $cch); } - $this->_append($header.$data.$sheetname); + $this->_append($header . $data . $sheetname); } /** @@ -1065,7 +1062,7 @@ protected function _storeNumFormat($format, $ifmt) } if ($this->_BIFF_version == 0x0600 && function_exists('iconv')) { // Encode format String - if (mb_detect_encoding($format, 'auto') !== 'UTF-16LE'){ + if (mb_detect_encoding($format, 'auto') !== 'UTF-16LE') { $format = iconv(mb_detect_encoding($format, 'auto'),'UTF-16LE',$format); } $encoding = 1; @@ -1179,7 +1176,7 @@ protected function _storeNameShort($index, $type, $rowmin, $rowmax, $colmin, $co $rgch = $type; // Built-in name type $unknown03 = 0x3b; - $unknown04 = 0xffff-$index; + $unknown04 = 0xffff - $index; $unknown05 = 0x0000; $unknown06 = 0x0000; $unknown07 = 0x1087; @@ -1245,7 +1242,7 @@ protected function _storeNameLong($index, $type, $rowmin, $rowmax, $colmin, $col $unknown01 = 0x29; $unknown02 = 0x002b; $unknown03 = 0x3b; - $unknown04 = 0xffff-$index; + $unknown04 = 0xffff - $index; $unknown05 = 0x0000; $unknown06 = 0x0000; $unknown07 = 0x1087; @@ -1359,7 +1356,7 @@ protected function _calculateSharedStringsSizes() $continue_limit = 8208; $block_length = 0; $written = 0; - $this->_block_sizes = array(); + $this->_block_sizes = []; $continue = 0; foreach (array_keys($this->_str_table) as $string) { diff --git a/Spreadsheet/Excel/Writer/Worksheet.php b/Spreadsheet/Excel/Writer/Worksheet.php index 760c898..e36a743 100644 --- a/Spreadsheet/Excel/Writer/Worksheet.php +++ b/Spreadsheet/Excel/Writer/Worksheet.php @@ -467,11 +467,11 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr * @access private */ public function __construct($BIFF_version, $name, - $index, &$activesheet, - &$firstsheet, &$str_total, - &$str_unique, &$str_table, - $url_format, $parser, - $tmp_dir) + $index, &$activesheet, + &$firstsheet, &$str_total, + &$str_unique, &$str_table, + $url_format, $parser, + $tmp_dir) { // It needs to call its parent's constructor explicitly parent::__construct(); @@ -503,9 +503,9 @@ public function __construct($BIFF_version, $name, $this->_dim_rowmax = 0; $this->_dim_colmin = $colmax + 1; $this->_dim_colmax = 0; - $this->_colinfo = array(); - $this->_selection = array(0, 0, 0, 0); - $this->_panes = array(); + $this->_colinfo = []; + $this->_selection = [0, 0, 0, 0]; + $this->_panes = []; $this->_active_pane = 3; $this->_frozen = 0; $this->selected = 0; @@ -540,14 +540,14 @@ public function __construct($BIFF_version, $name, $this->_fit_width = 0; $this->_fit_height = 0; - $this->_hbreaks = array(); - $this->_vbreaks = array(); + $this->_hbreaks = []; + $this->_vbreaks = []; $this->_protect = 0; $this->_password = null; - $this->col_sizes = array(); - $this->_row_sizes = array(); + $this->col_sizes = []; + $this->_row_sizes = []; $this->_zoom = 100; $this->_print_scale = 100; @@ -559,11 +559,11 @@ public function __construct($BIFF_version, $name, $this->_outline_on = 1; $this->_Arabic = 0; - $this->_merged_ranges = array(); + $this->_merged_ranges = []; $this->_input_encoding = ''; - $this->_dv = array(); + $this->_dv = []; $this->_tmp_dir = $tmp_dir; $this->_tmp_file = ''; @@ -675,7 +675,7 @@ public function close($sheetnames) // Prepend GRIDSET $this->_storeGridset(); - // Prepend GUTS + // Prepend GUTS if ($this->_BIFF_version == 0x0500) { $this->_storeGuts(); } @@ -689,7 +689,7 @@ public function close($sheetnames) // Prepend EXTERNSHEET references if ($this->_BIFF_version == 0x0500) { for ($i = $num_sheets; $i > 0; $i--) { - $sheetname = $sheetnames[$i-1]; + $sheetname = $sheetnames[$i - 1]; $this->_storeExternsheet($sheetname); } } @@ -801,15 +801,14 @@ public function setMerge($first_row, $first_col, $last_row, $last_col) } $max_record_ranges = floor(($this->_limit - 6) / 8); - if ($this->_merged_cells_counter >= $max_record_ranges) - { + if ($this->_merged_cells_counter >= $max_record_ranges) { $this->_merged_cells_record++; $this->_merged_cells_counter = 0; - } + } // don't check rowmin, rowmax, etc... because we don't know when this // is going to be called - $this->_merged_ranges[$this->_merged_cells_record][] = array($first_row, $first_col, $last_row, $last_col); + $this->_merged_ranges[$this->_merged_cells_record][] = [$first_row, $first_col, $last_row, $last_col]; $this->_merged_cells_counter++; } @@ -877,36 +876,30 @@ public function protect($password) public function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0) { // added by Dan Lynn _colinfo as $key => $colinfo) - { + foreach ($this->_colinfo as $key => $colinfo) { $existing_start = $colinfo[0]; $existing_end = $colinfo[1]; // if the new range starts within another range - if ($firstcol > $existing_start && $firstcol < $existing_end) - { // trim the existing range to the beginning of the new range + if ($firstcol > $existing_start && $firstcol < $existing_end) { // trim the existing range to the beginning of the new range $this->_colinfo[$key][1] = $firstcol - 1; // if the new range lies WITHIN the existing range - if ($lastcol < $existing_end) - { // split the existing range by adding a range after our new range - $this->_colinfo[] = array($lastcol+1, $existing_end, $colinfo[2], /* format */ $colinfo[3], $colinfo[4], $colinfo[5]); + if ($lastcol < $existing_end) { // split the existing range by adding a range after our new range + $this->_colinfo[] = [$lastcol + 1, $existing_end, $colinfo[2], /* format */ $colinfo[3], $colinfo[4], $colinfo[5]]; } } // if the new range ends inside an existing range - elseif ($lastcol > $existing_start && $lastcol < $existing_end) - { // trim the existing range to the end of the new range + elseif ($lastcol > $existing_start && $lastcol < $existing_end) { // trim the existing range to the end of the new range $this->_colinfo[$key][0] = $lastcol + 1; } // if the new range completely overlaps the existing range - elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) - { + elseif ($firstcol <= $existing_start && $lastcol >= $existing_end) { unset($this->_colinfo[$key]); } } // added by Dan Lynn _colinfo = array_values($this->_colinfo); - $this->_colinfo[] = array($firstcol, $lastcol, $width, $format, $hidden, $level); + $this->_colinfo[] = [$firstcol, $lastcol, $width, $format, $hidden, $level]; // Set width to zero if column is hidden $width = ($hidden) ? 0 : $width; - for ($col = $firstcol; $col <= $lastcol; $col++) - { + for ($col = $firstcol; $col <= $lastcol; $col++) { $this->col_sizes[$col] = $width; } } @@ -922,7 +915,7 @@ public function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = */ public function setSelection($first_row,$first_column,$last_row,$last_column) { - $this->_selection = array($first_row, $first_column, $last_row, $last_column); + $this->_selection = [$first_row, $first_column, $last_row, $last_column]; } /** @@ -1445,22 +1438,22 @@ protected function _substituteCellref($cell) // Convert a column range: 'A:A' or 'B:G' if (preg_match("/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) { - list($no_use, $col1) = $this->_cellToRowcol($match[1] .'1'); // Add a dummy row - list($no_use, $col2) = $this->_cellToRowcol($match[2] .'1'); // Add a dummy row - return (array($col1, $col2)); + list($no_use, $col1) = $this->_cellToRowcol($match[1] . '1'); // Add a dummy row + list($no_use, $col2) = $this->_cellToRowcol($match[2] . '1'); // Add a dummy row + return ([$col1, $col2]); } // Convert a cell range: 'A1:B7' if (preg_match("/\\$?([A-I]?[A-Z]\\$?\\d+):\\$?([A-I]?[A-Z]\\$?\\d+)/", $cell, $match)) { list($row1, $col1) = $this->_cellToRowcol($match[1]); list($row2, $col2) = $this->_cellToRowcol($match[2]); - return (array($row1, $col1, $row2, $col2)); + return ([$row1, $col1, $row2, $col2]); } // Convert a cell reference: 'A1' or 'AD2000' if (preg_match("/\\$?([A-I]?[A-Z]\\$?\\d+)/", $cell, $match)) { list($row1, $col1) = $this->_cellToRowcol($match[1]); - return (array($row1, $col1)); + return ([$row1, $col1]); } // TODO use real error codes @@ -1488,7 +1481,7 @@ protected function _cellToRowcol($cell) while ($chars) { $char = array_pop($chars); // LS char first - $col += (ord($char) -ord('A') +1) * pow(26,$expn); + $col += (ord($char) - ord('A') + 1) * pow(26,$expn); $expn++; } @@ -1496,7 +1489,7 @@ protected function _cellToRowcol($cell) $row--; $col--; - return (array($row, $col)); + return ([$row, $col]); } /** @@ -1547,7 +1540,7 @@ public function setOutline($visible = true, $symbols_below = true, $symbols_righ if ($this->_outline_on) { $this->_outline_on = 1; } - } + } /** * This method sets the worksheet direction to right-to-left (RTL) @@ -1557,7 +1550,7 @@ public function setOutline($visible = true, $symbols_below = true, $symbols_righ public function setRTL($rtl = true) { $this->_Arabic = ($rtl ? 1 : 0); - } + } /****************************************************************************** ******************************************************************************* @@ -1594,16 +1587,16 @@ public function writeNumber($row, $col, $num, $format = null) if ($col >= $this->_xls_colmax) { return (-2); } - if ($row < $this->_dim_rowmin) { + if ($row < $this->_dim_rowmin) { $this->_dim_rowmin = $row; } - if ($row > $this->_dim_rowmax) { + if ($row > $this->_dim_rowmax) { $this->_dim_rowmax = $row; } - if ($col < $this->_dim_colmin) { + if ($col < $this->_dim_colmin) { $this->_dim_colmin = $col; } - if ($col > $this->_dim_colmax) { + if ($col > $this->_dim_colmax) { $this->_dim_colmax = $col; } @@ -1614,7 +1607,7 @@ public function writeNumber($row, $col, $num, $format = null) $xl_double = strrev($xl_double); } - $this->_append($header.$data.$xl_double); + $this->_append($header . $data . $xl_double); return (0); } @@ -1686,10 +1679,10 @@ public function writeString($row, $col, $str, $format = null) */ public function setInputEncoding($encoding) { - if ($encoding != 'UTF-16LE' && !function_exists('iconv')) { - $this->raiseError("Using an input encoding other than UTF-16LE requires PHP support for iconv"); - } - $this->_input_encoding = $encoding; + if ($encoding != 'UTF-16LE' && !function_exists('iconv')) { + $this->raiseError("Using an input encoding other than UTF-16LE requires PHP support for iconv"); + } + $this->_input_encoding = $encoding; } /** @@ -1714,12 +1707,10 @@ public function writeStringBIFF8($row, $col, $str, $format = null) // (apparently the length is expected to be the number of 16-bit code points, not the number of characters). // Instead, always use the byte length divided by two for Unicode strings, and if mb_strlen() exists use // mb_strlen($str, '8bit') just in case mbstring.func_overload is set to overload strlen(). - if ($this->_input_encoding == 'UTF-16LE') - { + if ($this->_input_encoding == 'UTF-16LE') { $strlen = (function_exists('mb_strlen') ? mb_strlen($str, '8bit') : strlen($str)) / 2; $encoding = 0x1; - } elseif ($this->_input_encoding != '') - { + } elseif ($this->_input_encoding != '') { $str = iconv($this->_input_encoding, 'UTF-16LE', $str); $strlen = (function_exists('mb_strlen') ? mb_strlen($str, '8bit') : strlen($str)) / 2; $encoding = 0x1; @@ -1738,7 +1729,7 @@ public function writeStringBIFF8($row, $col, $str, $format = null) return -2; } - $str = pack('vC', $strlen, $encoding).$str; + $str = pack('vC', $strlen, $encoding) . $str; /* check if string is already present */ if (!isset($this->_str_table[$str])) { @@ -1748,7 +1739,7 @@ public function writeStringBIFF8($row, $col, $str, $format = null) $header = pack('vv', $record, $length); $data = pack('vvvV', $row, $col, $xf, $this->_str_table[$str]); - $this->_append($header.$data); + $this->_append($header . $data); return $str_error; } @@ -1832,7 +1823,7 @@ public function writeNote($row, $col, $note) $length = 0x0006 + strlen($chunk); $header = pack("vv", $record, $length); $data = pack("vvv", -1, 0, strlen($chunk)); - $this->_append($header.$data.$chunk); + $this->_append($header . $data . $chunk); } return (0); } @@ -1955,7 +1946,7 @@ public function writeFormula($row, $col, $formula, $format = null) $header = pack("vv", $record, $length); $data = pack("vvvdvVv", $row, $col, $xf, $num, - $grbit, $unknown, $formlen); + $grbit, $unknown, $formlen); $this->_append($header . $data . $formula); return 0; @@ -2129,7 +2120,7 @@ protected function _writeUrlInternal($row1, $col1, $row2, $col2, $url, $str, $fo $url = $url . "\0\0\0"; // Pack the length of the URL as chars (not wchars) - $url_len = pack("V", floor(strlen($url)/2)); + $url_len = pack("V", floor(strlen($url) / 2)); // Calculate the data length $length = 0x24 + strlen($url); @@ -2256,13 +2247,13 @@ protected function _writeUrlExternal($row1, $col1, $row2, $col2, $url, $str, $fo // Pack the main data stream $data = pack("vvvv", $row1, $row2, $col1, $col2) . - $unknown1 . - $link_type . - $unknown2 . - $up_count . - $dir_short_len. - $dir_short . - $unknown3 . + $unknown1 . + $link_type . + $unknown2 . + $up_count . + $dir_short_len . + $dir_short . + $unknown3 . $stream_len ;/*. $dir_long_len . $unknown4 . @@ -2275,7 +2266,7 @@ protected function _writeUrlExternal($row1, $col1, $row2, $col2, $url, $str, $fo $header = pack("vv", $record, $length); // Write the packed data - $this->_append($header. $data); + $this->_append($header . $data); return ($str_error); } @@ -2333,8 +2324,8 @@ public function setRow($row, $height, $format = null, $hidden = false, $level = $header = pack("vv", $record, $length); $data = pack("vvvvvvvv", $row, $colMic, $colMac, $miyRw, - $irwMac,$reserved, $grbit, $ixfe); - $this->_append($header.$data); + $irwMac,$reserved, $grbit, $ixfe); + $this->_append($header . $data); } /** @@ -2354,14 +2345,14 @@ protected function _storeDimensions() if ($this->_BIFF_version == 0x0500) { $length = 0x000A; // Number of bytes to follow $data = pack("vvvvv", $row_min, $row_max, - $col_min, $col_max, $reserved); + $col_min, $col_max, $reserved); } elseif ($this->_BIFF_version == 0x0600) { $length = 0x000E; $data = pack("VVvvv", $row_min, $row_max, - $col_min, $col_max, $reserved); + $col_min, $col_max, $reserved); } $header = pack("vv", $record, $length); - $this->_prepend($header.$data); + $this->_prepend($header . $data); } /** @@ -2419,7 +2410,7 @@ protected function _storeWindow2() $zoom_factor_normal = 0x0000; $data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000); } - $this->_append($header.$data); + $this->_append($header . $data); } /** @@ -2495,8 +2486,8 @@ protected function _storeColinfo($col_array) $header = pack("vv", $record, $length); $data = pack("vvvvvC", $colFirst, $colLast, $coldx, - $ixfe, $grbit, $reserved); - $this->_prepend($header.$data); + $ixfe, $grbit, $reserved); + $this->_prepend($header . $data); } /** @@ -2527,18 +2518,18 @@ protected function _storeSelection($array) // Swap last row/col for first row/col as necessary if ($rwFirst > $rwLast) { - list($rwFirst, $rwLast) = array($rwLast, $rwFirst); + list($rwFirst, $rwLast) = [$rwLast, $rwFirst]; } if ($colFirst > $colLast) { - list($colFirst, $colLast) = array($colLast, $colFirst); + list($colFirst, $colLast) = [$colLast, $colFirst]; } $header = pack("vv", $record, $length); $data = pack("CvvvvvvCC", $pnn, $rwAct, $colAct, - $irefAct, $cref, - $rwFirst, $rwLast, - $colFirst, $colLast); + $irefAct, $cref, + $rwFirst, $rwLast, + $colFirst, $colLast); $this->_append($header . $data); } @@ -2554,17 +2545,16 @@ protected function _storeMergedCells() return; } $record = 0x00E5; - foreach ($this->_merged_ranges as $ranges) - { + foreach ($this->_merged_ranges as $ranges) { $length = 2 + count($ranges) * 8; $header = pack('vv', $record, $length); $data = pack('v', count($ranges)); foreach ($ranges as $range) { - $data .= pack('vvvv', $range[0], $range[2], $range[1], $range[3]); + $data .= pack('vvvv', $range[0], $range[2], $range[1], $range[3]); } - $string = $header.$data; + $string = $header . $data; $this->_append($string, true); - } + } } /** @@ -2673,8 +2663,8 @@ protected function _storePanes($panes) // The default column width is 8.43 // The following slope and intersection values were interpolated. // - $y = 20*$y + 255; - $x = 113.879*$x + 390; + $y = 20 * $y + 255; + $x = 113.879 * $x + 390; } // Determine which pane should be active. There is also the undocumented @@ -2751,14 +2741,14 @@ protected function _storeSetup() $header = pack("vv", $record, $length); $data1 = pack("vvvvvvvv", $iPaperSize, - $iScale, - $iPageStart, - $iFitWidth, - $iFitHeight, - $grbit, - $iRes, - $iVRes); - $data2 = $numHdr.$numFtr; + $iScale, + $iPageStart, + $iFitWidth, + $iFitHeight, + $grbit, + $iRes, + $iVRes); + $data2 = $numHdr . $numFtr; $data3 = pack("v", $iCopies); $this->_prepend($header . $data1 . $data2 . $data3); } @@ -2788,7 +2778,7 @@ protected function _storeHeader() $data = pack("C", $cch); } - $this->_prepend($header.$data.$str); + $this->_prepend($header . $data . $str); } /** @@ -2834,7 +2824,7 @@ protected function _storeHcenter() $header = pack("vv", $record, $length); $data = pack("v", $fHCenter); - $this->_prepend($header.$data); + $this->_prepend($header . $data); } /** @@ -2957,18 +2947,18 @@ public function mergeCells($first_row, $first_col, $last_row, $last_col) // Swap last row/col for first row/col as necessary if ($first_row > $last_row) { - list($first_row, $last_row) = array($last_row, $first_row); + list($first_row, $last_row) = [$last_row, $first_row]; } if ($first_col > $last_col) { - list($first_col, $last_col) = array($last_col, $first_col); + list($first_col, $last_col) = [$last_col, $first_col]; } $header = pack("vv", $record, $length); $data = pack("vvvvv", $cref, $first_row, $last_row, - $first_col, $last_col); + $first_col, $last_col); - $this->_append($header.$data); + $this->_append($header . $data); } /** @@ -3047,10 +3037,10 @@ protected function _storeGuts() // for the row outline level is carried out in setRow(). $colcount = count($this->_colinfo); for ($i = 0; $i < $colcount; $i++) { - // Skip cols without outline level info. - if (count($this->_colinfo[$i]) >= 6) { - $col_level = max($this->_colinfo[$i][5], $col_level); - } + // Skip cols without outline level info. + if (count($this->_colinfo[$i]) >= 6) { + $col_level = max($this->_colinfo[$i][5], $col_level); + } } // Set the limits for the outline levels (0 <= x <= 7). @@ -3067,7 +3057,7 @@ protected function _storeGuts() $header = pack("vv", $record, $length); $data = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level); - $this->_prepend($header.$data); + $this->_prepend($header . $data); } /** @@ -3135,9 +3125,9 @@ protected function _storeHbreak() $record = 0x001b; // Record identifier $cbrk = count($breaks); // Number of page breaks if ($this->_BIFF_version == 0x0600) { - $length = 2 + 6*$cbrk; // Bytes to follow + $length = 2 + 6 * $cbrk; // Bytes to follow } else { - $length = 2 + 2*$cbrk; // Bytes to follow + $length = 2 + 2 * $cbrk; // Bytes to follow } $header = pack("vv", $record, $length); @@ -3152,7 +3142,7 @@ protected function _storeHbreak() } } - $this->_prepend($header.$data); + $this->_prepend($header . $data); } /** @@ -3180,9 +3170,9 @@ protected function _storeVbreak() $record = 0x001a; // Record identifier $cbrk = count($breaks); // Number of page breaks if ($this->_BIFF_version == 0x0600) { - $length = 2 + 6*$cbrk; // Bytes to follow + $length = 2 + 6 * $cbrk; // Bytes to follow } else { - $length = 2 + 2*$cbrk; // Bytes to follow + $length = 2 + 2 * $cbrk; // Bytes to follow } $header = pack("vv", $record, $length); @@ -3220,7 +3210,7 @@ protected function _storeProtect() $header = pack("vv", $record, $length); $data = pack("v", $fLock); - $this->_prepend($header.$data); + $this->_prepend($header . $data); } /** @@ -3282,7 +3272,7 @@ public function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $lcb = $size; $header = pack("vvvvV", $record, $length, $cf, $env, $lcb); - $this->_append($header.$data); + $this->_append($header . $data); } /** @@ -3350,8 +3340,8 @@ protected function _positionImage($col_start, $row_start, $x1, $y1, $width, $hei $y1 = 0; } - $width = $width + $x1 -1; - $height = $height + $y1 -1; + $width = $width + $x1 - 1; + $height = $height + $y1 - 1; // Subtract the underlying cell widths to find the end cell of the image while ($width >= $this->_sizeCol($col_end)) { @@ -3388,9 +3378,9 @@ protected function _positionImage($col_start, $row_start, $x1, $y1, $width, $hei $y2 = $height / $this->_sizeRow($row_end) * 256; // Distance to bottom of object $this->_storeObjPicture($col_start, $x1, - $row_start, $y1, - $col_end, $x2, - $row_end, $y2); + $row_start, $y1, + $col_end, $x2, + $row_end, $y2); } /** @@ -3433,7 +3423,7 @@ protected function _sizeRow($row) if ($this->_row_sizes[$row] == 0) { return (0); } else { - return (floor(4/3 * $this->_row_sizes[$row])); + return (floor(4 / 3 * $this->_row_sizes[$row])); } } else { return (17); @@ -3603,7 +3593,7 @@ protected function _processBitmap($bitmap) $header = pack("Vvvvv", 0x000c, $width, $height, 0x01, 0x18); $data = $header . $data; - return (array($width, $height, $size, $data)); + return ([$width, $height, $size, $data]); } /** @@ -3653,8 +3643,8 @@ protected function _storeDataValidity() $header = pack('vv', $record, $length); $data = pack('vVVVV', $grbit, $horPos, $verPos, $objId, - count($this->_dv)); - $this->_append($header.$data); + count($this->_dv)); + $this->_append($header . $data); $record = 0x01be; // Record identifier foreach ($this->_dv as $dv) { diff --git a/test/Test/Spreadsheet/Excel/Writer/ParserTest.php b/test/Test/Spreadsheet/Excel/Writer/ParserTest.php index 9bf390a..f5b5809 100644 --- a/test/Test/Spreadsheet/Excel/Writer/ParserTest.php +++ b/test/Test/Spreadsheet/Excel/Writer/ParserTest.php @@ -29,7 +29,7 @@ public function testConvertFunctionReturnsValue() $this->assertTrue(is_string($result)); // Array structure: [function_number, arg_count, unknown, volatile_flag] - $parser->_functions['INVALID'] = array(999, -2, 0, 0); // -2 is not valid + $parser->_functions['INVALID'] = [999, -2, 0, 0]; // -2 is not valid $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid argument count -2 for function INVALID'); diff --git a/test/Test/Spreadsheet/Excel/Writer/WorksheetTest.php b/test/Test/Spreadsheet/Excel/Writer/WorksheetTest.php index d9276bd..337cfac 100644 --- a/test/Test/Spreadsheet/Excel/Writer/WorksheetTest.php +++ b/test/Test/Spreadsheet/Excel/Writer/WorksheetTest.php @@ -44,18 +44,18 @@ public function testSubstituteCellrefWithDollarSigns() // Test absolute cell reference $result = $method->invoke($this->worksheet, '$A$1'); - $this->assertEquals(array(0, 0), $result); + $this->assertEquals([0, 0], $result); // Test mixed references $result = $method->invoke($this->worksheet, 'A$1'); - $this->assertEquals(array(0, 0), $result); + $this->assertEquals([0, 0], $result); $result = $method->invoke($this->worksheet, '$A1'); - $this->assertEquals(array(0, 0), $result); + $this->assertEquals([0, 0], $result); // Test cell range with dollar signs $result = $method->invoke($this->worksheet, '$A$1:$B$2'); - $this->assertEquals(array(0, 0, 1, 1), $result); + $this->assertEquals([0, 0, 1, 1], $result); } /** @@ -68,15 +68,15 @@ public function testCellToRowcolWithDollarSigns() // Test with absolute reference $result = $method->invoke($this->worksheet, '$A$1'); - $this->assertEquals(array(0, 0), $result); + $this->assertEquals([0, 0], $result); // Test with relative reference $result = $method->invoke($this->worksheet, 'B2'); - $this->assertEquals(array(1, 1), $result); + $this->assertEquals([1, 1], $result); // Test with mixed reference $result = $method->invoke($this->worksheet, '$C3'); - $this->assertEquals(array(2, 2), $result); + $this->assertEquals([2, 2], $result); } /** diff --git a/test/Test/Spreadsheet/Excel/WriterTestCase.php b/test/Test/Spreadsheet/Excel/WriterTestCase.php index 9383256..3a8fd68 100644 --- a/test/Test/Spreadsheet/Excel/WriterTestCase.php +++ b/test/Test/Spreadsheet/Excel/WriterTestCase.php @@ -30,7 +30,7 @@ protected function assertSameAsInFixture($filename, Spreadsheet_Excel_Writer $wo $workbook->close(); $data = ob_get_clean(); - $fullPath = self::FIXTURES_PATH.$filename; + $fullPath = self::FIXTURES_PATH . $filename; if ($this->shouldUpdateFixtures()) { file_put_contents($fullPath, $data);