Fix code style

This commit is contained in:
Adrien Loison committed 2017-09-06 00:33:43 +02:00
1 parent 740fcfb8c1
commit b968513cb9
171 files changed
+517 -792

No files matched your search

@@ -2,19 +2,17 @@
namespace Box\Spout\Writer\ODS\Creator;
use Box\Spout\Common\Helper\StringHelper;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
use Box\Spout\Common\Helper\Escaper;
use Box\Spout\Common\Helper\StringHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
/**
* Class HelperFactory
* Factory for helpers needed by the ODS Writer
*
* @package Box\Spout\Writer\ODS\Creator
*/
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
{
@@ -4,8 +4,8 @@ namespace Box\Spout\Writer\ODS\Creator;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Writer\Common\Manager\SheetManager;
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
use Box\Spout\Writer\ODS\Manager\Style\StyleRegistry;
@@ -15,8 +15,6 @@ use Box\Spout\Writer\ODS\Manager\WorksheetManager;
/**
* Class ManagerFactory
* Factory for managers needed by the ODS Writer
*
* @package Box\Spout\Writer\ODS\Creator
*/
class ManagerFactory implements ManagerFactoryInterface
{
@@ -78,6 +76,7 @@ class ManagerFactory implements ManagerFactoryInterface
public function createSheetManager()
{
$stringHelper = $this->helperFactory->createStringHelper();
return new SheetManager($stringHelper);
}
@@ -88,6 +87,7 @@ class ManagerFactory implements ManagerFactoryInterface
private function createStyleManager(OptionsManagerInterface $optionsManager)
{
$styleRegistry = $this->createStyleRegistry($optionsManager);
return new StyleManager($styleRegistry);
}
@@ -98,6 +98,7 @@ class ManagerFactory implements ManagerFactoryInterface
private function createStyleRegistry(OptionsManagerInterface $optionsManager)
{
$defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
return new StyleRegistry($defaultRowStyle);
}
}
+4 -4
View File
@@ -2,8 +2,8 @@
namespace Box\Spout\Writer\ODS\Helper;
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
/**
* Class BorderHelper
@@ -27,9 +27,9 @@ class BorderHelper
* @var array
*/
protected static $widthMap = [
Border::WIDTH_THIN => '0.75pt',
Border::WIDTH_THIN => '0.75pt',
Border::WIDTH_MEDIUM => '1.75pt',
Border::WIDTH_THICK => '2.5pt',
Border::WIDTH_THICK => '2.5pt',
];
/**
@@ -38,7 +38,7 @@ class BorderHelper
* @var array
*/
protected static $styleMap = [
Border::STYLE_SOLID => 'solid',
Border::STYLE_SOLID => 'solid',
Border::STYLE_DASHED => 'dashed',
Border::STYLE_DOTTED => 'dotted',
Border::STYLE_DOUBLE => 'double',
@@ -2,9 +2,9 @@
namespace Box\Spout\Writer\ODS\Helper;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
use Box\Spout\Writer\ODS\Manager\WorksheetManager;
@@ -12,8 +12,6 @@ use Box\Spout\Writer\ODS\Manager\WorksheetManager;
* Class FileSystemHelper
* This class provides helper functions to help with the file system operations
* like files/folders creation & deletion for ODS files
*
* @package Box\Spout\Writer\ODS\Helper
*/
class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface
{
@@ -70,8 +68,8 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
/**
* Creates all the folders needed to create a ODS file, as well as the files that won't change.
*
* @return void
* @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the base folders
* @return void
*/
public function createBaseFilesAndFolders()
{
@@ -86,20 +84,21 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
/**
* Creates the folder that will be used as root
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
* @return FileSystemHelper
*/
protected function createRootFolder()
{
$this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('ods'));
return $this;
}
/**
* Creates the "META-INF" folder under the root folder as well as the "manifest.xml" file in it
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the "manifest.xml" file
* @return FileSystemHelper
*/
protected function createMetaInfoFolderAndFile()
{
@@ -113,12 +112,12 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme
/**
* Creates the "manifest.xml" file under the "META-INF" folder (under root)
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
* @return FileSystemHelper
*/
protected function createManifestFile()
{
$manifestXmlFileContents = <<<EOD
$manifestXmlFileContents = <<<'EOD'
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
<manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
@@ -137,20 +136,21 @@ EOD;
* Creates the temp folder where specific sheets content will be written to.
* This folder is not part of the final ODS file and is only used to be able to jump between sheets.
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
* @return FileSystemHelper
*/
protected function createSheetsContentTempFolder()
{
$this->sheetsContentTempFolder = $this->createFolder($this->rootFolder, self::SHEETS_CONTENT_TEMP_FOLDER_NAME);
return $this;
}
/**
* Creates the "meta.xml" file under the root folder
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
* @return FileSystemHelper
*/
protected function createMetaFile()
{
@@ -176,12 +176,13 @@ EOD;
/**
* Creates the "mimetype" file under the root folder
*
* @return FileSystemHelper
* @throws \Box\Spout\Common\Exception\IOException If unable to create the file
* @return FileSystemHelper
*/
protected function createMimetypeFile()
{
$this->createFileWithContents($this->rootFolder, self::MIMETYPE_FILE_NAME, self::MIMETYPE);
return $this;
}
@@ -195,7 +196,7 @@ EOD;
*/
public function createContentFile($worksheetManager, $styleManager, $worksheets)
{
$contentXmlFileContents = <<<EOD
$contentXmlFileContents = <<<'EOD'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
EOD;
@@ -253,10 +254,10 @@ EOD;
public function deleteWorksheetTempFolder()
{
$this->deleteFolderRecursively($this->sheetsContentTempFolder);
return $this;
}
/**
* Creates the "styles.xml" file under the root folder
*
@@ -2,15 +2,13 @@
namespace Box\Spout\Writer\ODS\Manager;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Common\Manager\OptionsManagerAbstract;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Options;
/**
* Class OptionsManager
* ODS Writer options manager
*
* @package Box\Spout\Writer\ODS\Manager
*/
class OptionsManager extends OptionsManagerAbstract
{
@@ -28,7 +26,7 @@ class OptionsManager extends OptionsManagerAbstract
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function getSupportedOptions()
{
@@ -40,7 +38,7 @@ class OptionsManager extends OptionsManagerAbstract
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function setDefaultOptions()
{
@@ -8,8 +8,6 @@ use Box\Spout\Writer\ODS\Helper\BorderHelper;
/**
* Class StyleManager
* Manages styles to be applied to a cell
*
* @package Box\Spout\Writer\ODS\Manager\Style
*/
class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
{
@@ -24,7 +22,7 @@ class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager
*/
public function getStylesXMLFileContent($numWorksheets)
{
$content = <<<EOD
$content = <<<'EOD'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-styles office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
EOD;
@@ -34,7 +32,7 @@ EOD;
$content .= $this->getAutomaticStylesSectionContent($numWorksheets);
$content .= $this->getMasterStylesSectionContent($numWorksheets);
$content .= <<<EOD
$content .= <<<'EOD'
</office:document-styles>
EOD;
@@ -132,7 +130,6 @@ EOD;
return $content;
}
/**
* Returns the contents of the "<office:font-face-decls>" section, inside "content.xml" file.
*
@@ -163,7 +160,7 @@ EOD;
$content .= $this->getStyleSectionContent($style);
}
$content .= <<<EOD
$content .= <<<'EOD'
<style:style style:family="table-column" style:name="co1">
<style:table-column-properties fo:break-before="auto"/>
</style:style>
@@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
/**
* Class StyleRegistry
* Registry for all used styles
*
* @package Box\Spout\Writer\ODS\Manager\Style
*/
class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry
{
@@ -10,8 +10,6 @@ use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
/**
* Class WorkbookManager
* ODS workbook manager, providing the interfaces to work with workbook.
*
* @package Box\Spout\Writer\ODS\Manager
*/
class WorkbookManager extends WorkbookManagerAbstract
{
@@ -45,6 +43,7 @@ class WorkbookManager extends WorkbookManagerAbstract
public function getWorksheetFilePath(Sheet $sheet)
{
$sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder();
return $sheetsContentTempFolder . '/sheet' . $sheet->getIndex() . '.xml';
}
@@ -65,4 +64,4 @@ class WorkbookManager extends WorkbookManagerAbstract
->createStylesFile($this->styleManager, $numWorksheets)
->zipRootFolderAndCopyToStream($finalFilePointer);
}
}
}
@@ -7,16 +7,13 @@ use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\StringHelper;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\ODS\Manager\Style\StyleManager;
/**
* Class WorksheetManager
* ODS worksheet manager, providing the interfaces to work with ODS worksheets.
*
* @package Box\Spout\Writer\ODS\Manager
*/
class WorksheetManager implements WorksheetManagerInterface
{
@@ -39,8 +36,8 @@ class WorksheetManager implements WorksheetManagerInterface
public function __construct(
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
StringHelper $stringHelper,
EntityFactory $entityFactory)
{
EntityFactory $entityFactory
) {
$this->stringsEscaper = $stringsEscaper;
$this->stringHelper = $stringHelper;
$this->entityFactory = $entityFactory;
@@ -50,8 +47,8 @@ class WorksheetManager implements WorksheetManagerInterface
* Prepares the worksheet to accept data
*
* @param Worksheet $worksheet The worksheet to start
* @return void
* @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing
* @return void
*/
public function startSheet(Worksheet $worksheet)
{
@@ -65,8 +62,8 @@ class WorksheetManager implements WorksheetManagerInterface
* Checks if the sheet has been sucessfully created. Throws an exception if not.
*
* @param bool|resource $sheetFilePointer Pointer to the sheet data file or FALSE if unable to open the file
* @return void
* @throws IOException If the sheet data file cannot be opened for writing
* @return void
*/
private function throwIfSheetFilePointerIsNotAvailable($sheetFilePointer)
{
@@ -100,9 +97,9 @@ class WorksheetManager implements WorksheetManagerInterface
* @param array $dataRow Array containing data to be written. Cannot be empty.
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
* @param Style $rowStyle Style to be applied to the row. NULL means use default style.
* @return void
* @throws IOException If the data cannot be written
* @throws InvalidArgumentException If a cell value's type is not supported
* @return void
*/
public function addRow(Worksheet $worksheet, $dataRow, $rowStyle)
{
@@ -124,7 +121,6 @@ class WorksheetManager implements WorksheetManagerInterface
// Using isset here because it is way faster than array_key_exists...
if (!isset($dataRowWithNumericIndexes[$nextCellIndex]) ||
$currentCellValue !== $dataRowWithNumericIndexes[$nextCellIndex]) {
$numTimesValueRepeated = ($nextCellIndex - $currentCellIndex);
$data .= $this->getCellXML($currentCellValue, $styleIndex, $numTimesValueRepeated);
@@ -152,8 +148,8 @@ class WorksheetManager implements WorksheetManagerInterface
* @param mixed $cellValue The value to be written
* @param int $styleIndex Index of the used style
* @param int $numTimesValueRepeated Number of times the value is consecutively repeated
* @return string The cell XML content
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported
* @return string The cell XML content
*/
private function getCellXML($cellValue, $styleIndex, $numTimesValueRepeated)
{
@@ -163,7 +159,7 @@ class WorksheetManager implements WorksheetManagerInterface
$data .= ' table:number-columns-repeated="' . $numTimesValueRepeated . '"';
}
/** @TODO Remove code duplication with XLSX writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
/* @TODO Remove code duplication with XLSX writer: https://github.com/box/spout/pull/383#discussion_r113292746 */
if ($cellValue instanceof Cell) {
$cell = $cellValue;
} else {
@@ -179,15 +175,15 @@ class WorksheetManager implements WorksheetManagerInterface
}
$data .= '</table:table-cell>';
} else if ($cell->isBoolean()) {
} elseif ($cell->isBoolean()) {
$data .= ' office:value-type="boolean" calcext:value-type="boolean" office:boolean-value="' . $cell->getValue() . '">';
$data .= '<text:p>' . $cell->getValue() . '</text:p>';
$data .= '</table:table-cell>';
} else if ($cell->isNumeric()) {
} elseif ($cell->isNumeric()) {
$data .= ' office:value-type="float" calcext:value-type="float" office:value="' . $cell->getValue() . '">';
$data .= '<text:p>' . $cell->getValue() . '</text:p>';
$data .= '</table:table-cell>';
} else if ($cell->isEmpty()) {
} elseif ($cell->isEmpty()) {
$data .= '/>';
} else {
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cell->getValue()));
+2 -3
View File
@@ -8,8 +8,6 @@ use Box\Spout\Writer\WriterMultiSheetsAbstract;
/**
* Class Writer
* This class provides base support to write data to ODS files
*
* @package Box\Spout\Writer\ODS
*/
class Writer extends WriterMultiSheetsAbstract
{
@@ -22,14 +20,15 @@ class Writer extends WriterMultiSheetsAbstract
*
* @api
* @param string $tempFolder Temporary folder where the files to create the ODS will be stored
* @return Writer
* @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened
* @return Writer
*/
public function setTempFolder($tempFolder)
{
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.');
$this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
return $this;
}
}