_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q251200
Worksheet.unprotectCellsByColumnAndRow
validation
public function unprotectCellsByColumnAndRow($columnIndex1, $row1, $columnIndex2, $row2) { $cellRange = Coordinate::stringFromColumnIndex($columnIndex1) . $row1 . ':' . Coordinate::stringFromColumnIndex($columnIndex2) . $row2; return $this->unprotectCells($cellRange); }
php
{ "resource": "" }
q251201
Worksheet.setAutoFilterByColumnAndRow
validation
public function setAutoFilterByColumnAndRow($columnIndex1, $row1, $columnIndex2, $row2) { return $this->setAutoFilter( Coordinate::stringFromColumnIndex($columnIndex1) . $row1 . ':' . Coordinate::stringFromColumnIndex($columnIndex2) . $row2 ); }
php
{ "resource": "" }
q251202
Worksheet.freezePane
validation
public function freezePane($cell, $topLeftCell = null) { if (is_string($cell) && Coordinate::coordinateIsRange($cell)) { throw new Exception('Freeze pane can not be set on a range of cells.'); } if ($cell !== null && $topLeftCell === null) { $coordinate = Coordinate::coordinateFromString($cell); $topLeftCell = $coordinate[0] . $coordinate[1]; } $this->freezePane = $cell; $this->topLeftCell = $topLeftCell; return $this; }
php
{ "resource": "" }
q251203
Worksheet.insertNewRowBefore
validation
public function insertNewRowBefore($pBefore, $pNumRows = 1) { if ($pBefore >= 1) { $objReferenceHelper = ReferenceHelper::getInstance(); $objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this); } else { throw new Exception('Rows can only be inserted before at least row 1.'); } return $this; }
php
{ "resource": "" }
q251204
Worksheet.removeRow
validation
public function removeRow($pRow, $pNumRows = 1) { if ($pRow >= 1) { $highestRow = $this->getHighestDataRow(); $objReferenceHelper = ReferenceHelper::getInstance(); $objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this); for ($r = 0; $r < $pNumRows; ++$r) { $this->getCellCollection()->removeRow($highestRow); --$highestRow; } } else { throw new Exception('Rows to be deleted should at least start from row 1.'); } return $this; }
php
{ "resource": "" }
q251205
Worksheet.getComment
validation
public function getComment($pCellCoordinate) { // Uppercase coordinate $pCellCoordinate = strtoupper($pCellCoordinate); if (Coordinate::coordinateIsRange($pCellCoordinate)) { throw new Exception('Cell coordinate string can not be a range of cells.'); } elseif (strpos($pCellCoordinate, '$') !== false) { throw new Exception('Cell coordinate string must not be absolute.'); } elseif ($pCellCoordinate == '') { throw new Exception('Cell coordinate can not be zero-length string.'); } // Check if we already have a comment for this cell. if (isset($this->comments[$pCellCoordinate])) { return $this->comments[$pCellCoordinate]; } // If not, create a new comment. $newComment = new Comment(); $this->comments[$pCellCoordinate] = $newComment; return $newComment; }
php
{ "resource": "" }
q251206
Worksheet.setSelectedCells
validation
public function setSelectedCells($pCoordinate) { // Uppercase coordinate $pCoordinate = strtoupper($pCoordinate); // Convert 'A' to 'A:A' $pCoordinate = preg_replace('/^([A-Z]+)$/', '${1}:${1}', $pCoordinate); // Convert '1' to '1:1' $pCoordinate = preg_replace('/^(\d+)$/', '${1}:${1}', $pCoordinate); // Convert 'A:C' to 'A1:C1048576' $pCoordinate = preg_replace('/^([A-Z]+):([A-Z]+)$/', '${1}1:${2}1048576', $pCoordinate); // Convert '1:3' to 'A1:XFD3' $pCoordinate = preg_replace('/^(\d+):(\d+)$/', 'A${1}:XFD${2}', $pCoordinate); if (Coordinate::coordinateIsRange($pCoordinate)) { list($first) = Coordinate::splitRange($pCoordinate); $this->activeCell = $first[0]; } else { $this->activeCell = $pCoordinate; } $this->selectedCells = $pCoordinate; return $this; }
php
{ "resource": "" }
q251207
Worksheet.fromArray
validation
public function fromArray(array $source, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) { // Convert a 1-D array to 2-D (for ease of looping) if (!is_array(end($source))) { $source = [$source]; } // start coordinate list($startColumn, $startRow) = Coordinate::coordinateFromString($startCell); // Loop through $source foreach ($source as $rowData) { $currentColumn = $startColumn; foreach ($rowData as $cellValue) { if ($strictNullComparison) { if ($cellValue !== $nullValue) { // Set cell value $this->getCell($currentColumn . $startRow)->setValue($cellValue); } } else { if ($cellValue != $nullValue) { // Set cell value $this->getCell($currentColumn . $startRow)->setValue($cellValue); } } ++$currentColumn; } ++$startRow; } return $this; }
php
{ "resource": "" }
q251208
Worksheet.getHyperlink
validation
public function getHyperlink($pCellCoordinate) { // return hyperlink if we already have one if (isset($this->hyperlinkCollection[$pCellCoordinate])) { return $this->hyperlinkCollection[$pCellCoordinate]; } // else create hyperlink $this->hyperlinkCollection[$pCellCoordinate] = new Hyperlink(); return $this->hyperlinkCollection[$pCellCoordinate]; }
php
{ "resource": "" }
q251209
Worksheet.setHyperlink
validation
public function setHyperlink($pCellCoordinate, Hyperlink $pHyperlink = null) { if ($pHyperlink === null) { unset($this->hyperlinkCollection[$pCellCoordinate]); } else { $this->hyperlinkCollection[$pCellCoordinate] = $pHyperlink; } return $this; }
php
{ "resource": "" }
q251210
Worksheet.getDataValidation
validation
public function getDataValidation($pCellCoordinate) { // return data validation if we already have one if (isset($this->dataValidationCollection[$pCellCoordinate])) { return $this->dataValidationCollection[$pCellCoordinate]; } // else create data validation $this->dataValidationCollection[$pCellCoordinate] = new DataValidation(); return $this->dataValidationCollection[$pCellCoordinate]; }
php
{ "resource": "" }
q251211
Worksheet.setDataValidation
validation
public function setDataValidation($pCellCoordinate, DataValidation $pDataValidation = null) { if ($pDataValidation === null) { unset($this->dataValidationCollection[$pCellCoordinate]); } else { $this->dataValidationCollection[$pCellCoordinate] = $pDataValidation; } return $this; }
php
{ "resource": "" }
q251212
Worksheet.shrinkRangeToFit
validation
public function shrinkRangeToFit($range) { $maxCol = $this->getHighestColumn(); $maxRow = $this->getHighestRow(); $maxCol = Coordinate::columnIndexFromString($maxCol); $rangeBlocks = explode(' ', $range); foreach ($rangeBlocks as &$rangeSet) { $rangeBoundaries = Coordinate::getRangeBoundaries($rangeSet); if (Coordinate::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { $rangeBoundaries[0][0] = Coordinate::stringFromColumnIndex($maxCol); } if ($rangeBoundaries[0][1] > $maxRow) { $rangeBoundaries[0][1] = $maxRow; } if (Coordinate::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { $rangeBoundaries[1][0] = Coordinate::stringFromColumnIndex($maxCol); } if ($rangeBoundaries[1][1] > $maxRow) { $rangeBoundaries[1][1] = $maxRow; } $rangeSet = $rangeBoundaries[0][0] . $rangeBoundaries[0][1] . ':' . $rangeBoundaries[1][0] . $rangeBoundaries[1][1]; } unset($rangeSet); $stRange = implode(' ', $rangeBlocks); return $stRange; }
php
{ "resource": "" }
q251213
Worksheet.setCodeName
validation
public function setCodeName($pValue, $validate = true) { // Is this a 'rename' or not? if ($this->getCodeName() == $pValue) { return $this; } if ($validate) { $pValue = str_replace(' ', '_', $pValue); //Excel does this automatically without flinching, we are doing the same // Syntax check // throw an exception if not valid self::checkSheetCodeName($pValue); // We use the same code that setTitle to find a valid codeName else not using a space (Excel don't like) but a '_' if ($this->getParent()) { // Is there already such sheet name? if ($this->getParent()->sheetCodeNameExists($pValue)) { // Use name, but append with lowest possible integer if (Shared\StringHelper::countCharacters($pValue) > 29) { $pValue = Shared\StringHelper::substring($pValue, 0, 29); } $i = 1; while ($this->getParent()->sheetCodeNameExists($pValue . '_' . $i)) { ++$i; if ($i == 10) { if (Shared\StringHelper::countCharacters($pValue) > 28) { $pValue = Shared\StringHelper::substring($pValue, 0, 28); } } elseif ($i == 100) { if (Shared\StringHelper::countCharacters($pValue) > 27) { $pValue = Shared\StringHelper::substring($pValue, 0, 27); } } } $pValue = $pValue . '_' . $i; // ok, we have a valid name } } } $this->codeName = $pValue; return $this; }
php
{ "resource": "" }
q251214
NumberFormat.setFormatCode
validation
public function setFormatCode($pValue) { if ($pValue == '') { $pValue = self::FORMAT_GENERAL; } if ($this->isSupervisor) { $styleArray = $this->getStyleArray(['formatCode' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->formatCode = $pValue; $this->builtInFormatCode = self::builtInFormatCodeIndex($pValue); } return $this; }
php
{ "resource": "" }
q251215
NumberFormat.setBuiltInFormatCode
validation
public function setBuiltInFormatCode($pValue) { if ($this->isSupervisor) { $styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($pValue)]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->builtInFormatCode = $pValue; $this->formatCode = self::builtInFormatCode($pValue); } return $this; }
php
{ "resource": "" }
q251216
NumberFormat.fillBuiltInFormatCodes
validation
private static function fillBuiltInFormatCodes() { // [MS-OI29500: Microsoft Office Implementation Information for ISO/IEC-29500 Standard Compliance] // 18.8.30. numFmt (Number Format) // // The ECMA standard defines built-in format IDs // 14: "mm-dd-yy" // 22: "m/d/yy h:mm" // 37: "#,##0 ;(#,##0)" // 38: "#,##0 ;[Red](#,##0)" // 39: "#,##0.00;(#,##0.00)" // 40: "#,##0.00;[Red](#,##0.00)" // 47: "mmss.0" // KOR fmt 55: "yyyy-mm-dd" // Excel defines built-in format IDs // 14: "m/d/yyyy" // 22: "m/d/yyyy h:mm" // 37: "#,##0_);(#,##0)" // 38: "#,##0_);[Red](#,##0)" // 39: "#,##0.00_);(#,##0.00)" // 40: "#,##0.00_);[Red](#,##0.00)" // 47: "mm:ss.0" // KOR fmt 55: "yyyy/mm/dd" // Built-in format codes if (self::$builtInFormats === null) { self::$builtInFormats = []; // General self::$builtInFormats[0] = self::FORMAT_GENERAL; self::$builtInFormats[1] = '0'; self::$builtInFormats[2] = '0.00'; self::$builtInFormats[3] = '#,##0'; self::$builtInFormats[4] = '#,##0.00'; self::$builtInFormats[9] = '0%'; self::$builtInFormats[10] = '0.00%'; self::$builtInFormats[11] = '0.00E+00'; self::$builtInFormats[12] = '# ?/?'; self::$builtInFormats[13] = '# ??/??'; self::$builtInFormats[14] = 'm/d/yyyy'; // Despite ECMA 'mm-dd-yy'; self::$builtInFormats[15] = 'd-mmm-yy'; self::$builtInFormats[16] = 'd-mmm'; self::$builtInFormats[17] = 'mmm-yy'; self::$builtInFormats[18] = 'h:mm AM/PM'; self::$builtInFormats[19] = 'h:mm:ss AM/PM'; self::$builtInFormats[20] = 'h:mm'; self::$builtInFormats[21] = 'h:mm:ss'; self::$builtInFormats[22] = 'm/d/yyyy h:mm'; // Despite ECMA 'm/d/yy h:mm'; self::$builtInFormats[37] = '#,##0_);(#,##0)'; // Despite ECMA '#,##0 ;(#,##0)'; self::$builtInFormats[38] = '#,##0_);[Red](#,##0)'; // Despite ECMA '#,##0 ;[Red](#,##0)'; self::$builtInFormats[39] = '#,##0.00_);(#,##0.00)'; // Despite ECMA '#,##0.00;(#,##0.00)'; self::$builtInFormats[40] = '#,##0.00_);[Red](#,##0.00)'; // Despite ECMA '#,##0.00;[Red](#,##0.00)'; self::$builtInFormats[44] = '_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)'; self::$builtInFormats[45] = 'mm:ss'; self::$builtInFormats[46] = '[h]:mm:ss'; self::$builtInFormats[47] = 'mm:ss.0'; // Despite ECMA 'mmss.0'; self::$builtInFormats[48] = '##0.0E+0'; self::$builtInFormats[49] = '@'; // CHT self::$builtInFormats[27] = '[$-404]e/m/d'; self::$builtInFormats[30] = 'm/d/yy'; self::$builtInFormats[36] = '[$-404]e/m/d'; self::$builtInFormats[50] = '[$-404]e/m/d'; self::$builtInFormats[57] = '[$-404]e/m/d'; // THA self::$builtInFormats[59] = 't0'; self::$builtInFormats[60] = 't0.00'; self::$builtInFormats[61] = 't#,##0'; self::$builtInFormats[62] = 't#,##0.00'; self::$builtInFormats[67] = 't0%'; self::$builtInFormats[68] = 't0.00%'; self::$builtInFormats[69] = 't# ?/?'; self::$builtInFormats[70] = 't# ??/??'; // Flip array (for faster lookups) self::$flippedBuiltInFormats = array_flip(self::$builtInFormats); } }
php
{ "resource": "" }
q251217
NumberFormat.builtInFormatCode
validation
public static function builtInFormatCode($pIndex) { // Clean parameter $pIndex = (int) $pIndex; // Ensure built-in format codes are available self::fillBuiltInFormatCodes(); // Lookup format code if (isset(self::$builtInFormats[$pIndex])) { return self::$builtInFormats[$pIndex]; } return ''; }
php
{ "resource": "" }
q251218
Pdf.prepareForSave
validation
protected function prepareForSave($pFilename) { // garbage collect $this->spreadsheet->garbageCollect(); $this->saveArrayReturnType = Calculation::getArrayReturnType(); Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new WriterException("Could not open file $pFilename for writing."); } // Set PDF $this->isPdf = true; // Build CSS $this->buildCSS(true); return $fileHandle; }
php
{ "resource": "" }
q251219
CurlAdapter.request
validation
public function request($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); $response = curl_exec($ch); curl_close($ch); if ($response === false) { throw new \RuntimeException('Connection timeout.'); } return $response; }
php
{ "resource": "" }
q251220
Comments.writeComments
validation
public function writeComments(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // Comments cache $comments = $pWorksheet->getComments(); // Authors cache $authors = []; $authorId = 0; foreach ($comments as $comment) { if (!isset($authors[$comment->getAuthor()])) { $authors[$comment->getAuthor()] = $authorId++; } } // comments $objWriter->startElement('comments'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); // Loop through authors $objWriter->startElement('authors'); foreach ($authors as $author => $index) { $objWriter->writeElement('author', $author); } $objWriter->endElement(); // Loop through comments $objWriter->startElement('commentList'); foreach ($comments as $key => $value) { $this->writeComment($objWriter, $key, $value, $authors); } $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
php
{ "resource": "" }
q251221
Comments.writeComment
validation
private function writeComment(XMLWriter $objWriter, $pCellReference, Comment $pComment, array $pAuthors) { // comment $objWriter->startElement('comment'); $objWriter->writeAttribute('ref', $pCellReference); $objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]); // text $objWriter->startElement('text'); $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText()); $objWriter->endElement(); $objWriter->endElement(); }
php
{ "resource": "" }
q251222
Comments.writeVMLComments
validation
public function writeVMLComments(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // Comments cache $comments = $pWorksheet->getComments(); // xml $objWriter->startElement('xml'); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel'); // o:shapelayout $objWriter->startElement('o:shapelayout'); $objWriter->writeAttribute('v:ext', 'edit'); // o:idmap $objWriter->startElement('o:idmap'); $objWriter->writeAttribute('v:ext', 'edit'); $objWriter->writeAttribute('data', '1'); $objWriter->endElement(); $objWriter->endElement(); // v:shapetype $objWriter->startElement('v:shapetype'); $objWriter->writeAttribute('id', '_x0000_t202'); $objWriter->writeAttribute('coordsize', '21600,21600'); $objWriter->writeAttribute('o:spt', '202'); $objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe'); // v:stroke $objWriter->startElement('v:stroke'); $objWriter->writeAttribute('joinstyle', 'miter'); $objWriter->endElement(); // v:path $objWriter->startElement('v:path'); $objWriter->writeAttribute('gradientshapeok', 't'); $objWriter->writeAttribute('o:connecttype', 'rect'); $objWriter->endElement(); $objWriter->endElement(); // Loop through comments foreach ($comments as $key => $value) { $this->writeVMLComment($objWriter, $key, $value); } $objWriter->endElement(); // Return return $objWriter->getData(); }
php
{ "resource": "" }
q251223
Comments.writeVMLComment
validation
private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment) { // Metadata list($column, $row) = Coordinate::coordinateFromString($pCellReference); $column = Coordinate::columnIndexFromString($column); $id = 1024 + $column + $row; $id = substr($id, 0, 4); // v:shape $objWriter->startElement('v:shape'); $objWriter->writeAttribute('id', '_x0000_s' . $id); $objWriter->writeAttribute('type', '#_x0000_t202'); $objWriter->writeAttribute('style', 'position:absolute;margin-left:' . $pComment->getMarginLeft() . ';margin-top:' . $pComment->getMarginTop() . ';width:' . $pComment->getWidth() . ';height:' . $pComment->getHeight() . ';z-index:1;visibility:' . ($pComment->getVisible() ? 'visible' : 'hidden')); $objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB()); $objWriter->writeAttribute('o:insetmode', 'auto'); // v:fill $objWriter->startElement('v:fill'); $objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB()); $objWriter->endElement(); // v:shadow $objWriter->startElement('v:shadow'); $objWriter->writeAttribute('on', 't'); $objWriter->writeAttribute('color', 'black'); $objWriter->writeAttribute('obscured', 't'); $objWriter->endElement(); // v:path $objWriter->startElement('v:path'); $objWriter->writeAttribute('o:connecttype', 'none'); $objWriter->endElement(); // v:textbox $objWriter->startElement('v:textbox'); $objWriter->writeAttribute('style', 'mso-direction-alt:auto'); // div $objWriter->startElement('div'); $objWriter->writeAttribute('style', 'text-align:left'); $objWriter->endElement(); $objWriter->endElement(); // x:ClientData $objWriter->startElement('x:ClientData'); $objWriter->writeAttribute('ObjectType', 'Note'); // x:MoveWithCells $objWriter->writeElement('x:MoveWithCells', ''); // x:SizeWithCells $objWriter->writeElement('x:SizeWithCells', ''); // x:AutoFill $objWriter->writeElement('x:AutoFill', 'False'); // x:Row $objWriter->writeElement('x:Row', ($row - 1)); // x:Column $objWriter->writeElement('x:Column', ($column - 1)); $objWriter->endElement(); $objWriter->endElement(); }
php
{ "resource": "" }
q251224
DefaultValueBinder.dataTypeForValue
validation
public static function dataTypeForValue($pValue) { // Match the value against a few data types if ($pValue === null) { return DataType::TYPE_NULL; } elseif ($pValue === '') { return DataType::TYPE_STRING; } elseif ($pValue instanceof RichText) { return DataType::TYPE_INLINE; } elseif ($pValue[0] === '=' && strlen($pValue) > 1) { return DataType::TYPE_FORMULA; } elseif (is_bool($pValue)) { return DataType::TYPE_BOOL; } elseif (is_float($pValue) || is_int($pValue)) { return DataType::TYPE_NUMERIC; } elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) { $tValue = ltrim($pValue, '+-'); if (is_string($pValue) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') { return DataType::TYPE_STRING; } elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) { return DataType::TYPE_STRING; } return DataType::TYPE_NUMERIC; } elseif (is_string($pValue)) { $errorCodes = DataType::getErrorCodes(); if (isset($errorCodes[$pValue])) { return DataType::TYPE_ERROR; } } return DataType::TYPE_STRING; }
php
{ "resource": "" }
q251225
Blacklist.fromXML
validation
function fromXML($xmlElement) { if (isset($xmlElement->id)) $this->id = $xmlElement->id; if (isset($xmlElement->name)) $this->name = $xmlElement->name; if (isset($xmlElement->entries)) { $this->entries = array(); foreach ($xmlElement->entries->children() as $entry) { $this->entries[] = $entry; } } }
php
{ "resource": "" }
q251226
Html.mapVAlign
validation
private function mapVAlign($vAlign) { switch ($vAlign) { case Alignment::VERTICAL_BOTTOM: return 'bottom'; case Alignment::VERTICAL_TOP: return 'top'; case Alignment::VERTICAL_CENTER: case Alignment::VERTICAL_JUSTIFY: return 'middle'; default: return 'baseline'; } }
php
{ "resource": "" }
q251227
Html.mapHAlign
validation
private function mapHAlign($hAlign) { switch ($hAlign) { case Alignment::HORIZONTAL_GENERAL: return false; case Alignment::HORIZONTAL_LEFT: return 'left'; case Alignment::HORIZONTAL_RIGHT: return 'right'; case Alignment::HORIZONTAL_CENTER: case Alignment::HORIZONTAL_CENTER_CONTINUOUS: return 'center'; case Alignment::HORIZONTAL_JUSTIFY: return 'justify'; default: return false; } }
php
{ "resource": "" }
q251228
Html.mapBorderStyle
validation
private function mapBorderStyle($borderStyle) { switch ($borderStyle) { case Border::BORDER_NONE: return 'none'; case Border::BORDER_DASHDOT: return '1px dashed'; case Border::BORDER_DASHDOTDOT: return '1px dotted'; case Border::BORDER_DASHED: return '1px dashed'; case Border::BORDER_DOTTED: return '1px dotted'; case Border::BORDER_DOUBLE: return '3px double'; case Border::BORDER_HAIR: return '1px solid'; case Border::BORDER_MEDIUM: return '2px solid'; case Border::BORDER_MEDIUMDASHDOT: return '2px dashed'; case Border::BORDER_MEDIUMDASHDOTDOT: return '2px dotted'; case Border::BORDER_MEDIUMDASHED: return '2px dashed'; case Border::BORDER_SLANTDASHDOT: return '2px dashed'; case Border::BORDER_THICK: return '3px solid'; case Border::BORDER_THIN: return '1px solid'; default: // map others to thin return '1px solid'; } }
php
{ "resource": "" }
q251229
Html.generateHTMLHeader
validation
public function generateHTMLHeader($pIncludeStyles = false) { // Spreadsheet object known? if ($this->spreadsheet === null) { throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Construct HTML $properties = $this->spreadsheet->getProperties(); $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL; $html .= '<html>' . PHP_EOL; $html .= ' <head>' . PHP_EOL; $html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL; $html .= ' <meta name="generator" content="PhpSpreadsheet, https://github.com/PHPOffice/PhpSpreadsheet">' . PHP_EOL; if ($properties->getTitle() > '') { $html .= ' <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL; } if ($properties->getCreator() > '') { $html .= ' <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL; } if ($properties->getTitle() > '') { $html .= ' <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL; } if ($properties->getDescription() > '') { $html .= ' <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL; } if ($properties->getSubject() > '') { $html .= ' <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL; } if ($properties->getKeywords() > '') { $html .= ' <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL; } if ($properties->getCategory() > '') { $html .= ' <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL; } if ($properties->getCompany() > '') { $html .= ' <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL; } if ($properties->getManager() > '') { $html .= ' <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL; } if ($pIncludeStyles) { $html .= $this->generateStyles(true); } $html .= ' </head>' . PHP_EOL; $html .= '' . PHP_EOL; $html .= ' <body>' . PHP_EOL; return $html; }
php
{ "resource": "" }
q251230
Html.generateNavigation
validation
public function generateNavigation() { // Spreadsheet object known? if ($this->spreadsheet === null) { throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Fetch sheets $sheets = []; if ($this->sheetIndex === null) { $sheets = $this->spreadsheet->getAllSheets(); } else { $sheets[] = $this->spreadsheet->getSheet($this->sheetIndex); } // Construct HTML $html = ''; // Only if there are more than 1 sheets if (count($sheets) > 1) { // Loop all sheets $sheetId = 0; $html .= '<ul class="navigation">' . PHP_EOL; foreach ($sheets as $sheet) { $html .= ' <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL; ++$sheetId; } $html .= '</ul>' . PHP_EOL; } return $html; }
php
{ "resource": "" }
q251231
Html.writeImageInCell
validation
private function writeImageInCell(Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write images foreach ($pSheet->getDrawingCollection() as $drawing) { if ($drawing instanceof Drawing) { if ($drawing->getCoordinates() == $coordinates) { $filename = $drawing->getPath(); // Strip off eventual '.' if (substr($filename, 0, 1) == '.') { $filename = substr($filename, 1); } // Prepend images root $filename = $this->getImagesRoot() . $filename; // Strip off eventual '.' if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') { $filename = substr($filename, 1); } // Convert UTF8 data to PCDATA $filename = htmlspecialchars($filename); $html .= PHP_EOL; if ((!$this->embedImages) || ($this->isPdf)) { $imageData = $filename; } else { $imageDetails = getimagesize($filename); if ($fp = fopen($filename, 'rb', 0)) { $picture = fread($fp, filesize($filename)); fclose($fp); // base64 encode the binary data, then break it // into chunks according to RFC 2045 semantics $base64 = chunk_split(base64_encode($picture)); $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64; } else { $imageData = $filename; } } $html .= '<div style="position: relative;">'; $html .= '<img style="position: absolute; z-index: 1; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $imageData . '" border="0" />'; $html .= '</div>'; } } elseif ($drawing instanceof MemoryDrawing) { if ($drawing->getCoordinates() != $coordinates) { continue; } ob_start(); // Let's start output buffering. imagepng($drawing->getImageResource()); // This will normally output the image, but because of ob_start(), it won't. $contents = ob_get_contents(); // Instead, output above is saved to $contents ob_end_clean(); // End the output buffer. $dataUri = 'data:image/jpeg;base64,' . base64_encode($contents); // Because of the nature of tables, width is more important than height. // max-width: 100% ensures that image doesnt overflow containing cell // width: X sets width of supplied image. // As a result, images bigger than cell will be contained and images smaller will not get stretched $html .= '<img src="' . $dataUri . '" style="max-width:100%;width:' . $drawing->getWidth() . 'px;" />'; } } return $html; }
php
{ "resource": "" }
q251232
Html.writeChartInCell
validation
private function writeChartInCell(Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write charts foreach ($pSheet->getChartCollection() as $chart) { if ($chart instanceof Chart) { $chartCoordinates = $chart->getTopLeftPosition(); if ($chartCoordinates['cell'] == $coordinates) { $chartFileName = File::sysGetTempDir() . '/' . uniqid('', true) . '.png'; if (!$chart->render($chartFileName)) { return; } $html .= PHP_EOL; $imageDetails = getimagesize($chartFileName); if ($fp = fopen($chartFileName, 'rb', 0)) { $picture = fread($fp, filesize($chartFileName)); fclose($fp); // base64 encode the binary data, then break it // into chunks according to RFC 2045 semantics $base64 = chunk_split(base64_encode($picture)); $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64; $html .= '<div style="position: relative;">'; $html .= '<img style="position: absolute; z-index: 1; left: ' . $chartCoordinates['xOffset'] . 'px; top: ' . $chartCoordinates['yOffset'] . 'px; width: ' . $imageDetails[0] . 'px; height: ' . $imageDetails[1] . 'px;" src="' . $imageData . '" border="0" />' . PHP_EOL; $html .= '</div>'; unlink($chartFileName); } } } } // Return return $html; }
php
{ "resource": "" }
q251233
Html.generateStyles
validation
public function generateStyles($generateSurroundingHTML = true) { // Spreadsheet object known? if ($this->spreadsheet === null) { throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Build CSS $css = $this->buildCSS($generateSurroundingHTML); // Construct HTML $html = ''; // Start styles if ($generateSurroundingHTML) { $html .= ' <style type="text/css">' . PHP_EOL; $html .= ' html { ' . $this->assembleCSS($css['html']) . ' }' . PHP_EOL; } // Write all other styles foreach ($css as $styleName => $styleDefinition) { if ($styleName != 'html') { $html .= ' ' . $styleName . ' { ' . $this->assembleCSS($styleDefinition) . ' }' . PHP_EOL; } } // End styles if ($generateSurroundingHTML) { $html .= ' </style>' . PHP_EOL; } // Return return $html; }
php
{ "resource": "" }
q251234
Html.createCSSStyle
validation
private function createCSSStyle(Style $pStyle) { // Create CSS $css = array_merge( $this->createCSSStyleAlignment($pStyle->getAlignment()), $this->createCSSStyleBorders($pStyle->getBorders()), $this->createCSSStyleFont($pStyle->getFont()), $this->createCSSStyleFill($pStyle->getFill()) ); // Return return $css; }
php
{ "resource": "" }
q251235
Html.formatColor
validation
public function formatColor($pValue, $pFormat) { // Color information, e.g. [Red] is always at the beginning $color = null; // initialize $matches = []; $color_regex = '/^\\[[a-zA-Z]+\\]/'; if (preg_match($color_regex, $pFormat, $matches)) { $color = str_replace(['[', ']'], '', $matches[0]); $color = strtolower($color); } // convert to PCDATA $value = htmlspecialchars($pValue); // color span tag if ($color !== null) { $value = '<span style="color:' . $color . '">' . $value . '</span>'; } return $value; }
php
{ "resource": "" }
q251236
Html.writeComment
validation
private function writeComment(Worksheet $pSheet, $coordinate) { $result = ''; if (!$this->isPdf && isset($pSheet->getComments()[$coordinate])) { $result .= '<a class="comment-indicator"></a>'; $result .= '<div class="comment">' . nl2br($pSheet->getComment($coordinate)->getText()->getPlainText()) . '</div>'; $result .= PHP_EOL; } return $result; }
php
{ "resource": "" }
q251237
Csv.checkSeparator
validation
protected function checkSeparator() { $line = fgets($this->fileHandle); if ($line === false) { return; } if ((strlen(trim($line, "\r\n")) == 5) && (stripos($line, 'sep=') === 0)) { $this->delimiter = substr($line, 4, 1); return; } return $this->skipBOM(); }
php
{ "resource": "" }
q251238
Csv.inferSeparator
validation
protected function inferSeparator() { if ($this->delimiter !== null) { return; } $potentialDelimiters = [',', ';', "\t", '|', ':', ' ']; $counts = []; foreach ($potentialDelimiters as $delimiter) { $counts[$delimiter] = []; } // Count how many times each of the potential delimiters appears in each line $numberLines = 0; while (($line = fgets($this->fileHandle)) !== false && (++$numberLines < 1000)) { // Drop everything that is enclosed to avoid counting false positives in enclosures $enclosure = preg_quote($this->enclosure, '/'); $line = preg_replace('/(' . $enclosure . '.*' . $enclosure . ')/U', '', $line); $countLine = []; for ($i = strlen($line) - 1; $i >= 0; --$i) { $char = $line[$i]; if (isset($counts[$char])) { if (!isset($countLine[$char])) { $countLine[$char] = 0; } ++$countLine[$char]; } } foreach ($potentialDelimiters as $delimiter) { $counts[$delimiter][] = isset($countLine[$delimiter]) ? $countLine[$delimiter] : 0; } } // Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently) $meanSquareDeviations = []; $middleIdx = floor(($numberLines - 1) / 2); foreach ($potentialDelimiters as $delimiter) { $series = $counts[$delimiter]; sort($series); $median = ($numberLines % 2) ? $series[$middleIdx] : ($series[$middleIdx] + $series[$middleIdx + 1]) / 2; if ($median === 0) { continue; } $meanSquareDeviations[$delimiter] = array_reduce( $series, function ($sum, $value) use ($median) { return $sum + pow($value - $median, 2); } ) / count($series); } // ... and pick the delimiter with the smallest mean square deviation (in case of ties, the order in potentialDelimiters is respected) $min = INF; foreach ($potentialDelimiters as $delimiter) { if (!isset($meanSquareDeviations[$delimiter])) { continue; } if ($meanSquareDeviations[$delimiter] < $min) { $min = $meanSquareDeviations[$delimiter]; $this->delimiter = $delimiter; } } // If no delimiter could be detected, fall back to the default if ($this->delimiter === null) { $this->delimiter = reset($potentialDelimiters); } return $this->skipBOM(); }
php
{ "resource": "" }
q251239
GridLines.setShadowProperties
validation
public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null) { $this->activateObject() ->setShadowPresetsProperties((int) $sh_presets) ->setShadowColor( $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha), $sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type ) ->setShadowBlur($sh_blur) ->setShadowAngle($sh_angle) ->setShadowDistance($sh_distance); }
php
{ "resource": "" }
q251240
GridLines.setShadowColor
validation
private function setShadowColor($color, $alpha, $type) { if ($color !== null) { $this->shadowProperties['color']['value'] = (string) $color; } if ($alpha !== null) { $this->shadowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); } if ($type !== null) { $this->shadowProperties['color']['type'] = (string) $type; } return $this; }
php
{ "resource": "" }
q251241
GridLines.setSoftEdgesSize
validation
public function setSoftEdgesSize($size) { if ($size !== null) { $this->activateObject(); $softEdges['size'] = (string) $this->getExcelPointsWidth($size); } }
php
{ "resource": "" }
q251242
DecoratorStack.add
validation
public function add(callable $decorator, $priority = 0) { $this->stack[] = array( 'decorator' => $decorator, 'priority' => $priority, 'index' => $this->index ); $this->index--; uasort($this->stack, array($this, 'compareStackItems')); return $this; }
php
{ "resource": "" }
q251243
DecoratorStack.apply
validation
public function apply(Tag $tag, Renderer $renderer) { foreach ($this->stack as $item) { $result = $item['decorator']($tag, $renderer); // in case a decorator returns something unexpected if ($result instanceof Tag) { $tag = $result; } else { trigger_error(sprintf('%s does not return an instance of Sirius\\Html\\Tag', get_class($item['decorator'])), E_USER_WARNING); } } return $tag; }
php
{ "resource": "" }
q251244
Remove.removeRecursive
validation
protected function removeRecursive( $path, $pattern, Logger $logger ) { // Check if source file exists at all. if ( !is_file( $path ) && !is_dir( $path ) ) { $logger->log( "$path is not a valid source.", Logger::WARNING ); return; } // Skip non readable files in src directory if ( !is_readable( $path ) ) { $logger->log( "$path is not readable, skipping.", Logger::WARNING ); return; } // Skip non writeable parent directories if ( !is_writeable( $parent = dirname( $path ) ) ) { $logger->log( "$parent is not writable, skipping.", Logger::WARNING ); return; } $matchesPattern = ( ( $pattern === null ) || ( preg_match( $pattern, basename( $path ) ) ) ); // Handle files if ( is_file( $path ) ) { if ( $matchesPattern ) { unlink( $path ); } return; } // Handle directory contents $dh = opendir( $path ); while ( ( $file = readdir( $dh ) ) !== false ) { if ( ( $file === '.' ) || ( $file === '..' ) ) { continue; } $this->removeRecursive( $path . '/' . $file, ( $matchesPattern ? null : $pattern ), $logger ); } if ( $matchesPattern ) { rmdir( $path ); } }
php
{ "resource": "" }
q251245
HTTPResponseCodes.getStringFromHTTPStatusCode
validation
static function getStringFromHTTPStatusCode($httpStatusCode) { if (array_key_exists($httpStatusCode, HTTPResponseCodes::$codes) === true) { return HTTPResponseCodes::$codes[$httpStatusCode]; } else { return "unknown error code: " . $httpStatusCode; } }
php
{ "resource": "" }
q251246
Spreadsheet.setRibbonXMLData
validation
public function setRibbonXMLData($target, $xmlData) { if ($target !== null && $xmlData !== null) { $this->ribbonXMLData = ['target' => $target, 'data' => $xmlData]; } else { $this->ribbonXMLData = null; } }
php
{ "resource": "" }
q251247
Spreadsheet.getRibbonXMLData
validation
public function getRibbonXMLData($what = 'all') //we need some constants here... { $returnData = null; $what = strtolower($what); switch ($what) { case 'all': $returnData = $this->ribbonXMLData; break; case 'target': case 'data': if (is_array($this->ribbonXMLData) && isset($this->ribbonXMLData[$what])) { $returnData = $this->ribbonXMLData[$what]; } break; } return $returnData; }
php
{ "resource": "" }
q251248
Spreadsheet.getRibbonBinObjects
validation
public function getRibbonBinObjects($what = 'all') { $ReturnData = null; $what = strtolower($what); switch ($what) { case 'all': return $this->ribbonBinObjects; break; case 'names': case 'data': if (is_array($this->ribbonBinObjects) && isset($this->ribbonBinObjects[$what])) { $ReturnData = $this->ribbonBinObjects[$what]; } break; case 'types': if (is_array($this->ribbonBinObjects) && isset($this->ribbonBinObjects['data']) && is_array($this->ribbonBinObjects['data'])) { $tmpTypes = array_keys($this->ribbonBinObjects['data']); $ReturnData = array_unique(array_map([$this, 'getExtensionOnly'], $tmpTypes)); } else { $ReturnData = []; // the caller want an array... not null if empty } break; } return $ReturnData; }
php
{ "resource": "" }
q251249
Spreadsheet.disconnectWorksheets
validation
public function disconnectWorksheets() { $worksheet = null; foreach ($this->workSheetCollection as $k => &$worksheet) { $worksheet->disconnectCells(); $this->workSheetCollection[$k] = null; } unset($worksheet); $this->workSheetCollection = []; }
php
{ "resource": "" }
q251250
Spreadsheet.createSheet
validation
public function createSheet($sheetIndex = null) { $newSheet = new Worksheet($this); $this->addSheet($newSheet, $sheetIndex); return $newSheet; }
php
{ "resource": "" }
q251251
Spreadsheet.addSheet
validation
public function addSheet(Worksheet $pSheet, $iSheetIndex = null) { if ($this->sheetNameExists($pSheet->getTitle())) { throw new Exception( "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first." ); } if ($iSheetIndex === null) { if ($this->activeSheetIndex < 0) { $this->activeSheetIndex = 0; } $this->workSheetCollection[] = $pSheet; } else { // Insert the sheet at the requested index array_splice( $this->workSheetCollection, $iSheetIndex, 0, [$pSheet] ); // Adjust active sheet index if necessary if ($this->activeSheetIndex >= $iSheetIndex) { ++$this->activeSheetIndex; } } if ($pSheet->getParent() === null) { $pSheet->rebindParent($this); } return $pSheet; }
php
{ "resource": "" }
q251252
Spreadsheet.removeSheetByIndex
validation
public function removeSheetByIndex($pIndex) { $numSheets = count($this->workSheetCollection); if ($pIndex > $numSheets - 1) { throw new Exception( "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." ); } array_splice($this->workSheetCollection, $pIndex, 1); // Adjust active sheet index if necessary if (($this->activeSheetIndex >= $pIndex) && ($pIndex > count($this->workSheetCollection) - 1)) { --$this->activeSheetIndex; } }
php
{ "resource": "" }
q251253
Spreadsheet.getSheet
validation
public function getSheet($pIndex) { if (!isset($this->workSheetCollection[$pIndex])) { $numSheets = $this->getSheetCount(); throw new Exception( "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}." ); } return $this->workSheetCollection[$pIndex]; }
php
{ "resource": "" }
q251254
Spreadsheet.getSheetByName
validation
public function getSheetByName($pName) { $worksheetCount = count($this->workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { if ($this->workSheetCollection[$i]->getTitle() === $pName) { return $this->workSheetCollection[$i]; } } return null; }
php
{ "resource": "" }
q251255
Spreadsheet.getIndex
validation
public function getIndex(Worksheet $pSheet) { foreach ($this->workSheetCollection as $key => $value) { if ($value->getHashCode() == $pSheet->getHashCode()) { return $key; } } throw new Exception('Sheet does not exist.'); }
php
{ "resource": "" }
q251256
Spreadsheet.setActiveSheetIndexByName
validation
public function setActiveSheetIndexByName($pValue) { if (($worksheet = $this->getSheetByName($pValue)) instanceof Worksheet) { $this->setActiveSheetIndex($this->getIndex($worksheet)); return $worksheet; } throw new Exception('Workbook does not contain sheet:' . $pValue); }
php
{ "resource": "" }
q251257
Spreadsheet.addExternalSheet
validation
public function addExternalSheet(Worksheet $pSheet, $iSheetIndex = null) { if ($this->sheetNameExists($pSheet->getTitle())) { throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); } // count how many cellXfs there are in this workbook currently, we will need this below $countCellXfs = count($this->cellXfCollection); // copy all the shared cellXfs from the external workbook and append them to the current foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) { $this->addCellXf(clone $cellXf); } // move sheet to this workbook $pSheet->rebindParent($this); // update the cellXfs foreach ($pSheet->getCoordinates(false) as $coordinate) { $cell = $pSheet->getCell($coordinate); $cell->setXfIndex($cell->getXfIndex() + $countCellXfs); } return $this->addSheet($pSheet, $iSheetIndex); }
php
{ "resource": "" }
q251258
Spreadsheet.addNamedRange
validation
public function addNamedRange(NamedRange $namedRange) { if ($namedRange->getScope() == null) { // global scope $this->namedRanges[$namedRange->getName()] = $namedRange; } else { // local scope $this->namedRanges[$namedRange->getScope()->getTitle() . '!' . $namedRange->getName()] = $namedRange; } return true; }
php
{ "resource": "" }
q251259
Spreadsheet.removeNamedRange
validation
public function removeNamedRange($namedRange, Worksheet $pSheet = null) { if ($pSheet === null) { if (isset($this->namedRanges[$namedRange])) { unset($this->namedRanges[$namedRange]); } } else { if (isset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange])) { unset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange]); } } return $this; }
php
{ "resource": "" }
q251260
Spreadsheet.addCellXf
validation
public function addCellXf(Style $style) { $this->cellXfCollection[] = $style; $style->setIndex(count($this->cellXfCollection) - 1); }
php
{ "resource": "" }
q251261
Spreadsheet.removeCellXfByIndex
validation
public function removeCellXfByIndex($pIndex) { if ($pIndex > count($this->cellXfCollection) - 1) { throw new Exception('CellXf index is out of bounds.'); } // first remove the cellXf array_splice($this->cellXfCollection, $pIndex, 1); // then update cellXf indexes for cells foreach ($this->workSheetCollection as $worksheet) { foreach ($worksheet->getCoordinates(false) as $coordinate) { $cell = $worksheet->getCell($coordinate); $xfIndex = $cell->getXfIndex(); if ($xfIndex > $pIndex) { // decrease xf index by 1 $cell->setXfIndex($xfIndex - 1); } elseif ($xfIndex == $pIndex) { // set to default xf index 0 $cell->setXfIndex(0); } } } }
php
{ "resource": "" }
q251262
Spreadsheet.addCellStyleXf
validation
public function addCellStyleXf(Style $pStyle) { $this->cellStyleXfCollection[] = $pStyle; $pStyle->setIndex(count($this->cellStyleXfCollection) - 1); }
php
{ "resource": "" }
q251263
Spreadsheet.removeCellStyleXfByIndex
validation
public function removeCellStyleXfByIndex($pIndex) { if ($pIndex > count($this->cellStyleXfCollection) - 1) { throw new Exception('CellStyleXf index is out of bounds.'); } array_splice($this->cellStyleXfCollection, $pIndex, 1); }
php
{ "resource": "" }
q251264
Functions.flattenArray
validation
public static function flattenArray($array) { if (!is_array($array)) { return (array) $array; } $arrayValues = []; foreach ($array as $value) { if (is_array($value)) { foreach ($value as $val) { if (is_array($val)) { foreach ($val as $v) { $arrayValues[] = $v; } } else { $arrayValues[] = $val; } } } else { $arrayValues[] = $value; } } return $arrayValues; }
php
{ "resource": "" }
q251265
Functions.flattenArrayIndexed
validation
public static function flattenArrayIndexed($array) { if (!is_array($array)) { return (array) $array; } $arrayValues = []; foreach ($array as $k1 => $value) { if (is_array($value)) { foreach ($value as $k2 => $val) { if (is_array($val)) { foreach ($val as $k3 => $v) { $arrayValues[$k1 . '.' . $k2 . '.' . $k3] = $v; } } else { $arrayValues[$k1 . '.' . $k2] = $val; } } } else { $arrayValues[$k1] = $value; } } return $arrayValues; }
php
{ "resource": "" }
q251266
ContactsService.getContact
validation
function getContact($contactId, $checksum, $standard_fields = array(), $custom_fields = array(), $ignoreChecksum = false) { $queryParameters = array( 'id' => $contactId, 'checksum' => $checksum, 'standard_field' => $standard_fields, 'ignore_checksum' => $ignoreChecksum ? "true" : "false" ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields); return $this->get('contacts/contact', $queryParameters); }
php
{ "resource": "" }
q251267
ContactsService.getContacts
validation
function getContacts($page_index = 1, $page_size = 100, $standard_fields = array(), $custom_fields = array()) { $queryParameters = array( 'page_index' => $page_index, 'page_size' => $page_size, 'standard_field' => $standard_fields ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields); return $this->get('contacts', $queryParameters); }
php
{ "resource": "" }
q251268
ContactsService.getContactByEmail
validation
function getContactByEmail($email, $standard_fields = array(), $custom_fields = array()) { $queryParameters = array( 'standard_field' => $standard_fields ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields); return $this->get('contacts/email/' . utf8_encode($email), $queryParameters); }
php
{ "resource": "" }
q251269
ContactsService.getContactsByExternalId
validation
function getContactsByExternalId($externalId, $standard_fields = array(), $custom_fields = array()) { $queryParameters = array( 'standard_field' => $standard_fields ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields); return $this->get('contacts/externalid/' . utf8_encode($externalId), $queryParameters); }
php
{ "resource": "" }
q251270
ContactsService.getContactsByFilterId
validation
function getContactsByFilterId($filterId, $page_index = 1, $page_size = 100, $standard_fields = array(), $custom_fields = array()) { $queryParameters = array( 'page_index' => $page_index, 'page_size' => $page_size, 'standard_field' => $standard_fields ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $custom_fields); return $this->get('contacts/filter/' . utf8_encode($filterId), $queryParameters); }
php
{ "resource": "" }
q251271
ContactsService.updateContact
validation
function updateContact($contact, $checksum = "", $src = null, $subscriptionPage = null, $triggerDoi = FALSE, $doiMailingKey = null, $ignoreChecksum = false) { $queryParameters = array( 'id' => $contact->id, 'checksum' => $checksum, 'triggerdoi' => ($triggerDoi == TRUE) ? "true" : "false", 'ignore_checksum' => $ignoreChecksum ? "true" : "false" ); if (isset($contact->permission)) $queryParameters['permission'] = $contact->permission->getCode(); if (isset($src)) $queryParameters['src'] = $src; if (isset($subscriptionPage)) $queryParameters['page_key'] = $subscriptionPage; $doiMailingKey = trim($doiMailingKey); if (!empty($doiMailingKey)) $queryParameters['doimailing'] = $doiMailingKey; // The API allows only some of the fields to be submitted $contactToSend = new Contact(null, $contact->email, null, $contact->external_id, null, $contact->standard_fields, $contact->custom_fields); return $this->put("contacts/contact", $contactToSend->toXMLString(), $queryParameters); }
php
{ "resource": "" }
q251272
ContactsService.synchronizeContacts
validation
function synchronizeContacts($contacts, $permission = null, $syncMode = null, $useExternalId = false, $ignoreInvalidContacts = false, $reimportUnsubscribedContacts = true, $overridePermission = true, $updateOnly = false, $preferMaileonId = false) { $queryParameters = array( 'permission' => ($permission == null) ? 1 : $permission->getCode(), 'sync_mode' => ($syncMode == null) ? 2 : $syncMode->getCode(), 'use_external_id' => ($useExternalId == TRUE) ? "true" : "false", 'ignore_invalid_contacts' => ($ignoreInvalidContacts == TRUE) ? "true" : "false", 'reimport_unsubscribed_contacts' => ($reimportUnsubscribedContacts == TRUE) ? "true" : "false", 'override_permission' => ($overridePermission == TRUE) ? "true" : "false", 'update_only' => ($updateOnly == TRUE) ? "true" : "false", 'prefer_maileon_id' => ($preferMaileonId == TRUE) ? "true" : "false" ); $cleanedContacts = new Contacts(); foreach ($contacts as $contact) { $cleanedContact = new Contact($contact->id, $contact->email, null, $contact->external_id, null, $contact->standard_fields, $contact->custom_fields); $cleanedContacts->addContact($cleanedContact); } return $this->post("contacts", $cleanedContacts->toXMLString(), $queryParameters); }
php
{ "resource": "" }
q251273
ContactsService.unsubscribeContactByEmail
validation
function unsubscribeContactByEmail($email, $mailingId = "", $reasons = null) { $queryParameters = array(); if (!empty($mailingId)) { $queryParameters['mailingId'] = $mailingId; } if (!empty($reasons)) { if (is_array($reasons)) { $queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons); } else { $queryParameters['reason'] = urlencode($reasons); } } $encodedEmail = utf8_encode($email); return $this->delete("contacts/email/${encodedEmail}/unsubscribe", $queryParameters); }
php
{ "resource": "" }
q251274
ContactsService.addUnsubscriptionReasonsToUnsubscribedContact
validation
function addUnsubscriptionReasonsToUnsubscribedContact($id, $checksum = null, $reasons = null, $ignore_checksum = false) { $queryParameters = array(); $queryParameters['id'] = $id; if (!empty($checksum)) { $queryParameters['checksum'] = $checksum; } if ($ignore_checksum===true) $queryParameters['ignore_checksum'] = "true"; if (!empty($reasons)) { if (is_array($reasons)) { $queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons); } else { $queryParameters['reason'] = urlencode($reasons); } } return $this->put("contacts/contact/unsubscribe/reasons", null, $queryParameters); }
php
{ "resource": "" }
q251275
ContactsService.unsubscribeContactById
validation
function unsubscribeContactById($id, $mailingId = "", $reasons = null) { $queryParameters = array( 'id' => $id ); if (!empty($mailingId)) { $queryParameters['mailingId'] = $mailingId; } if (!empty($reasons)) { if (is_array($reasons)) { $queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons); } else { $queryParameters['reason'] = urlencode($reasons); } } return $this->delete("contacts/contact/unsubscribe", $queryParameters); }
php
{ "resource": "" }
q251276
ContactsService.unsubscribeContactByExternalId
validation
function unsubscribeContactByExternalId($externalId, $mailingId = "", $reasons = null) { $queryParameters = array(); if (!empty($mailingId)) { $queryParameters['mailingId'] = $mailingId; } if (!empty($reasons)) { if (is_array($reasons)) { $queryParameters = $this->appendArrayFields($queryParameters, 'reason', $reasons); } else { $queryParameters['reason'] = urlencode($reasons); } } $encodedExternalId = utf8_encode($externalId); return $this->delete("contacts/externalid/${encodedExternalId}/unsubscribe", $queryParameters); }
php
{ "resource": "" }
q251277
ContactsService.getBlockedContacts
validation
function getBlockedContacts($standardFields = array(), $customFields = array(), $pageIndex = 1, $pageSize = 1000) { $queryParameters = array( 'standard_field' => $standardFields, 'page_index' => $pageIndex, 'page_size' => $pageSize ); $queryParameters = $this->appendArrayFields($queryParameters, 'custom_field', $customFields); return $this->get('contacts/blocked', $queryParameters); }
php
{ "resource": "" }
q251278
ContactsService.createCustomField
validation
function createCustomField($name, $type = 'string') { $queryParameters = array('type' => $type); $encodedName = urlencode(mb_convert_encoding($name, "UTF-8")); return $this->post("contacts/fields/custom/${encodedName}", "", $queryParameters); }
php
{ "resource": "" }
q251279
ContactsService.renameCustomField
validation
function renameCustomField($oldName, $newName) { $encodedOldName = urlencode(mb_convert_encoding($oldName, "UTF-8")); $encodedNewName = urlencode(mb_convert_encoding($newName, "UTF-8")); return $this->put("contacts/fields/custom/${encodedOldName}/${encodedNewName}"); }
php
{ "resource": "" }
q251280
Xml.trySimpleXMLLoadString
validation
public function trySimpleXMLLoadString($pFilename) { try { $xml = simplexml_load_string( $this->securityScan(file_get_contents($pFilename)), 'SimpleXMLElement', Settings::getLibXmlLoaderOptions() ); } catch (\Exception $e) { throw new Exception('Cannot load invalid XML file: ' . $pFilename, 0, $e); } return $xml; }
php
{ "resource": "" }
q251281
Xml.load
validation
public function load($pFilename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); $spreadsheet->removeSheetByIndex(0); // Load into this instance return $this->loadIntoExisting($pFilename, $spreadsheet); }
php
{ "resource": "" }
q251282
Rule.toString
validation
function toString() { return "Rule [isCustomfield=" . ($this->isCustomfield) ? "true" : "false" . ", field=" . $this->field . ", operator=" . $this->operator . ", value=" . $this->value . " (type = " . $this->type . ")"; }
php
{ "resource": "" }
q251283
StoragePluginManager.validatePlugin
validation
public function validatePlugin($plugin) { if ($plugin instanceof Storage\StorageInterface) { return; } throw new Storage\Exception\RuntimeException(sprintf('Plugin of type %s is invalid; must implement %s\Storage\StorageInterfaceInterface', (is_object($plugin) ? get_class($plugin) : gettype($plugin)), __NAMESPACE__)); }
php
{ "resource": "" }
q251284
PieceBag.offsetSet
validation
public function offsetSet($key, $value) { if(!($value instanceof PieceInterface)) { $value = new Piece($value); } parent::offsetSet($key, $value); }
php
{ "resource": "" }
q251285
FormItemFactory.createSelectAssociationFormItem
validation
private function createSelectAssociationFormItem(Model $model, Column $column, $item) { $result = new SelectFormItem(); $relations = $this->aujaConfigurator->getRelationsForModel($model); $relatedModel = null; foreach ($relations as $relation) { $rightModel = $relation->getRight(); if (starts_with($column->getName(), camel_case($rightModel->getName()))) { $relatedModel = $rightModel; } } if ($relatedModel != null) { $displayName = $this->aujaConfigurator->getDisplayName($relatedModel); $result->setName($displayName); $result->setValue($item->id); $items = call_user_func(array($relatedModel->getName(), 'all')); $displayField = $this->aujaConfigurator->getDisplayField($relatedModel); foreach ($items as $item) { $label = isset($item->$displayField) ? $item->$displayField : ''; $value = $item->id; $option = new SelectOption($label, $value); $result->addOption($option); } } return $result; }
php
{ "resource": "" }
q251286
FormItemFactory.createFromType
validation
private function createFromType(Model $model, Column $column, $item) { $result = null; switch ($column->getType()) { case Type::TEXT: case Type::TARRAY: case Type::SIMPLE_ARRAY: case Type::JSON_ARRAY: case Type::OBJECT: case Type::BLOB: $result = new TextAreaFormItem(); break; case Type::INTEGER: case Type::SMALLINT: case Type::BIGINT: $result = new IntegerFormItem(); break; case Type::DECIMAL: case Type::FLOAT: $result = new NumberFormItem(); break; case Type::BOOLEAN: $result = new CheckboxFormItem(); break; case Type::DATE: $result = new DateFormItem(); break; case Type::DATETIME: case Type::DATETIMETZ: $result = new DateTimeFormItem(); break; case Type::TIME: $result = new TimeFormItem(); break; case Type::STRING: case Type::GUID: default: $result = new TextFormItem(); break; } $columnName = $column->getName(); $result->setName($columnName); $result->setLabel(Lang::trans($this->aujaConfigurator->getColumnDisplayName($model, $columnName))); if ($item != null && isset($item->$columnName)) { $result->setValue($item->$columnName); } return $result; }
php
{ "resource": "" }
q251287
ContactReference.isEmpty
validation
function isEmpty() { $result = !isset($this->id) && !isset($this->external_id) && !isset($this->email); return $result; }
php
{ "resource": "" }
q251288
Copy.copyRecursive
validation
protected function copyRecursive( $src, $dst, $depth, Logger $logger ) { if ( $depth == 0 ) { return; } // Check if source file exists at all. if ( !is_file( $src ) && !is_dir( $src ) ) { $logger->log( "$src is not a valid source.", Logger::WARNING ); return; } // Skip non readable files in src directory if ( !is_readable( $src ) ) { $logger->log( "$src is not readable, skipping.", Logger::WARNING ); return; } // Destination file should not exist if ( is_file( $dst ) || is_dir( $dst ) ) { $logger->log( "$dst already exists, and cannot be overwritten.", Logger::WARNING ); return; } // Actually copy if ( is_dir( $src ) ) { mkdir( $dst ); } elseif ( is_file( $src ) ) { copy( $src, $dst ); return; } // Recurse into directory $dh = opendir( $src ); while ( ( $file = readdir( $dh ) ) !== false ) { if ( ( $file === '.' ) || ( $file === '..' ) ) { continue; } $this->copyRecursive( $src . '/' . $file, $dst . '/' . $file, $depth - 1, $logger ); } }
php
{ "resource": "" }
q251289
Theme.getColourByIndex
validation
public function getColourByIndex($index) { if (isset($this->colourMap[$index])) { return $this->colourMap[$index]; } return null; }
php
{ "resource": "" }
q251290
JSONSerializer.toArray
validation
private static function toArray($object) { $type = gettype($object); if($type == 'array') { foreach($object as $element) { // call this method on each object in the array $result[]= self::toArray($element); } // return the processed array return $result; } else if ($type == 'object') { // if we can call toArray() on this object call it, otherwise return // the object as-is and trigger a notice if(is_subclass_of($object, 'AbstractJSONWrapper')) { return $object->toArray(); } else { trigger_error("JSONSerializer: Trying to serialize " . get_class($object)); return $object; } } else { // if this is not an object we have nothing to do return $object; } }
php
{ "resource": "" }
q251291
ConfigResolver.resolve
validation
public function resolve() { if (is_null($this->config->getDisplayField()) || $this->config->getDisplayField() == '') { $this->config->setDisplayField($this->resolveDisplayField()); $this->config->setVisibleFields($this->resolveVisibleFields()); } return $this->config; }
php
{ "resource": "" }
q251292
ConfigResolver.resolveVisibleFields
validation
private function resolveVisibleFields() { $result = []; $columns = $this->model->getColumns(); foreach($columns as $column){ $result[] = $column->getName(); } return $result; }
php
{ "resource": "" }
q251293
FakerGenerator.resolvePath
validation
private function resolvePath($path_alias, $file_name) { $path = \Yii::getAlias($path_alias, false); $path = $path ? realpath($path) : $path; $file_name = !preg_match('/\.php$/i', $file_name) ? $file_name . '.php' : $file_name; if (!$path || !is_dir($path) || !file_exists($path . '/' . $file_name)) { throw new Exception("Faker template \"{$path}/{$file_name}\" not found"); } return $path . '/' . $file_name; }
php
{ "resource": "" }
q251294
DataSeriesValues.setDataType
validation
public function setDataType($dataType) { if (!in_array($dataType, self::$dataTypeValues)) { throw new Exception('Invalid datatype for chart data series values'); } $this->dataType = $dataType; return $this; }
php
{ "resource": "" }
q251295
DataSeriesValues.setDataValues
validation
public function setDataValues($dataValues) { $this->dataValues = Functions::flattenArray($dataValues); $this->pointCount = count($dataValues); return $this; }
php
{ "resource": "" }
q251296
Stack.push
validation
public function push($type, $value, $reference = null) { $this->stack[$this->count++] = [ 'type' => $type, 'value' => $value, 'reference' => $reference, ]; if ($type == 'Function') { $localeFunction = Calculation::localeFunc($value); if ($localeFunction != $value) { $this->stack[($this->count - 1)]['localeValue'] = $localeFunction; } } }
php
{ "resource": "" }
q251297
MemoryCacheItemPool.getItem
validation
public function getItem($key) { if ($this->hasItem($key) !== true) { $this->data[$key] = new CacheItem($key, null, false); } return $this->data[$key]; }
php
{ "resource": "" }
q251298
MemoryCacheItemPool.hasItem
validation
public function hasItem($key) { if (isset($this->data[$key])) { /* @var $item \Psr6NullCache\CacheItem */ $item = $this->data[$key]; if ($item->isHit() === true && ($item->getExpires() === null || $item->getExpires() > new DateTime())) { return true; } } return false; }
php
{ "resource": "" }
q251299
MemoryCacheItemPool.save
validation
public function save(CacheItemInterface $item) { $item->setIsHit(true); $this->data[$item->getKey()] = $item; return true; }
php
{ "resource": "" }