From f90eae6b610f9d8944d4ae5e257379bc5832fcd4 Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Tue, 5 Sep 2017 23:39:54 +0200 Subject: [PATCH] Fix code style --- src/Spout/Autoloader/Psr4Autoloader.php | 12 +++-- src/Spout/Autoloader/autoload.php | 2 +- src/Spout/Common/Creator/HelperFactory.php | 2 - .../Exception/EncodingConversionException.php | 1 - src/Spout/Common/Exception/IOException.php | 1 - .../Exception/InvalidArgumentException.php | 1 - src/Spout/Common/Exception/SpoutException.php | 1 - .../Exception/UnsupportedTypeException.php | 1 - src/Spout/Common/Helper/EncodingHelper.php | 10 ++--- src/Spout/Common/Helper/Escaper/CSV.php | 2 - .../Helper/Escaper/EscaperInterface.php | 2 - src/Spout/Common/Helper/Escaper/ODS.php | 2 - src/Spout/Common/Helper/Escaper/XLSX.php | 12 +++-- src/Spout/Common/Helper/FileSystemHelper.php | 12 +++-- .../Helper/FileSystemHelperInterface.php | 10 ++--- .../Common/Helper/GlobalFunctionsHelper.php | 3 +- src/Spout/Common/Helper/StringHelper.php | 4 +- .../Common/Manager/OptionsManagerAbstract.php | 2 - .../Manager/OptionsManagerInterface.php | 2 - .../Reader/CSV/Creator/EntityFactory.php | 3 +- .../Reader/CSV/Manager/OptionsManager.php | 6 +-- src/Spout/Reader/CSV/Reader.php | 10 ++--- src/Spout/Reader/CSV/RowIterator.php | 28 +++++------- src/Spout/Reader/CSV/Sheet.php | 3 -- src/Spout/Reader/CSV/SheetIterator.php | 13 +++--- .../Common/Creator/EntityFactoryInterface.php | 2 - src/Spout/Reader/Common/Entity/Options.php | 2 - src/Spout/Reader/Common/ReaderOptions.php | 4 +- src/Spout/Reader/Common/XMLProcessor.php | 6 +-- .../IteratorNotRewindableException.php | 1 - .../Exception/NoSheetsFoundException.php | 1 - .../Reader/Exception/ReaderException.php | 1 - .../Exception/ReaderNotOpenedException.php | 1 - .../SharedStringNotFoundException.php | 1 - .../Exception/XMLProcessingException.php | 2 - src/Spout/Reader/IteratorInterface.php | 2 - .../Reader/ODS/Creator/EntityFactory.php | 4 -- .../Reader/ODS/Creator/HelperFactory.php | 6 +-- .../Reader/ODS/Helper/CellValueFormatter.php | 14 +++--- .../Reader/ODS/Helper/SettingsHelper.php | 3 -- .../Reader/ODS/Manager/OptionsManager.php | 6 +-- src/Spout/Reader/ODS/Reader.php | 4 +- src/Spout/Reader/ODS/RowIterator.php | 34 +++++++------- src/Spout/Reader/ODS/Sheet.php | 4 -- src/Spout/Reader/ODS/SheetIterator.php | 19 ++++---- src/Spout/Reader/ReaderAbstract.php | 17 ++++--- src/Spout/Reader/ReaderFactory.php | 5 +-- src/Spout/Reader/ReaderInterface.php | 6 +-- src/Spout/Reader/SheetInterface.php | 2 - .../Wrapper/XMLInternalErrorsHelper.php | 7 +-- src/Spout/Reader/Wrapper/XMLReader.php | 13 +++--- .../Reader/XLSX/Creator/EntityFactory.php | 10 ++--- .../Reader/XLSX/Creator/HelperFactory.php | 8 +--- .../Reader/XLSX/Creator/ManagerFactory.php | 4 +- src/Spout/Reader/XLSX/Helper/CellHelper.php | 4 +- .../Reader/XLSX/Helper/CellValueFormatter.php | 18 ++++---- .../Reader/XLSX/Helper/DateFormatHelper.php | 5 +-- .../Reader/XLSX/Manager/OptionsManager.php | 6 +-- .../CachingStrategyFactory.php | 5 +-- .../CachingStrategyInterface.php | 4 +- .../FileBasedStrategy.php | 8 ++-- .../SharedStringsCaching/InMemoryStrategy.php | 4 +- .../XLSX/Manager/SharedStringsManager.php | 13 +++--- .../Reader/XLSX/Manager/SheetManager.php | 8 ++-- .../Reader/XLSX/Manager/StyleManager.php | 17 +++---- src/Spout/Reader/XLSX/Reader.php | 10 ++--- src/Spout/Reader/XLSX/RowIterator.php | 34 ++++++-------- src/Spout/Reader/XLSX/Sheet.php | 3 -- src/Spout/Reader/XLSX/SheetIterator.php | 14 +++--- .../Writer/CSV/Manager/OptionsManager.php | 8 ++-- src/Spout/Writer/CSV/Writer.php | 9 ++-- .../Writer/Common/Creator/EntityFactory.php | 2 - .../Creator/ManagerFactoryInterface.php | 2 - .../Common/Creator/Style/BorderBuilder.php | 6 ++- .../Common/Creator/Style/StyleBuilder.php | 12 ++++- src/Spout/Writer/Common/Entity/Cell.php | 8 ++-- src/Spout/Writer/Common/Entity/Options.php | 2 - src/Spout/Writer/Common/Entity/Sheet.php | 4 +- .../Writer/Common/Entity/Style/Border.php | 5 +-- .../Writer/Common/Entity/Style/BorderPart.php | 4 +- .../Writer/Common/Entity/Style/Color.php | 4 +- .../Writer/Common/Entity/Style/Style.php | 21 ++++++--- src/Spout/Writer/Common/Entity/Workbook.php | 4 +- src/Spout/Writer/Common/Entity/Worksheet.php | 10 ++--- src/Spout/Writer/Common/Helper/CellHelper.php | 6 +-- ...ileSystemWithRootFolderHelperInterface.php | 6 +-- src/Spout/Writer/Common/Helper/ZipHelper.php | 5 +-- .../Writer/Common/Manager/SheetManager.php | 4 +- .../Common/Manager/Style/StyleManager.php | 3 +- .../Manager/Style/StyleManagerInterface.php | 2 - .../Common/Manager/Style/StyleMerger.php | 4 -- .../Common/Manager/Style/StyleRegistry.php | 3 +- .../Manager/WorkbookManagerAbstract.php | 26 +++++------ .../Manager/WorkbookManagerInterface.php | 12 +++-- .../Manager/WorksheetManagerInterface.php | 10 ++--- .../Exception/Border/InvalidNameException.php | 2 +- .../Border/InvalidStyleException.php | 2 +- .../Border/InvalidWidthException.php | 2 +- .../Exception/InvalidColorException.php | 1 - .../Exception/InvalidSheetNameException.php | 1 - .../Exception/SheetNotFoundException.php | 1 - .../WriterAlreadyOpenedException.php | 1 - .../Writer/Exception/WriterException.php | 1 - .../Exception/WriterNotOpenedException.php | 1 - .../Writer/ODS/Creator/HelperFactory.php | 14 +++--- .../Writer/ODS/Creator/ManagerFactory.php | 7 +-- src/Spout/Writer/ODS/Helper/BorderHelper.php | 8 ++-- .../Writer/ODS/Helper/FileSystemHelper.php | 27 +++++------ .../Writer/ODS/Manager/OptionsManager.php | 8 ++-- .../Writer/ODS/Manager/Style/StyleManager.php | 9 ++-- .../ODS/Manager/Style/StyleRegistry.php | 2 - .../Writer/ODS/Manager/WorkbookManager.php | 5 +-- .../Writer/ODS/Manager/WorksheetManager.php | 26 +++++------ src/Spout/Writer/ODS/Writer.php | 5 +-- src/Spout/Writer/WriterAbstract.php | 26 +++++------ src/Spout/Writer/WriterFactory.php | 4 +- src/Spout/Writer/WriterInterface.php | 14 +++--- .../Writer/WriterMultiSheetsAbstract.php | 30 ++++++------- .../Writer/XLSX/Creator/HelperFactory.php | 4 +- .../Writer/XLSX/Creator/ManagerFactory.php | 11 ++--- src/Spout/Writer/XLSX/Helper/BorderHelper.php | 20 ++++----- .../Writer/XLSX/Helper/FileSystemHelper.php | 45 ++++++++++--------- .../Writer/XLSX/Manager/OptionsManager.php | 8 ++-- .../XLSX/Manager/SharedStringsManager.php | 6 +-- .../XLSX/Manager/Style/StyleManager.php | 11 ++--- .../XLSX/Manager/Style/StyleRegistry.php | 4 -- .../Writer/XLSX/Manager/WorkbookManager.php | 5 +-- .../Writer/XLSX/Manager/WorksheetManager.php | 43 +++++++++--------- src/Spout/Writer/XLSX/Writer.php | 8 ++-- .../Common/Helper/EncodingHelperTest.php | 2 - tests/Spout/Common/Helper/Escaper/ODSTest.php | 6 +-- .../Spout/Common/Helper/Escaper/XLSXTest.php | 10 ++--- .../Common/Helper/FileSystemHelperTest.php | 2 - .../Common/Manager/OptionsManagerTest.php | 3 -- tests/Spout/Reader/CSV/ReaderTest.php | 20 ++++----- tests/Spout/Reader/CSV/SheetTest.php | 2 - tests/Spout/Reader/CSV/SpoutTestStream.php | 7 +-- tests/Spout/Reader/ODS/ReaderTest.php | 16 +++---- tests/Spout/Reader/ODS/SheetTest.php | 2 - tests/Spout/Reader/ReaderFactoryTest.php | 2 - tests/Spout/Reader/Wrapper/XMLReaderTest.php | 3 -- .../Reader/XLSX/Helper/CellHelperTest.php | 8 ++-- .../XLSX/Helper/CellValueFormatterTest.php | 6 +-- .../XLSX/Helper/DateFormatHelperTest.php | 2 - .../CachingStrategyFactoryTest.php | 6 +-- .../XLSX/Manager/SharedStringsManagerTest.php | 2 - .../Reader/XLSX/Manager/StyleManagerTest.php | 3 -- tests/Spout/Reader/XLSX/ReaderTest.php | 14 +++--- tests/Spout/Reader/XLSX/SheetTest.php | 2 - tests/Spout/ReflectionHelper.php | 4 +- tests/Spout/TestUsingResource.php | 2 - tests/Spout/Writer/CSV/WriterTest.php | 10 ++--- .../Common/Creator/StyleBuilderTest.php | 2 - .../Spout/Writer/Common/Entity/SheetTest.php | 2 - .../Writer/Common/Entity/Style/BorderTest.php | 6 +-- .../Writer/Common/Entity/Style/ColorTest.php | 3 -- .../Writer/Common/Helper/CellHelperTest.php | 26 +++++------ .../Common/Manager/Style/StyleManagerTest.php | 2 - .../Common/Manager/Style/StyleMergerTest.php | 2 - .../Manager/Style/StyleRegistryTest.php | 5 --- .../ODS/Manager/Style/StyleRegistryTest.php | 7 ++- tests/Spout/Writer/ODS/SheetTest.php | 2 - tests/Spout/Writer/ODS/WriterTest.php | 12 ++--- .../Spout/Writer/ODS/WriterWithStyleTest.php | 8 +--- tests/Spout/Writer/WriterFactoryTest.php | 2 - .../XLSX/Manager/Style/StyleManagerTest.php | 2 - .../XLSX/Manager/Style/StyleRegistryTest.php | 5 +-- tests/Spout/Writer/XLSX/SheetTest.php | 2 - tests/Spout/Writer/XLSX/WriterTest.php | 12 +++-- .../Spout/Writer/XLSX/WriterWithStyleTest.php | 35 +++++++-------- tests/bootstrap.php | 9 ++-- 171 files changed, 517 insertions(+), 792 deletions(-) diff --git a/src/Spout/Autoloader/Psr4Autoloader.php b/src/Spout/Autoloader/Psr4Autoloader.php index 67cccc3..9dcc374 100644 --- a/src/Spout/Autoloader/Psr4Autoloader.php +++ b/src/Spout/Autoloader/Psr4Autoloader.php @@ -5,8 +5,6 @@ namespace Box\Spout\Autoloader; /** * Class Psr4Autoloader * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example - * - * @package Box\Spout\Autoloader */ class Psr4Autoloader { @@ -16,7 +14,7 @@ class Psr4Autoloader * * @var array */ - protected $prefixes = array(); + protected $prefixes = []; /** * Register loader with SPL autoloader stack. @@ -25,7 +23,7 @@ class Psr4Autoloader */ public function register() { - spl_autoload_register(array($this, 'loadClass')); + spl_autoload_register([$this, 'loadClass']); } /** @@ -49,7 +47,7 @@ class Psr4Autoloader // initialize the namespace prefix array if (isset($this->prefixes[$prefix]) === false) { - $this->prefixes[$prefix] = array(); + $this->prefixes[$prefix] = []; } // retain the base directory for the namespace prefix @@ -75,7 +73,6 @@ class Psr4Autoloader // work backwards through the namespace names of the fully-qualified // class name to find a mapped file name while (false !== $pos = strrpos($prefix, '\\')) { - // retain the trailing namespace separator in the prefix $prefix = substr($class, 0, $pos + 1); @@ -114,7 +111,6 @@ class Psr4Autoloader // look through base directories for this namespace prefix foreach ($this->prefixes[$prefix] as $baseDir) { - // replace the namespace prefix with the base directory, // replace namespace separators with directory separators // in the relative class name, append with .php @@ -143,8 +139,10 @@ class Psr4Autoloader { if (file_exists($file)) { require $file; + return true; } + return false; } } diff --git a/src/Spout/Autoloader/autoload.php b/src/Spout/Autoloader/autoload.php index 73ee519..e08ee34 100644 --- a/src/Spout/Autoloader/autoload.php +++ b/src/Spout/Autoloader/autoload.php @@ -5,7 +5,7 @@ namespace Box\Spout\Autoloader; require_once 'Psr4Autoloader.php'; /** - * @var string $srcBaseDirectory + * @var string * Full path to "src/Spout" which is what we want "Box\Spout" to map to. */ $srcBaseDirectory = dirname(dirname(__FILE__)); diff --git a/src/Spout/Common/Creator/HelperFactory.php b/src/Spout/Common/Creator/HelperFactory.php index 755fe6c..2277f2c 100644 --- a/src/Spout/Common/Creator/HelperFactory.php +++ b/src/Spout/Common/Creator/HelperFactory.php @@ -10,8 +10,6 @@ use Box\Spout\Common\Helper\StringHelper; /** * Class HelperFactory * Factory to create helpers - * - * @package Box\Spout\Common\Creator */ class HelperFactory { diff --git a/src/Spout/Common/Exception/EncodingConversionException.php b/src/Spout/Common/Exception/EncodingConversionException.php index 6dcc0a8..aae1e4c 100644 --- a/src/Spout/Common/Exception/EncodingConversionException.php +++ b/src/Spout/Common/Exception/EncodingConversionException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Common\Exception; * Class EncodingConversionException * * @api - * @package Box\Spout\Common\Exception */ class EncodingConversionException extends SpoutException { diff --git a/src/Spout/Common/Exception/IOException.php b/src/Spout/Common/Exception/IOException.php index 4307ca4..1bd269b 100644 --- a/src/Spout/Common/Exception/IOException.php +++ b/src/Spout/Common/Exception/IOException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Common\Exception; * Class IOException * * @api - * @package Box\Spout\Common\Exception */ class IOException extends SpoutException { diff --git a/src/Spout/Common/Exception/InvalidArgumentException.php b/src/Spout/Common/Exception/InvalidArgumentException.php index b1ec05f..6b79a57 100644 --- a/src/Spout/Common/Exception/InvalidArgumentException.php +++ b/src/Spout/Common/Exception/InvalidArgumentException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Common\Exception; * Class InvalidArgumentException * * @api - * @package Box\Spout\Common\Exception */ class InvalidArgumentException extends SpoutException { diff --git a/src/Spout/Common/Exception/SpoutException.php b/src/Spout/Common/Exception/SpoutException.php index aa762d7..2816fcc 100644 --- a/src/Spout/Common/Exception/SpoutException.php +++ b/src/Spout/Common/Exception/SpoutException.php @@ -5,7 +5,6 @@ namespace Box\Spout\Common\Exception; /** * Class SpoutException * - * @package Box\Spout\Common\Exception * @abstract */ abstract class SpoutException extends \Exception diff --git a/src/Spout/Common/Exception/UnsupportedTypeException.php b/src/Spout/Common/Exception/UnsupportedTypeException.php index 65e8500..1281dcd 100644 --- a/src/Spout/Common/Exception/UnsupportedTypeException.php +++ b/src/Spout/Common/Exception/UnsupportedTypeException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Common\Exception; * Class UnsupportedTypeException * * @api - * @package Box\Spout\Common\Exception */ class UnsupportedTypeException extends SpoutException { diff --git a/src/Spout/Common/Helper/EncodingHelper.php b/src/Spout/Common/Helper/EncodingHelper.php index 3a30aaa..9064274 100644 --- a/src/Spout/Common/Helper/EncodingHelper.php +++ b/src/Spout/Common/Helper/EncodingHelper.php @@ -7,8 +7,6 @@ use Box\Spout\Common\Exception\EncodingConversionException; /** * Class EncodingHelper * This class provides helper functions to work with encodings. - * - * @package Box\Spout\Common\Helper */ class EncodingHelper { @@ -97,8 +95,8 @@ class EncodingHelper * * @param string $string Non UTF-8 string to be converted * @param string $sourceEncoding The encoding used to encode the source string - * @return string The converted, UTF-8 string * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed + * @return string The converted, UTF-8 string */ public function attemptConversionToUTF8($string, $sourceEncoding) { @@ -110,8 +108,8 @@ class EncodingHelper * * @param string $string UTF-8 string to be converted * @param string $targetEncoding The encoding the string should be re-encoded into - * @return string The converted string, encoded with the given encoding * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed + * @return string The converted string, encoded with the given encoding */ public function attemptConversionFromUTF8($string, $targetEncoding) { @@ -125,8 +123,8 @@ class EncodingHelper * @param string $string string to be converted * @param string $sourceEncoding The encoding used to encode the source string * @param string $targetEncoding The encoding the string should be re-encoded into - * @return string The converted string, encoded with the given encoding * @throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed + * @return string The converted string, encoded with the given encoding */ protected function attemptConversion($string, $sourceEncoding, $targetEncoding) { @@ -139,7 +137,7 @@ class EncodingHelper if ($this->canUseIconv()) { $convertedString = $this->globalFunctionsHelper->iconv($string, $sourceEncoding, $targetEncoding); - } else if ($this->canUseMbString()) { + } elseif ($this->canUseMbString()) { $convertedString = $this->globalFunctionsHelper->mb_convert_encoding($string, $sourceEncoding, $targetEncoding); } else { throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding is not supported. Please install \"iconv\" or \"PHP Intl\"."); diff --git a/src/Spout/Common/Helper/Escaper/CSV.php b/src/Spout/Common/Helper/Escaper/CSV.php index f572d67..26777e8 100644 --- a/src/Spout/Common/Helper/Escaper/CSV.php +++ b/src/Spout/Common/Helper/Escaper/CSV.php @@ -5,8 +5,6 @@ namespace Box\Spout\Common\Helper\Escaper; /** * Class CSV * Provides functions to escape and unescape data for CSV files - * - * @package Box\Spout\Common\Helper\Escaper */ class CSV implements EscaperInterface { diff --git a/src/Spout/Common/Helper/Escaper/EscaperInterface.php b/src/Spout/Common/Helper/Escaper/EscaperInterface.php index 80613d5..61225b8 100644 --- a/src/Spout/Common/Helper/Escaper/EscaperInterface.php +++ b/src/Spout/Common/Helper/Escaper/EscaperInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Common\Helper\Escaper; /** * Interface EscaperInterface - * - * @package Box\Spout\Common\Helper\Escaper */ interface EscaperInterface { diff --git a/src/Spout/Common/Helper/Escaper/ODS.php b/src/Spout/Common/Helper/Escaper/ODS.php index c232a76..cf7d5be 100644 --- a/src/Spout/Common/Helper/Escaper/ODS.php +++ b/src/Spout/Common/Helper/Escaper/ODS.php @@ -5,8 +5,6 @@ namespace Box\Spout\Common\Helper\Escaper; /** * Class ODS * Provides functions to escape and unescape data for ODS files - * - * @package Box\Spout\Common\Helper\Escaper */ class ODS implements EscaperInterface { diff --git a/src/Spout/Common/Helper/Escaper/XLSX.php b/src/Spout/Common/Helper/Escaper/XLSX.php index 0f305a1..01b71c6 100644 --- a/src/Spout/Common/Helper/Escaper/XLSX.php +++ b/src/Spout/Common/Helper/Escaper/XLSX.php @@ -5,8 +5,6 @@ namespace Box\Spout\Common\Helper\Escaper; /** * Class XLSX * Provides functions to escape and unescape data for XLSX files - * - * @package Box\Spout\Common\Helper\Escaper */ class XLSX implements EscaperInterface { @@ -95,7 +93,7 @@ class XLSX implements EscaperInterface * "\t", "\r" and "\n" don't need to be escaped. * * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) - * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 + * @see https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 * * @return string[] */ @@ -108,7 +106,7 @@ class XLSX implements EscaperInterface $character = chr($charValue); if (preg_match("/{$this->escapableControlCharactersPattern}/", $character)) { $charHexValue = dechex($charValue); - $escapedChar = '_x' . sprintf('%04s' , strtoupper($charHexValue)) . '_'; + $escapedChar = '_x' . sprintf('%04s', strtoupper($charHexValue)) . '_'; $controlCharactersEscapingMap[$escapedChar] = $character; } } @@ -124,7 +122,7 @@ class XLSX implements EscaperInterface * So "\0" -> _x0000_ and "_x0000_" -> _x005F_x0000_. * * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) - * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 + * @see https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 * * @param string $string String to escape * @return string @@ -138,7 +136,7 @@ class XLSX implements EscaperInterface return $escapedString; } - return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function($matches) { + return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function ($matches) { return $this->controlCharactersEscapingReverseMap[$matches[0]]; }, $escapedString); } @@ -162,7 +160,7 @@ class XLSX implements EscaperInterface * So "_x0000_" -> "\0" and "_x005F_x0000_" -> "_x0000_" * * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) - * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 + * @see https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 * * @param string $string String to unescape * @return string diff --git a/src/Spout/Common/Helper/FileSystemHelper.php b/src/Spout/Common/Helper/FileSystemHelper.php index 11428ab..b1bff8f 100644 --- a/src/Spout/Common/Helper/FileSystemHelper.php +++ b/src/Spout/Common/Helper/FileSystemHelper.php @@ -8,8 +8,6 @@ use Box\Spout\Common\Exception\IOException; * Class FileSystemHelper * This class provides helper functions to help with the file system operations * like files/folders creation & deletion - * - * @package Box\Spout\Common\Helper */ class FileSystemHelper implements FileSystemHelperInterface { @@ -29,8 +27,8 @@ class FileSystemHelper implements FileSystemHelperInterface * * @param string $parentFolderPath The parent folder path under which the folder is going to be created * @param string $folderName The name of the folder to create - * @return string Path of the created folder * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder + * @return string Path of the created folder */ public function createFolder($parentFolderPath, $folderName) { @@ -53,8 +51,8 @@ class FileSystemHelper implements FileSystemHelperInterface * @param string $parentFolderPath The parent folder path where the file is going to be created * @param string $fileName The name of the file to create * @param string $fileContents The contents of the file to create - * @return string Path of the created file * @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder + * @return string Path of the created file */ public function createFileWithContents($parentFolderPath, $fileName, $fileContents) { @@ -74,8 +72,8 @@ class FileSystemHelper implements FileSystemHelperInterface * Delete the file at the given path * * @param string $filePath Path of the file to delete - * @return void * @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder + * @return void */ public function deleteFile($filePath) { @@ -90,8 +88,8 @@ class FileSystemHelper implements FileSystemHelperInterface * Delete the folder at the given path as well as all its contents * * @param string $folderPath Path of the folder to delete - * @return void * @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder + * @return void */ public function deleteFolderRecursively($folderPath) { @@ -119,8 +117,8 @@ class FileSystemHelper implements FileSystemHelperInterface * should occur is not inside the base folder. * * @param string $operationFolderPath The path of the folder where the I/O operation should occur - * @return void * @throws \Box\Spout\Common\Exception\IOException If the folder where the I/O operation should occur is not inside the base folder + * @return void */ protected function throwIfOperationNotInBaseFolder($operationFolderPath) { diff --git a/src/Spout/Common/Helper/FileSystemHelperInterface.php b/src/Spout/Common/Helper/FileSystemHelperInterface.php index 7036a05..53c7dd9 100644 --- a/src/Spout/Common/Helper/FileSystemHelperInterface.php +++ b/src/Spout/Common/Helper/FileSystemHelperInterface.php @@ -6,8 +6,6 @@ namespace Box\Spout\Common\Helper; * Class FileSystemHelperInterface * This interface describes helper functions to help with the file system operations * like files/folders creation & deletion - * - * @package Box\Spout\Common\Helper */ interface FileSystemHelperInterface { @@ -16,8 +14,8 @@ interface FileSystemHelperInterface * * @param string $parentFolderPath The parent folder path under which the folder is going to be created * @param string $folderName The name of the folder to create - * @return string Path of the created folder * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder + * @return string Path of the created folder */ public function createFolder($parentFolderPath, $folderName); @@ -28,8 +26,8 @@ interface FileSystemHelperInterface * @param string $parentFolderPath The parent folder path where the file is going to be created * @param string $fileName The name of the file to create * @param string $fileContents The contents of the file to create - * @return string Path of the created file * @throws \Box\Spout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder + * @return string Path of the created file */ public function createFileWithContents($parentFolderPath, $fileName, $fileContents); @@ -37,8 +35,8 @@ interface FileSystemHelperInterface * Delete the file at the given path * * @param string $filePath Path of the file to delete - * @return void * @throws \Box\Spout\Common\Exception\IOException If the file path is not inside of the base folder + * @return void */ public function deleteFile($filePath); @@ -46,8 +44,8 @@ interface FileSystemHelperInterface * Delete the folder at the given path as well as all its contents * * @param string $folderPath Path of the folder to delete - * @return void * @throws \Box\Spout\Common\Exception\IOException If the folder path is not inside of the base folder + * @return void */ public function deleteFolderRecursively($folderPath); } diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index bd1a0bd..608854a 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -7,8 +7,6 @@ namespace Box\Spout\Common\Helper; * This class wraps global functions to facilitate testing * * @codeCoverageIgnore - * - * @package Box\Spout\Common\Helper */ class GlobalFunctionsHelper { @@ -165,6 +163,7 @@ class GlobalFunctionsHelper public function file_get_contents($filePath) { $realFilePath = $this->convertToUseRealPath($filePath); + return file_get_contents($realFilePath); } diff --git a/src/Spout/Common/Helper/StringHelper.php b/src/Spout/Common/Helper/StringHelper.php index 273104e..c698815 100644 --- a/src/Spout/Common/Helper/StringHelper.php +++ b/src/Spout/Common/Helper/StringHelper.php @@ -7,8 +7,6 @@ namespace Box\Spout\Common\Helper; * This class provides helper functions to work with strings and multibyte strings. * * @codeCoverageIgnore - * - * @package Box\Spout\Common\Helper */ class StringHelper { @@ -50,6 +48,7 @@ class StringHelper public function getCharFirstOccurrencePosition($char, $string) { $position = $this->hasMbstringSupport ? mb_strpos($string, $char) : strpos($string, $char); + return ($position !== false) ? $position : -1; } @@ -66,6 +65,7 @@ class StringHelper public function getCharLastOccurrencePosition($char, $string) { $position = $this->hasMbstringSupport ? mb_strrpos($string, $char) : strrpos($string, $char); + return ($position !== false) ? $position : -1; } } diff --git a/src/Spout/Common/Manager/OptionsManagerAbstract.php b/src/Spout/Common/Manager/OptionsManagerAbstract.php index e88eb94..20eb14e 100644 --- a/src/Spout/Common/Manager/OptionsManagerAbstract.php +++ b/src/Spout/Common/Manager/OptionsManagerAbstract.php @@ -4,8 +4,6 @@ namespace Box\Spout\Common\Manager; /** * Class OptionsManager - * - * @package Box\Spout\Common\Manager */ abstract class OptionsManagerAbstract implements OptionsManagerInterface { diff --git a/src/Spout/Common/Manager/OptionsManagerInterface.php b/src/Spout/Common/Manager/OptionsManagerInterface.php index 4789b93..21fea0c 100644 --- a/src/Spout/Common/Manager/OptionsManagerInterface.php +++ b/src/Spout/Common/Manager/OptionsManagerInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Common\Manager; /** * Interface OptionsManagerInterface - * - * @package Box\Spout\Common\Manager */ interface OptionsManagerInterface { diff --git a/src/Spout/Reader/CSV/Creator/EntityFactory.php b/src/Spout/Reader/CSV/Creator/EntityFactory.php index 545b79b..a305ef9 100644 --- a/src/Spout/Reader/CSV/Creator/EntityFactory.php +++ b/src/Spout/Reader/CSV/Creator/EntityFactory.php @@ -13,8 +13,6 @@ use Box\Spout\Reader\CSV\SheetIterator; /** * Class EntityFactory * Factory to create entities - * - * @package Box\Spout\Reader\CSV\Creator */ class EntityFactory implements EntityFactoryInterface { @@ -61,6 +59,7 @@ class EntityFactory implements EntityFactoryInterface private function createRowIterator($filePointer, $optionsManager, $globalFunctionsHelper) { $encodingHelper = $this->helperFactory->createEncodingHelper($globalFunctionsHelper); + return new RowIterator($filePointer, $optionsManager, $encodingHelper, $globalFunctionsHelper); } } diff --git a/src/Spout/Reader/CSV/Manager/OptionsManager.php b/src/Spout/Reader/CSV/Manager/OptionsManager.php index 267ff77..befefe3 100644 --- a/src/Spout/Reader/CSV/Manager/OptionsManager.php +++ b/src/Spout/Reader/CSV/Manager/OptionsManager.php @@ -9,13 +9,11 @@ use Box\Spout\Reader\Common\Entity\Options; /** * Class OptionsManager * CSV Reader options manager - * - * @package Box\Spout\Reader\CSV\Manager */ class OptionsManager extends OptionsManagerAbstract { /** - * @inheritdoc + * {@inheritdoc} */ protected function getSupportedOptions() { @@ -29,7 +27,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function setDefaultOptions() { diff --git a/src/Spout/Reader/CSV/Reader.php b/src/Spout/Reader/CSV/Reader.php index 89a3cf1..ec43405 100644 --- a/src/Spout/Reader/CSV/Reader.php +++ b/src/Spout/Reader/CSV/Reader.php @@ -2,16 +2,14 @@ namespace Box\Spout\Reader\CSV; +use Box\Spout\Common\Exception\IOException; use Box\Spout\Reader\Common\Entity\Options; use Box\Spout\Reader\CSV\Creator\EntityFactory; use Box\Spout\Reader\ReaderAbstract; -use Box\Spout\Common\Exception\IOException; /** * Class Reader * This class provides support to read data from a CSV file. - * - * @package Box\Spout\Reader\CSV */ class Reader extends ReaderAbstract { @@ -34,6 +32,7 @@ class Reader extends ReaderAbstract public function setFieldDelimiter($fieldDelimiter) { $this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter); + return $this; } @@ -47,6 +46,7 @@ class Reader extends ReaderAbstract public function setFieldEnclosure($fieldEnclosure) { $this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure); + return $this; } @@ -60,6 +60,7 @@ class Reader extends ReaderAbstract public function setEncoding($encoding) { $this->optionsManager->setOption(Options::ENCODING, $encoding); + return $this; } @@ -78,8 +79,8 @@ class Reader extends ReaderAbstract * If setEncoding() was not called, it assumes that the file is encoded in UTF-8. * * @param string $filePath Path of the CSV file to be read - * @return void * @throws \Box\Spout\Common\Exception\IOException + * @return void */ protected function openReader($filePath) { @@ -111,7 +112,6 @@ class Reader extends ReaderAbstract return $this->sheetIterator; } - /** * Closes the reader. To be used after reading the file. * diff --git a/src/Spout/Reader/CSV/RowIterator.php b/src/Spout/Reader/CSV/RowIterator.php index 390b3d4..d1ac3f6 100644 --- a/src/Spout/Reader/CSV/RowIterator.php +++ b/src/Spout/Reader/CSV/RowIterator.php @@ -2,17 +2,13 @@ namespace Box\Spout\Reader\CSV; -use Box\Spout\Common\Creator\HelperFactory; -use Box\Spout\Reader\Common\Entity\Options; -use Box\Spout\Reader\CSV\Creator\EntityFactory; -use Box\Spout\Reader\IteratorInterface; use Box\Spout\Common\Helper\EncodingHelper; +use Box\Spout\Reader\Common\Entity\Options; +use Box\Spout\Reader\IteratorInterface; /** * Class RowIterator * Iterate over CSV rows. - * - * @package Box\Spout\Reader\CSV */ class RowIterator implements IteratorInterface { @@ -28,7 +24,7 @@ class RowIterator implements IteratorInterface protected $numReadRows = 0; /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */ - protected $rowDataBuffer = null; + protected $rowDataBuffer; /** @var bool Indicates whether all rows have been read */ protected $hasReachedEndOfFile = false; @@ -70,7 +66,7 @@ class RowIterator implements IteratorInterface /** * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * * @return void */ @@ -100,7 +96,7 @@ class RowIterator implements IteratorInterface /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -111,10 +107,10 @@ class RowIterator implements IteratorInterface /** * Move forward to next element. Reads data for the next unprocessed row. - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * - * @return void * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 + * @return void */ public function next() { @@ -126,8 +122,8 @@ class RowIterator implements IteratorInterface } /** - * @return void * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 + * @return void */ protected function readDataForNextRow() { @@ -167,8 +163,8 @@ class RowIterator implements IteratorInterface * As fgetcsv() does not manage correctly encoding for non UTF-8 data, * we remove manually whitespace with ltrim or rtrim (depending on the order of the bytes) * - * @return array|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read * @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8 + * @return array|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read */ protected function getNextUTF8EncodedRow() { @@ -178,7 +174,7 @@ class RowIterator implements IteratorInterface } foreach ($encodedRowData as $cellIndex => $cellValue) { - switch($this->encoding) { + switch ($this->encoding) { case EncodingHelper::ENCODING_UTF16_LE: case EncodingHelper::ENCODING_UTF32_LE: // remove whitespace from the beginning of a string as fgetcsv() add extra whitespace when it try to explode non UTF-8 data @@ -209,7 +205,7 @@ class RowIterator implements IteratorInterface /** * Return the current element from the buffer - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return array|null */ @@ -220,7 +216,7 @@ class RowIterator implements IteratorInterface /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ diff --git a/src/Spout/Reader/CSV/Sheet.php b/src/Spout/Reader/CSV/Sheet.php index 15c1cf7..3453ffb 100644 --- a/src/Spout/Reader/CSV/Sheet.php +++ b/src/Spout/Reader/CSV/Sheet.php @@ -2,13 +2,10 @@ namespace Box\Spout\Reader\CSV; -use Box\Spout\Reader\CSV\Creator\EntityFactory; use Box\Spout\Reader\SheetInterface; /** * Class Sheet - * - * @package Box\Spout\Reader\CSV */ class Sheet implements SheetInterface { diff --git a/src/Spout/Reader/CSV/SheetIterator.php b/src/Spout/Reader/CSV/SheetIterator.php index 254d625..69eb58a 100644 --- a/src/Spout/Reader/CSV/SheetIterator.php +++ b/src/Spout/Reader/CSV/SheetIterator.php @@ -2,14 +2,11 @@ namespace Box\Spout\Reader\CSV; -use Box\Spout\Reader\CSV\Creator\EntityFactory; use Box\Spout\Reader\IteratorInterface; /** * Class SheetIterator * Iterate over CSV unique "sheet". - * - * @package Box\Spout\Reader\CSV */ class SheetIterator implements IteratorInterface { @@ -29,7 +26,7 @@ class SheetIterator implements IteratorInterface /** * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * * @return void */ @@ -40,7 +37,7 @@ class SheetIterator implements IteratorInterface /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -51,7 +48,7 @@ class SheetIterator implements IteratorInterface /** * Move forward to next element - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * * @return void */ @@ -62,7 +59,7 @@ class SheetIterator implements IteratorInterface /** * Return the current element - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return \Box\Spout\Reader\CSV\Sheet */ @@ -73,7 +70,7 @@ class SheetIterator implements IteratorInterface /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ diff --git a/src/Spout/Reader/Common/Creator/EntityFactoryInterface.php b/src/Spout/Reader/Common/Creator/EntityFactoryInterface.php index 184a72c..78b7754 100644 --- a/src/Spout/Reader/Common/Creator/EntityFactoryInterface.php +++ b/src/Spout/Reader/Common/Creator/EntityFactoryInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader\Common\Creator; /** * Interface EntityFactoryInterface - * - * @package Box\Spout\Reader\Common\Creator */ interface EntityFactoryInterface { diff --git a/src/Spout/Reader/Common/Entity/Options.php b/src/Spout/Reader/Common/Entity/Options.php index 4178d03..615160d 100644 --- a/src/Spout/Reader/Common/Entity/Options.php +++ b/src/Spout/Reader/Common/Entity/Options.php @@ -5,8 +5,6 @@ namespace Box\Spout\Reader\Common\Entity; /** * Class Options * Readers' options holder - * - * @package Box\Spout\Reader\Common\Entity */ abstract class Options { diff --git a/src/Spout/Reader/Common/ReaderOptions.php b/src/Spout/Reader/Common/ReaderOptions.php index 4ab7a07..1540b1c 100644 --- a/src/Spout/Reader/Common/ReaderOptions.php +++ b/src/Spout/Reader/Common/ReaderOptions.php @@ -5,8 +5,6 @@ namespace Box\Spout\Reader\Common; /** * Class ReaderOptions * Readers' common options - * - * @package Box\Spout\Reader\Common */ class ReaderOptions { @@ -33,6 +31,7 @@ class ReaderOptions public function setShouldFormatDates($shouldFormatDates) { $this->shouldFormatDates = $shouldFormatDates; + return $this; } @@ -53,6 +52,7 @@ class ReaderOptions public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows) { $this->shouldPreserveEmptyRows = $shouldPreserveEmptyRows; + return $this; } } diff --git a/src/Spout/Reader/Common/XMLProcessor.php b/src/Spout/Reader/Common/XMLProcessor.php index d8a1da8..3b2d848 100644 --- a/src/Spout/Reader/Common/XMLProcessor.php +++ b/src/Spout/Reader/Common/XMLProcessor.php @@ -7,8 +7,6 @@ use Box\Spout\Reader\Wrapper\XMLReader; /** * Class XMLProcessor * Helps process XML files - * - * @package Box\Spout\Reader\Common */ class XMLProcessor { @@ -24,14 +22,12 @@ class XMLProcessor const PROCESSING_CONTINUE = 1; const PROCESSING_STOP = 2; - /** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */ protected $xmlReader; /** @var array Registered callbacks */ private $callbacks = []; - /** * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object */ @@ -90,8 +86,8 @@ class XMLProcessor * Resumes the reading of the XML file where it was left off. * Stops whenever a callback indicates that reading should stop or at the end of the file. * - * @return void * @throws \Box\Spout\Reader\Exception\XMLProcessingException + * @return void */ public function readUntilStopped() { diff --git a/src/Spout/Reader/Exception/IteratorNotRewindableException.php b/src/Spout/Reader/Exception/IteratorNotRewindableException.php index a030c12..cb6cb2a 100644 --- a/src/Spout/Reader/Exception/IteratorNotRewindableException.php +++ b/src/Spout/Reader/Exception/IteratorNotRewindableException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Reader\Exception; * Class IteratorNotRewindableException * * @api - * @package Box\Spout\Reader\Exception */ class IteratorNotRewindableException extends ReaderException { diff --git a/src/Spout/Reader/Exception/NoSheetsFoundException.php b/src/Spout/Reader/Exception/NoSheetsFoundException.php index 38d8772..71c6655 100644 --- a/src/Spout/Reader/Exception/NoSheetsFoundException.php +++ b/src/Spout/Reader/Exception/NoSheetsFoundException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Reader\Exception; * Class NoSheetsFoundException * * @api - * @package Box\Spout\Reader\Exception */ class NoSheetsFoundException extends ReaderException { diff --git a/src/Spout/Reader/Exception/ReaderException.php b/src/Spout/Reader/Exception/ReaderException.php index ee9ca79..4b38192 100644 --- a/src/Spout/Reader/Exception/ReaderException.php +++ b/src/Spout/Reader/Exception/ReaderException.php @@ -7,7 +7,6 @@ use Box\Spout\Common\Exception\SpoutException; /** * Class ReaderException * - * @package Box\Spout\Reader\Exception * @abstract */ abstract class ReaderException extends SpoutException diff --git a/src/Spout/Reader/Exception/ReaderNotOpenedException.php b/src/Spout/Reader/Exception/ReaderNotOpenedException.php index 8f94de3..9418d9a 100644 --- a/src/Spout/Reader/Exception/ReaderNotOpenedException.php +++ b/src/Spout/Reader/Exception/ReaderNotOpenedException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Reader\Exception; * Class ReaderNotOpenedException * * @api - * @package Box\Spout\Reader\Exception */ class ReaderNotOpenedException extends ReaderException { diff --git a/src/Spout/Reader/Exception/SharedStringNotFoundException.php b/src/Spout/Reader/Exception/SharedStringNotFoundException.php index b494612..106c566 100644 --- a/src/Spout/Reader/Exception/SharedStringNotFoundException.php +++ b/src/Spout/Reader/Exception/SharedStringNotFoundException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Reader\Exception; * Class SharedStringNotFoundException * * @api - * @package Box\Spout\Reader\Exception */ class SharedStringNotFoundException extends ReaderException { diff --git a/src/Spout/Reader/Exception/XMLProcessingException.php b/src/Spout/Reader/Exception/XMLProcessingException.php index 70f630b..ee2602b 100644 --- a/src/Spout/Reader/Exception/XMLProcessingException.php +++ b/src/Spout/Reader/Exception/XMLProcessingException.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader\Exception; /** * Class XMLProcessingException - * - * @package Box\Spout\Reader\Exception */ class XMLProcessingException extends ReaderException { diff --git a/src/Spout/Reader/IteratorInterface.php b/src/Spout/Reader/IteratorInterface.php index 7d58e28..4a9305d 100644 --- a/src/Spout/Reader/IteratorInterface.php +++ b/src/Spout/Reader/IteratorInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader; /** * Interface IteratorInterface - * - * @package Box\Spout\Reader */ interface IteratorInterface extends \Iterator { diff --git a/src/Spout/Reader/ODS/Creator/EntityFactory.php b/src/Spout/Reader/ODS/Creator/EntityFactory.php index 359de40..3af756a 100644 --- a/src/Spout/Reader/ODS/Creator/EntityFactory.php +++ b/src/Spout/Reader/ODS/Creator/EntityFactory.php @@ -2,8 +2,6 @@ namespace Box\Spout\Reader\ODS\Creator; -use Box\Spout\Common\Helper\GlobalFunctionsHelper; -use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Reader\Common\Creator\EntityFactoryInterface; use Box\Spout\Reader\Common\Entity\Options; use Box\Spout\Reader\Common\XMLProcessor; @@ -15,8 +13,6 @@ use Box\Spout\Reader\Wrapper\XMLReader; /** * Class EntityFactory * Factory to create entities - * - * @package Box\Spout\Reader\ODS\Creator */ class EntityFactory implements EntityFactoryInterface { diff --git a/src/Spout/Reader/ODS/Creator/HelperFactory.php b/src/Spout/Reader/ODS/Creator/HelperFactory.php index 0109498..6f128bd 100644 --- a/src/Spout/Reader/ODS/Creator/HelperFactory.php +++ b/src/Spout/Reader/ODS/Creator/HelperFactory.php @@ -5,12 +5,9 @@ namespace Box\Spout\Reader\ODS\Creator; use Box\Spout\Reader\ODS\Helper\CellValueFormatter; use Box\Spout\Reader\ODS\Helper\SettingsHelper; - /** * Class EntityFactory * Factory to create helpers - * - * @package Box\Spout\Reader\ODS\Creator */ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory { @@ -21,6 +18,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory public function createCellValueFormatter($shouldFormatDates) { $escaper = $this->createStringsEscaper(); + return new CellValueFormatter($shouldFormatDates, $escaper); } @@ -38,7 +36,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory */ public function createStringsEscaper() { - /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ + /* @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ return new \Box\Spout\Common\Helper\Escaper\ODS(); } } diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index 359fea7..87a2909 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -5,8 +5,6 @@ namespace Box\Spout\Reader\ODS\Helper; /** * Class CellValueFormatter * This class provides helper functions to format cell values - * - * @package Box\Spout\Reader\ODS\Helper */ class CellValueFormatter { @@ -100,11 +98,11 @@ class CellValueFormatter foreach ($pNode->childNodes as $childNode) { if ($childNode instanceof \DOMText) { $currentPValue .= $childNode->nodeValue; - } else if ($childNode->nodeName === self::XML_NODE_S) { + } elseif ($childNode->nodeName === self::XML_NODE_S) { $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C); - $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1; + $numSpaces = (!empty($spaceAttribute)) ? (int) $spaceAttribute : 1; $currentPValue .= str_repeat(' ', $numSpaces); - } else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) { + } elseif ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) { $currentPValue .= $childNode->nodeValue; } } @@ -114,6 +112,7 @@ class CellValueFormatter $escapedCellValue = implode("\n", $pNodeValues); $cellValue = $this->escaper->unescape($escapedCellValue); + return $cellValue; } @@ -126,9 +125,11 @@ class CellValueFormatter protected function formatFloatCellValue($node) { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_VALUE); - $nodeIntValue = intval($nodeValue); + + $nodeIntValue = (int) $nodeValue; $nodeFloatValue = (float) $nodeValue; $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue; + return $cellValue; } @@ -141,6 +142,7 @@ class CellValueFormatter protected function formatBooleanCellValue($node) { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_BOOLEAN_VALUE); + return (bool) $nodeValue; } diff --git a/src/Spout/Reader/ODS/Helper/SettingsHelper.php b/src/Spout/Reader/ODS/Helper/SettingsHelper.php index a2faf48..9a2b8f7 100644 --- a/src/Spout/Reader/ODS/Helper/SettingsHelper.php +++ b/src/Spout/Reader/ODS/Helper/SettingsHelper.php @@ -4,13 +4,10 @@ namespace Box\Spout\Reader\ODS\Helper; use Box\Spout\Reader\Exception\XMLProcessingException; use Box\Spout\Reader\ODS\Creator\EntityFactory; -use Box\Spout\Reader\Wrapper\XMLReader; /** * Class SettingsHelper * This class provides helper functions to extract data from the "settings.xml" file. - * - * @package Box\Spout\Reader\ODS\Helper */ class SettingsHelper { diff --git a/src/Spout/Reader/ODS/Manager/OptionsManager.php b/src/Spout/Reader/ODS/Manager/OptionsManager.php index d94740e..102eccb 100644 --- a/src/Spout/Reader/ODS/Manager/OptionsManager.php +++ b/src/Spout/Reader/ODS/Manager/OptionsManager.php @@ -8,13 +8,11 @@ use Box\Spout\Reader\Common\Entity\Options; /** * Class OptionsManager * ODS Reader options manager - * - * @package Box\Spout\Reader\ODS\Manager */ class OptionsManager extends OptionsManagerAbstract { /** - * @inheritdoc + * {@inheritdoc} */ protected function getSupportedOptions() { @@ -25,7 +23,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function setDefaultOptions() { diff --git a/src/Spout/Reader/ODS/Reader.php b/src/Spout/Reader/ODS/Reader.php index 0d85c6c..2e8ba28 100644 --- a/src/Spout/Reader/ODS/Reader.php +++ b/src/Spout/Reader/ODS/Reader.php @@ -9,8 +9,6 @@ use Box\Spout\Reader\ReaderAbstract; /** * Class Reader * This class provides support to read data from a ODS file - * - * @package Box\Spout\Reader\ODS */ class Reader extends ReaderAbstract { @@ -34,9 +32,9 @@ class Reader extends ReaderAbstract * Opens the file at the given file path to make it ready to be read. * * @param string $filePath Path of the file to be read - * @return void * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file + * @return void */ protected function openReader($filePath) { diff --git a/src/Spout/Reader/ODS/RowIterator.php b/src/Spout/Reader/ODS/RowIterator.php index 7472c82..6af8a8d 100644 --- a/src/Spout/Reader/ODS/RowIterator.php +++ b/src/Spout/Reader/ODS/RowIterator.php @@ -4,19 +4,15 @@ namespace Box\Spout\Reader\ODS; use Box\Spout\Common\Exception\IOException; use Box\Spout\Reader\Common\Entity\Options; +use Box\Spout\Reader\Common\XMLProcessor; use Box\Spout\Reader\Exception\IteratorNotRewindableException; use Box\Spout\Reader\Exception\XMLProcessingException; use Box\Spout\Reader\IteratorInterface; -use Box\Spout\Reader\ODS\Creator\EntityFactory; -use Box\Spout\Reader\ODS\Creator\HelperFactory; use Box\Spout\Reader\ODS\Helper\CellValueFormatter; use Box\Spout\Reader\Wrapper\XMLReader; -use Box\Spout\Reader\Common\XMLProcessor; /** * Class RowIterator - * - * @package Box\Spout\Reader\ODS */ class RowIterator implements IteratorInterface { @@ -49,7 +45,7 @@ class RowIterator implements IteratorInterface protected $currentlyProcessedRowData = []; /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */ - protected $rowDataBuffer = null; + protected $rowDataBuffer; /** @var bool Indicates whether all rows have been read */ protected $hasReachedEndOfFile = false; @@ -61,7 +57,7 @@ class RowIterator implements IteratorInterface protected $nextRowIndexToBeProcessed = 1; /** @var mixed|null Value of the last processed cell (because when reading cell at column N+1, cell N is processed) */ - protected $lastProcessedCellValue = null; + protected $lastProcessedCellValue; /** @var int Number of times the last processed row should be repeated */ protected $numRowsRepeated = 1; @@ -72,7 +68,6 @@ class RowIterator implements IteratorInterface /** @var bool Whether at least one cell has been read for the row currently being processed */ protected $hasAlreadyReadOneCellInCurrentRow = false; - /** * @param XMLReader $xmlReader XML Reader, positioned on the "" element * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager @@ -96,10 +91,10 @@ class RowIterator implements IteratorInterface /** * Rewind the Iterator to the first element. * NOTE: It can only be done once, as it is not possible to read an XML file backwards. - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * - * @return void * @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once + * @return void */ public function rewind() { @@ -121,7 +116,7 @@ class RowIterator implements IteratorInterface /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -132,11 +127,11 @@ class RowIterator implements IteratorInterface /** * Move forward to next element. Empty rows will be skipped. - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * - * @return void * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML + * @return void */ public function next() { @@ -167,9 +162,9 @@ class RowIterator implements IteratorInterface } /** - * @return void * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML + * @return void */ protected function readDataForNextRow() { @@ -280,7 +275,8 @@ class RowIterator implements IteratorInterface protected function getNumRowsRepeatedForCurrentNode($xmlReader) { $numRowsRepeated = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_ROWS_REPEATED); - return ($numRowsRepeated !== null) ? intval($numRowsRepeated) : 1; + + return ($numRowsRepeated !== null) ? (int) $numRowsRepeated : 1; } /** @@ -290,7 +286,8 @@ class RowIterator implements IteratorInterface protected function getNumColumnsRepeatedForCurrentNode($xmlReader) { $numColumnsRepeated = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_COLUMNS_REPEATED); - return ($numColumnsRepeated !== null) ? intval($numColumnsRepeated) : 1; + + return ($numColumnsRepeated !== null) ? (int) $numColumnsRepeated : 1; } /** @@ -324,7 +321,7 @@ class RowIterator implements IteratorInterface /** * Return the current element, from the buffer. - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return array|null */ @@ -335,7 +332,7 @@ class RowIterator implements IteratorInterface /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ @@ -344,7 +341,6 @@ class RowIterator implements IteratorInterface return $this->lastRowIndexProcessed; } - /** * Cleans up what was created to iterate over the object. * diff --git a/src/Spout/Reader/ODS/Sheet.php b/src/Spout/Reader/ODS/Sheet.php index b22e405..31879c8 100644 --- a/src/Spout/Reader/ODS/Sheet.php +++ b/src/Spout/Reader/ODS/Sheet.php @@ -2,15 +2,11 @@ namespace Box\Spout\Reader\ODS; -use Box\Spout\Reader\ODS\Creator\EntityFactory; use Box\Spout\Reader\SheetInterface; -use Box\Spout\Reader\Wrapper\XMLReader; /** * Class Sheet * Represents a sheet within a ODS file - * - * @package Box\Spout\Reader\ODS */ class Sheet implements SheetInterface { diff --git a/src/Spout/Reader/ODS/SheetIterator.php b/src/Spout/Reader/ODS/SheetIterator.php index a18dc9f..3c6dd4e 100644 --- a/src/Spout/Reader/ODS/SheetIterator.php +++ b/src/Spout/Reader/ODS/SheetIterator.php @@ -6,15 +6,12 @@ use Box\Spout\Common\Exception\IOException; use Box\Spout\Reader\Exception\XMLProcessingException; use Box\Spout\Reader\IteratorInterface; use Box\Spout\Reader\ODS\Creator\EntityFactory; -use Box\Spout\Reader\ODS\Creator\HelperFactory; use Box\Spout\Reader\ODS\Helper\SettingsHelper; use Box\Spout\Reader\Wrapper\XMLReader; /** * Class SheetIterator * Iterate over ODS sheet. - * - * @package Box\Spout\Reader\ODS */ class SheetIterator implements IteratorInterface { @@ -67,10 +64,10 @@ class SheetIterator implements IteratorInterface /** * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * - * @return void * @throws \Box\Spout\Common\Exception\IOException If unable to open the XML file containing sheets' data + * @return void */ public function rewind() { @@ -84,15 +81,15 @@ class SheetIterator implements IteratorInterface try { $this->hasFoundSheet = $this->xmlReader->readUntilNodeFound(self::XML_NODE_TABLE); } catch (XMLProcessingException $exception) { - throw new IOException("The content.xml file is invalid and cannot be read. [{$exception->getMessage()}]"); - } + throw new IOException("The content.xml file is invalid and cannot be read. [{$exception->getMessage()}]"); + } $this->currentSheetIndex = 0; } /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -103,7 +100,7 @@ class SheetIterator implements IteratorInterface /** * Move forward to next element - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * * @return void */ @@ -118,7 +115,7 @@ class SheetIterator implements IteratorInterface /** * Return the current element - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return \Box\Spout\Reader\ODS\Sheet */ @@ -151,7 +148,7 @@ class SheetIterator implements IteratorInterface /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ diff --git a/src/Spout/Reader/ReaderAbstract.php b/src/Spout/Reader/ReaderAbstract.php index 4de55a1..e8ee5f0 100644 --- a/src/Spout/Reader/ReaderAbstract.php +++ b/src/Spout/Reader/ReaderAbstract.php @@ -12,7 +12,6 @@ use Box\Spout\Reader\Exception\ReaderNotOpenedException; /** * Class ReaderAbstract * - * @package Box\Spout\Reader * @abstract */ abstract class ReaderAbstract implements ReaderInterface @@ -66,8 +65,8 @@ abstract class ReaderAbstract implements ReaderInterface public function __construct( OptionsManagerInterface $optionsManager, GlobalFunctionsHelper $globalFunctionsHelper, - EntityFactoryInterface $entityFactory) - { + EntityFactoryInterface $entityFactory + ) { $this->optionsManager = $optionsManager; $this->globalFunctionsHelper = $globalFunctionsHelper; $this->entityFactory = $entityFactory; @@ -83,6 +82,7 @@ abstract class ReaderAbstract implements ReaderInterface public function setShouldFormatDates($shouldFormatDates) { $this->optionsManager->setOption(Options::SHOULD_FORMAT_DATES, $shouldFormatDates); + return $this; } @@ -96,6 +96,7 @@ abstract class ReaderAbstract implements ReaderInterface public function setShouldPreserveEmptyRows($shouldPreserveEmptyRows) { $this->optionsManager->setOption(Options::SHOULD_PRESERVE_EMPTY_ROWS, $shouldPreserveEmptyRows); + return $this; } @@ -105,8 +106,8 @@ abstract class ReaderAbstract implements ReaderInterface * * @api * @param string $filePath Path of the file to be read - * @return void * @throws \Box\Spout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted + * @return void */ public function open($filePath) { @@ -118,7 +119,8 @@ abstract class ReaderAbstract implements ReaderInterface // we skip the checks if the provided file path points to a PHP stream if (!$this->globalFunctionsHelper->file_exists($filePath)) { throw new IOException("Could not open $filePath for reading! File does not exist."); - } else if (!$this->globalFunctionsHelper->is_readable($filePath)) { + } + if (!$this->globalFunctionsHelper->is_readable($filePath)) { throw new IOException("Could not open $filePath for reading! File is not readable."); } } @@ -162,6 +164,7 @@ abstract class ReaderAbstract implements ReaderInterface if (preg_match('/^(\w+):\/\//', $filePath, $matches)) { $streamScheme = $matches[1]; } + return $streamScheme; } @@ -188,6 +191,7 @@ abstract class ReaderAbstract implements ReaderInterface protected function isSupportedStreamWrapper($filePath) { $streamScheme = $this->getStreamWrapperScheme($filePath); + return ($streamScheme !== null) ? in_array($streamScheme, $this->globalFunctionsHelper->stream_get_wrappers()) : true; @@ -202,6 +206,7 @@ abstract class ReaderAbstract implements ReaderInterface protected function isPhpStream($filePath) { $streamScheme = $this->getStreamWrapperScheme($filePath); + return ($streamScheme === 'php'); } @@ -209,8 +214,8 @@ abstract class ReaderAbstract implements ReaderInterface * Returns an iterator to iterate over sheets. * * @api - * @return \Iterator To iterate over sheets * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader + * @return \Iterator To iterate over sheets */ public function getSheetIterator() { diff --git a/src/Spout/Reader/ReaderFactory.php b/src/Spout/Reader/ReaderFactory.php index de39030..fb68f49 100644 --- a/src/Spout/Reader/ReaderFactory.php +++ b/src/Spout/Reader/ReaderFactory.php @@ -11,8 +11,6 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory; * Class ReaderFactory * This factory is used to create readers, based on the type of the file to be read. * It supports CSV and XLSX formats. - * - * @package Box\Spout\Reader */ class ReaderFactory { @@ -21,12 +19,11 @@ class ReaderFactory * * @api * @param string $readerType Type of the reader to instantiate - * @return ReaderInterface * @throws \Box\Spout\Common\Exception\UnsupportedTypeException + * @return ReaderInterface */ public static function create($readerType) { - switch ($readerType) { case Type::CSV: return self::getCSVReader(); case Type::XLSX: return self::getXLSXReader(); diff --git a/src/Spout/Reader/ReaderInterface.php b/src/Spout/Reader/ReaderInterface.php index 8ecde30..74bcc4a 100644 --- a/src/Spout/Reader/ReaderInterface.php +++ b/src/Spout/Reader/ReaderInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader; /** * Interface ReaderInterface - * - * @package Box\Spout\Reader */ interface ReaderInterface { @@ -14,16 +12,16 @@ interface ReaderInterface * that the file exists and is readable. * * @param string $filePath Path of the file to be read - * @return void * @throws \Box\Spout\Common\Exception\IOException + * @return void */ public function open($filePath); /** * Returns an iterator to iterate over sheets. * - * @return \Iterator To iterate over sheets * @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader + * @return \Iterator To iterate over sheets */ public function getSheetIterator(); diff --git a/src/Spout/Reader/SheetInterface.php b/src/Spout/Reader/SheetInterface.php index 4f3eea0..d0a115d 100644 --- a/src/Spout/Reader/SheetInterface.php +++ b/src/Spout/Reader/SheetInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader; /** * Interface SheetInterface - * - * @package Box\Spout\Reader */ interface SheetInterface { diff --git a/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php b/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php index 8b4464a..7047a94 100644 --- a/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php +++ b/src/Spout/Reader/Wrapper/XMLInternalErrorsHelper.php @@ -6,8 +6,6 @@ use Box\Spout\Reader\Exception\XMLProcessingException; /** * Trait XMLInternalErrorsHelper - * - * @package Box\Spout\Reader\Wrapper */ trait XMLInternalErrorsHelper { @@ -30,8 +28,8 @@ trait XMLInternalErrorsHelper * Throws an XMLProcessingException if an error occured. * It also always resets the "libxml_use_internal_errors" setting back to its initial value. * - * @return void * @throws \Box\Spout\Reader\Exception\XMLProcessingException + * @return void */ protected function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured() { @@ -57,7 +55,7 @@ trait XMLInternalErrorsHelper * Returns the error message for the last XML error that occured. * @see libxml_get_last_error * - * @return String|null Last XML error message or null if no error + * @return string|null Last XML error message or null if no error */ private function getLastXMLErrorMessage() { @@ -78,5 +76,4 @@ trait XMLInternalErrorsHelper { libxml_use_internal_errors($this->initialUseInternalErrorsValue); } - } diff --git a/src/Spout/Reader/Wrapper/XMLReader.php b/src/Spout/Reader/Wrapper/XMLReader.php index 7f81b43..c50f5c0 100644 --- a/src/Spout/Reader/Wrapper/XMLReader.php +++ b/src/Spout/Reader/Wrapper/XMLReader.php @@ -2,13 +2,10 @@ namespace Box\Spout\Reader\Wrapper; - /** * Class XMLReader * Wrapper around the built-in XMLReader * @see \XMLReader - * - * @package Box\Spout\Reader\Wrapper */ class XMLReader extends \XMLReader { @@ -80,8 +77,8 @@ class XMLReader extends \XMLReader * Move to next node in document * @see \XMLReader::read * - * @return bool TRUE on success or FALSE on failure * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred + * @return bool TRUE on success or FALSE on failure */ public function read() { @@ -98,8 +95,8 @@ class XMLReader extends \XMLReader * Read until the element with the given name is found, or the end of the file. * * @param string $nodeName Name of the node to find - * @return bool TRUE on success or FALSE on failure * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred + * @return bool TRUE on success or FALSE on failure */ public function readUntilNodeFound($nodeName) { @@ -116,8 +113,8 @@ class XMLReader extends \XMLReader * @see \XMLReader::next * * @param string|null $localName The name of the next node to move to - * @return bool TRUE on success or FALSE on failure * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred + * @return bool TRUE on success or FALSE on failure */ public function next($localName = null) { @@ -136,7 +133,7 @@ class XMLReader extends \XMLReader */ public function isPositionedOnStartingNode($nodeName) { - return $this->isPositionedOnNode($nodeName, XMLReader::ELEMENT); + return $this->isPositionedOnNode($nodeName, self::ELEMENT); } /** @@ -145,7 +142,7 @@ class XMLReader extends \XMLReader */ public function isPositionedOnEndingNode($nodeName) { - return $this->isPositionedOnNode($nodeName, XMLReader::END_ELEMENT); + return $this->isPositionedOnNode($nodeName, self::END_ELEMENT); } /** diff --git a/src/Spout/Reader/XLSX/Creator/EntityFactory.php b/src/Spout/Reader/XLSX/Creator/EntityFactory.php index 56b5b75..18fe3ef 100644 --- a/src/Spout/Reader/XLSX/Creator/EntityFactory.php +++ b/src/Spout/Reader/XLSX/Creator/EntityFactory.php @@ -5,18 +5,16 @@ namespace Box\Spout\Reader\XLSX\Creator; use Box\Spout\Reader\Common\Creator\EntityFactoryInterface; use Box\Spout\Reader\Common\Entity\Options; use Box\Spout\Reader\Common\XMLProcessor; +use Box\Spout\Reader\Wrapper\XMLReader; use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; use Box\Spout\Reader\XLSX\RowIterator; use Box\Spout\Reader\XLSX\Sheet; use Box\Spout\Reader\XLSX\SheetIterator; -use Box\Spout\Reader\Wrapper\XMLReader; use MongoDB\Driver\Manager; /** * Class EntityFactory * Factory to create entities - * - * @package Box\Spout\Reader\XLSX\Creator */ class EntityFactory implements EntityFactoryInterface { @@ -45,6 +43,7 @@ class EntityFactory implements EntityFactoryInterface public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager) { $sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this); + return new SheetIterator($sheetManager); } @@ -65,9 +64,10 @@ class EntityFactory implements EntityFactoryInterface $sheetName, $isSheetActive, $optionsManager, - $sharedStringsManager) - { + $sharedStringsManager + ) { $rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager); + return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive); } diff --git a/src/Spout/Reader/XLSX/Creator/HelperFactory.php b/src/Spout/Reader/XLSX/Creator/HelperFactory.php index dbd1fd5..6546712 100644 --- a/src/Spout/Reader/XLSX/Creator/HelperFactory.php +++ b/src/Spout/Reader/XLSX/Creator/HelperFactory.php @@ -4,17 +4,12 @@ namespace Box\Spout\Reader\XLSX\Creator; use Box\Spout\Common\Helper\Escaper; use Box\Spout\Reader\XLSX\Helper\CellValueFormatter; -use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory; use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; -use Box\Spout\Reader\XLSX\Manager\SheetManager; use Box\Spout\Reader\XLSX\Manager\StyleManager; - /** * Class HelperFactory * Factory to create helpers - * - * @package Box\Spout\Reader\XLSX\Creator */ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory { @@ -27,6 +22,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory public function createCellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates) { $escaper = $this->createStringsEscaper(); + return new CellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates, $escaper); } @@ -35,7 +31,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory */ public function createStringsEscaper() { - /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ + /* @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ return new Escaper\XLSX(); } } diff --git a/src/Spout/Reader/XLSX/Creator/ManagerFactory.php b/src/Spout/Reader/XLSX/Creator/ManagerFactory.php index 08acaff..497b130 100644 --- a/src/Spout/Reader/XLSX/Creator/ManagerFactory.php +++ b/src/Spout/Reader/XLSX/Creator/ManagerFactory.php @@ -7,12 +7,9 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsManager; use Box\Spout\Reader\XLSX\Manager\SheetManager; use Box\Spout\Reader\XLSX\Manager\StyleManager; - /** * Class ManagerFactory * Factory to create managers - * - * @package Box\Spout\Reader\XLSX\Creator */ class ManagerFactory { @@ -53,6 +50,7 @@ class ManagerFactory public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory) { $escaper = $this->helperFactory->createStringsEscaper(); + return new SheetManager($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory); } diff --git a/src/Spout/Reader/XLSX/Helper/CellHelper.php b/src/Spout/Reader/XLSX/Helper/CellHelper.php index 0d1dc29..9346f16 100644 --- a/src/Spout/Reader/XLSX/Helper/CellHelper.php +++ b/src/Spout/Reader/XLSX/Helper/CellHelper.php @@ -7,8 +7,6 @@ use Box\Spout\Common\Exception\InvalidArgumentException; /** * Class CellHelper * This class provides helper functions when working with cells - * - * @package Box\Spout\Reader\XLSX\Helper */ class CellHelper { @@ -51,8 +49,8 @@ class CellHelper * The mapping is zero based, so that A1 maps to 0, B2 maps to 1, Z13 to 25 and AA4 to 26. * * @param string $cellIndex The Excel cell index ('A1', 'BC13', ...) - * @return int * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid + * @return int */ public static function getColumnIndexFromCellIndex($cellIndex) { diff --git a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php index 338ccad..aaebfa6 100644 --- a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php @@ -8,8 +8,6 @@ use Box\Spout\Reader\XLSX\Manager\StyleManager; /** * Class CellValueFormatter * This class provides helper functions to format cell values - * - * @package Box\Spout\Reader\XLSX\Helper */ class CellValueFormatter { @@ -77,7 +75,7 @@ class CellValueFormatter { // Default cell type is "n" $cellType = $node->getAttribute(self::XML_ATTRIBUTE_TYPE) ?: self::CELL_TYPE_NUMERIC; - $cellStyleId = intval($node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID)); + $cellStyleId = (int) $node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID); $vNodeValue = $this->getVNodeValue($node); if (($vNodeValue === '') && ($cellType !== self::CELL_TYPE_INLINE_STRING)) { @@ -113,6 +111,7 @@ class CellValueFormatter // for cell types having a "v" tag containing the value. // if not, the returned value should be empty string. $vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0); + return ($vNode !== null) ? $vNode->nodeValue : ''; } @@ -128,6 +127,7 @@ class CellValueFormatter // [INLINE_STRING] $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0); $cellValue = $this->escaper->unescape($tNode->nodeValue); + return $cellValue; } @@ -141,9 +141,10 @@ class CellValueFormatter { // shared strings are formatted this way: // [SHARED_STRING_INDEX] - $sharedStringIndex = intval($nodeValue); + $sharedStringIndex = (int) $nodeValue; $escapedCellValue = $this->sharedStringsManager->getStringAtIndex($sharedStringIndex); $cellValue = $this->escaper->unescape($escapedCellValue); + return $cellValue; } @@ -157,6 +158,7 @@ class CellValueFormatter { $escapedCellValue = trim($nodeValue); $cellValue = $this->escaper->unescape($escapedCellValue); + return $cellValue; } @@ -175,9 +177,9 @@ class CellValueFormatter $shouldFormatAsDate = $this->styleManager->shouldFormatNumericValueAsDate($cellStyleId); if ($shouldFormatAsDate) { - $cellValue = $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId); + $cellValue = $this->formatExcelTimestampValue((float) $nodeValue, $cellStyleId); } else { - $nodeIntValue = intval($nodeValue); + $nodeIntValue = (int) $nodeValue; $nodeFloatValue = (float) $nodeValue; $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue; } @@ -204,7 +206,7 @@ class CellValueFormatter if ($nodeValue >= 1) { // Values greater than 1 represent "dates". The value 1.0 representing the "base" date: 1900-01-01. $cellValue = $this->formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId); - } else if ($nodeValue >= 0) { + } elseif ($nodeValue >= 0) { // Values between 0 and 1 represent "times". $cellValue = $this->formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId); } else { @@ -262,7 +264,7 @@ class CellValueFormatter try { $dateObj = \DateTime::createFromFormat('|Y-m-d', '1899-12-31'); - $dateObj->modify('+' . intval($nodeValue) . 'days'); + $dateObj->modify('+' . (int) $nodeValue . 'days'); $dateObj->modify('+' . $secondsRemainder . 'seconds'); if ($this->shouldFormatDates) { diff --git a/src/Spout/Reader/XLSX/Helper/DateFormatHelper.php b/src/Spout/Reader/XLSX/Helper/DateFormatHelper.php index 9dba4c6..1618af7 100644 --- a/src/Spout/Reader/XLSX/Helper/DateFormatHelper.php +++ b/src/Spout/Reader/XLSX/Helper/DateFormatHelper.php @@ -5,8 +5,6 @@ namespace Box\Spout\Reader\XLSX\Helper; /** * Class DateFormatHelper * This class provides helper functions to format Excel dates - * - * @package Box\Spout\Reader\XLSX\Helper */ class DateFormatHelper { @@ -104,9 +102,10 @@ class DateFormatHelper // Finally, to have the date format compatible with the DateTime::format() function, we need to escape // all characters that are inside double quotes (and double quotes must be removed). // For instance, ["Day " dd] should become [\D\a\y\ dd] - $phpDateFormat = preg_replace_callback('/"(.+?)"/', function($matches) { + $phpDateFormat = preg_replace_callback('/"(.+?)"/', function ($matches) { $stringToEscape = $matches[1]; $letters = preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY); + return '\\' . implode('\\', $letters); }, $phpDateFormat); diff --git a/src/Spout/Reader/XLSX/Manager/OptionsManager.php b/src/Spout/Reader/XLSX/Manager/OptionsManager.php index f56d0ec..7677c22 100644 --- a/src/Spout/Reader/XLSX/Manager/OptionsManager.php +++ b/src/Spout/Reader/XLSX/Manager/OptionsManager.php @@ -8,13 +8,11 @@ use Box\Spout\Reader\Common\Entity\Options; /** * Class OptionsManager * XLSX Reader options manager - * - * @package Box\Spout\Reader\XLSX\Manager */ class OptionsManager extends OptionsManagerAbstract { /** - * @inheritdoc + * {@inheritdoc} */ protected function getSupportedOptions() { @@ -26,7 +24,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function setDefaultOptions() { diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php index b05c896..4aaba3a 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php @@ -6,8 +6,6 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory; /** * Class CachingStrategyFactory - * - * @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching */ class CachingStrategyFactory { @@ -52,7 +50,6 @@ class CachingStrategyFactory */ const MAX_NUM_STRINGS_PER_TEMP_FILE = 10000; - /** * Returns the best caching strategy, given the number of unique shared strings * and the amount of memory available. @@ -114,7 +111,7 @@ class CachingStrategyFactory } if (preg_match('/(\d+)([bkmgt])b?/', $memoryLimitFormatted, $matches)) { - $amount = intval($matches[1]); + $amount = (int) ($matches[1]); $unit = $matches[2]; switch ($unit) { diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyInterface.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyInterface.php index 5628921..479b0b5 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyInterface.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyInterface.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching; /** * Interface CachingStrategyInterface - * - * @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching */ interface CachingStrategyInterface { @@ -30,8 +28,8 @@ interface CachingStrategyInterface * Returns the string located at the given index from the cache. * * @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file - * @return string The shared string at the given index * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index + * @return string The shared string at the given index */ public function getStringAtIndex($sharedStringIndex); diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php index 955ddc2..c8ded70 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php @@ -11,8 +11,6 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory; * This class implements the file-based caching strategy for shared strings. * Shared strings are stored in small files (with a max number of strings per file). * This strategy is slower than an in-memory strategy but is used to avoid out of memory crashes. - * - * @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching */ class FileBasedStrategy implements CachingStrategyInterface { @@ -98,7 +96,8 @@ class FileBasedStrategy implements CachingStrategyInterface */ protected function getSharedStringTempFilePath($sharedStringIndex) { - $numTempFile = intval($sharedStringIndex / $this->maxNumStringsPerTempFile); + $numTempFile = (int) ($sharedStringIndex / $this->maxNumStringsPerTempFile); + return $this->tempFolder . '/sharedstrings' . $numTempFile; } @@ -116,13 +115,12 @@ class FileBasedStrategy implements CachingStrategyInterface } } - /** * Returns the string located at the given index from the cache. * * @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file - * @return string The shared string at the given index * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index + * @return string The shared string at the given index */ public function getStringAtIndex($sharedStringIndex) { diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/InMemoryStrategy.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/InMemoryStrategy.php index 1b122fe..a16d4de 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/InMemoryStrategy.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/InMemoryStrategy.php @@ -9,8 +9,6 @@ use Box\Spout\Reader\Exception\SharedStringNotFoundException; * * This class implements the in-memory caching strategy for shared strings. * This strategy is used when the number of unique strings is low, compared to the memory available. - * - * @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching */ class InMemoryStrategy implements CachingStrategyInterface { @@ -58,8 +56,8 @@ class InMemoryStrategy implements CachingStrategyInterface * Returns the string located at the given index from the cache. * * @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file - * @return string The shared string at the given index * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index + * @return string The shared string at the given index */ public function getStringAtIndex($sharedStringIndex) { diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php b/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php index ad74b34..a59e093 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php @@ -13,8 +13,6 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyInterface; /** * Class SharedStringsManager * This class manages the shared strings defined in the associated XML file - * - * @package Box\Spout\Reader\XLSX\Manager */ class SharedStringsManager { @@ -98,8 +96,8 @@ class SharedStringsManager * The XML file can be really big with sheets containing a lot of data. That is why * we need to use a XML reader that provides streaming like the XMLReader library. * - * @return void * @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml can't be read + * @return void */ public function extractSharedStrings() { @@ -125,7 +123,6 @@ class SharedStringsManager } $this->cachingStrategy->closeCache(); - } catch (XMLProcessingException $exception) { throw new IOException("The sharedStrings.xml file is invalid and cannot be read. [{$exception->getMessage()}]"); } @@ -137,8 +134,8 @@ class SharedStringsManager * Returns the shared strings unique count, as specified in tag. * * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader instance - * @return int|null Number of unique shared strings in the sharedStrings.xml file * @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml is invalid and can't be read + * @return int|null Number of unique shared strings in the sharedStrings.xml file */ protected function getSharedStringsUniqueCount($xmlReader) { @@ -157,7 +154,7 @@ class SharedStringsManager $uniqueCount = $xmlReader->getAttribute(self::XML_ATTRIBUTE_COUNT); } - return ($uniqueCount !== null) ? intval($uniqueCount) : null; + return ($uniqueCount !== null) ? (int) $uniqueCount : null; } /** @@ -210,6 +207,7 @@ class SharedStringsManager protected function shouldExtractTextNodeValue($textNode) { $parentTagName = $textNode->parentNode->localName; + return ($parentTagName === self::XML_NODE_SI || $parentTagName === self::XML_NODE_R); } @@ -222,6 +220,7 @@ class SharedStringsManager protected function shouldPreserveWhitespace($textNode) { $spaceValue = $textNode->getAttribute(self::XML_ATTRIBUTE_XML_SPACE); + return ($spaceValue === self::XML_ATTRIBUTE_VALUE_PRESERVE); } @@ -229,8 +228,8 @@ class SharedStringsManager * Returns the shared string at the given index, using the previously chosen caching strategy. * * @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file - * @return string The shared string at the given index * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index + * @return string The shared string at the given index */ public function getStringAtIndex($sharedStringIndex) { diff --git a/src/Spout/Reader/XLSX/Manager/SheetManager.php b/src/Spout/Reader/XLSX/Manager/SheetManager.php index 6da8475..a848948 100644 --- a/src/Spout/Reader/XLSX/Manager/SheetManager.php +++ b/src/Spout/Reader/XLSX/Manager/SheetManager.php @@ -2,15 +2,12 @@ namespace Box\Spout\Reader\XLSX\Manager; -use Box\Spout\Reader\Wrapper\XMLReader; use Box\Spout\Reader\XLSX\Creator\EntityFactory; use Box\Spout\Reader\XLSX\Sheet; /** * Class SheetManager * This class manages XLSX sheets - * - * @package Box\Spout\Reader\XLSX\Manager */ class SheetManager { @@ -55,6 +52,7 @@ class SheetManager * @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings * @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data * @param EntityFactory $entityFactory Factory to create entities + * @param mixed $sharedStringsManager */ public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory) { @@ -85,11 +83,11 @@ class SheetManager // The "workbookView" node is located before "sheet" nodes, ensuring that // the active sheet is known before parsing sheets data. $activeSheetIndex = (int) $xmlReader->getAttribute(self::XML_ATTRIBUTE_ACTIVE_TAB); - } else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_SHEET)) { + } elseif ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_SHEET)) { $isSheetActive = ($sheetIndex === $activeSheetIndex); $sheets[] = $this->getSheetFromSheetXMLNode($xmlReader, $sheetIndex, $isSheetActive); $sheetIndex++; - } else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_SHEETS)) { + } elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_SHEETS)) { // stop reading once all sheets have been read break; } diff --git a/src/Spout/Reader/XLSX/Manager/StyleManager.php b/src/Spout/Reader/XLSX/Manager/StyleManager.php index 23c1582..b36661b 100644 --- a/src/Spout/Reader/XLSX/Manager/StyleManager.php +++ b/src/Spout/Reader/XLSX/Manager/StyleManager.php @@ -7,8 +7,6 @@ use Box\Spout\Reader\XLSX\Creator\EntityFactory; /** * Class StyleManager * This class manages XLSX styles - * - * @package Box\Spout\Reader\XLSX\Manager */ class StyleManager { @@ -118,8 +116,7 @@ class StyleManager while ($xmlReader->read()) { if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMTS)) { $this->extractNumberFormats($xmlReader); - - } else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) { + } elseif ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) { $this->extractStyleAttributes($xmlReader); } } @@ -140,10 +137,10 @@ class StyleManager { while ($xmlReader->read()) { if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMT)) { - $numFmtId = intval($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID)); + $numFmtId = (int) ($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID)); $formatCode = $xmlReader->getAttribute(self::XML_ATTRIBUTE_FORMAT_CODE); $this->customNumberFormats[$numFmtId] = $formatCode; - } else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) { + } elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) { // Once done reading "numFmts" node's children break; } @@ -163,16 +160,16 @@ class StyleManager while ($xmlReader->read()) { if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_XF)) { $numFmtId = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID); - $normalizedNumFmtId = ($numFmtId !== null) ? intval($numFmtId) : null; + $normalizedNumFmtId = ($numFmtId !== null) ? (int) $numFmtId : null; $applyNumberFormat = $xmlReader->getAttribute(self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT); - $normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? !!$applyNumberFormat : null; + $normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? (bool) $applyNumberFormat : null; $this->stylesAttributes[] = [ - self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId, + self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId, self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT => $normalizedApplyNumberFormat, ]; - } else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) { + } elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) { // Once done reading "cellXfs" node's children break; } diff --git a/src/Spout/Reader/XLSX/Reader.php b/src/Spout/Reader/XLSX/Reader.php index eaf0166..eb44cce 100644 --- a/src/Spout/Reader/XLSX/Reader.php +++ b/src/Spout/Reader/XLSX/Reader.php @@ -14,8 +14,6 @@ use Box\Spout\Reader\XLSX\Creator\ManagerFactory; /** * Class Reader * This class provides support to read data from a XLSX file - * - * @package Box\Spout\Reader\XLSX */ class Reader extends ReaderAbstract { @@ -31,7 +29,6 @@ class Reader extends ReaderAbstract /** @var SheetIterator To iterator over the XLSX sheets */ protected $sheetIterator; - /** * @param OptionsManagerInterface $optionsManager * @param GlobalFunctionsHelper $globalFunctionsHelper @@ -42,8 +39,8 @@ class Reader extends ReaderAbstract OptionsManagerInterface $optionsManager, GlobalFunctionsHelper $globalFunctionsHelper, EntityFactoryInterface $entityFactory, - ManagerFactory $managerFactory) - { + ManagerFactory $managerFactory + ) { parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory); $this->managerFactory = $managerFactory; } @@ -55,6 +52,7 @@ class Reader extends ReaderAbstract public function setTempFolder($tempFolder) { $this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder); + return $this; } @@ -74,9 +72,9 @@ class Reader extends ReaderAbstract * and fetches all the available sheets. * * @param string $filePath Path of the file to be read - * @return void * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file + * @return void */ protected function openReader($filePath) { diff --git a/src/Spout/Reader/XLSX/RowIterator.php b/src/Spout/Reader/XLSX/RowIterator.php index 795f00f..aa406d8 100644 --- a/src/Spout/Reader/XLSX/RowIterator.php +++ b/src/Spout/Reader/XLSX/RowIterator.php @@ -3,20 +3,15 @@ namespace Box\Spout\Reader\XLSX; use Box\Spout\Common\Exception\IOException; -use Box\Spout\Reader\Common\Entity\Options; +use Box\Spout\Reader\Common\XMLProcessor; use Box\Spout\Reader\Exception\XMLProcessingException; use Box\Spout\Reader\IteratorInterface; use Box\Spout\Reader\Wrapper\XMLReader; -use Box\Spout\Reader\XLSX\Creator\EntityFactory; -use Box\Spout\Reader\XLSX\Creator\HelperFactory; use Box\Spout\Reader\XLSX\Helper\CellHelper; -use Box\Spout\Reader\Common\XMLProcessor; use Box\Spout\Reader\XLSX\Helper\CellValueFormatter; /** * Class RowIterator - * - * @package Box\Spout\Reader\XLSX */ class RowIterator implements IteratorInterface { @@ -57,7 +52,7 @@ class RowIterator implements IteratorInterface protected $currentlyProcessedRowData = []; /** @var array|null Buffer used to store the row data, while checking if there are more rows to read */ - protected $rowDataBuffer = null; + protected $rowDataBuffer; /** @var bool Indicates whether all rows have been read */ protected $hasReachedEndOfFile = false; @@ -116,10 +111,10 @@ class RowIterator implements IteratorInterface * Rewind the Iterator to the first element. * Initializes the XMLReader object that reads the associated sheet data. * The XMLReader is configured to be safe from billion laughs attack. - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * - * @return void * @throws \Box\Spout\Common\Exception\IOException If the sheet data XML cannot be read + * @return void */ public function rewind() { @@ -141,7 +136,7 @@ class RowIterator implements IteratorInterface /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -152,11 +147,11 @@ class RowIterator implements IteratorInterface /** * Move forward to next element. Reads data describing the next unprocessed row. - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * - * @return void * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML + * @return void */ public function next() { @@ -191,9 +186,9 @@ class RowIterator implements IteratorInterface } /** - * @return void * @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found * @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML + * @return void */ protected function readDataForNextRow() { @@ -240,7 +235,7 @@ class RowIterator implements IteratorInterface $spans = $xmlReader->getAttribute(self::XML_ATTRIBUTE_SPANS); // returns '1:5' for instance if ($spans) { list(, $numberOfColumnsForRow) = explode(':', $spans); - $numberOfColumnsForRow = intval($numberOfColumnsForRow); + $numberOfColumnsForRow = (int) $numberOfColumnsForRow; } $this->currentlyProcessedRowData = ($numberOfColumnsForRow !== 0) ? array_fill(0, $numberOfColumnsForRow, '') : []; @@ -300,8 +295,8 @@ class RowIterator implements IteratorInterface /** * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "" node - * @return int Row index * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid + * @return int Row index */ protected function getRowIndex($xmlReader) { @@ -309,14 +304,14 @@ class RowIterator implements IteratorInterface $currentRowIndex = $xmlReader->getAttribute(self::XML_ATTRIBUTE_ROW_INDEX); return ($currentRowIndex !== null) ? - intval($currentRowIndex) : + (int) $currentRowIndex : $this->lastRowIndexProcessed + 1; } /** * @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "" node - * @return int Column index * @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid + * @return int Column index */ protected function getColumnIndex($xmlReader) { @@ -350,7 +345,7 @@ class RowIterator implements IteratorInterface /** * Return the current element, either an empty row or from the buffer. - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return array|null */ @@ -375,7 +370,7 @@ class RowIterator implements IteratorInterface /** * Return the key of the current element. Here, the row index. - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ @@ -389,7 +384,6 @@ class RowIterator implements IteratorInterface $this->numReadRows; } - /** * Cleans up what was created to iterate over the object. * diff --git a/src/Spout/Reader/XLSX/Sheet.php b/src/Spout/Reader/XLSX/Sheet.php index df0228e..bff1fb4 100644 --- a/src/Spout/Reader/XLSX/Sheet.php +++ b/src/Spout/Reader/XLSX/Sheet.php @@ -3,13 +3,10 @@ namespace Box\Spout\Reader\XLSX; use Box\Spout\Reader\SheetInterface; -use Box\Spout\Reader\XLSX\Creator\EntityFactory; /** * Class Sheet * Represents a sheet within a XLSX file - * - * @package Box\Spout\Reader\XLSX */ class Sheet implements SheetInterface { diff --git a/src/Spout/Reader/XLSX/SheetIterator.php b/src/Spout/Reader/XLSX/SheetIterator.php index d960a7a..d9ed17c 100644 --- a/src/Spout/Reader/XLSX/SheetIterator.php +++ b/src/Spout/Reader/XLSX/SheetIterator.php @@ -2,15 +2,13 @@ namespace Box\Spout\Reader\XLSX; +use Box\Spout\Reader\Exception\NoSheetsFoundException; use Box\Spout\Reader\IteratorInterface; use Box\Spout\Reader\XLSX\Manager\SheetManager; -use Box\Spout\Reader\Exception\NoSheetsFoundException; /** * Class SheetIterator * Iterate over XLSX sheet. - * - * @package Box\Spout\Reader\XLSX */ class SheetIterator implements IteratorInterface { @@ -36,7 +34,7 @@ class SheetIterator implements IteratorInterface /** * Rewind the Iterator to the first element - * @link http://php.net/manual/en/iterator.rewind.php + * @see http://php.net/manual/en/iterator.rewind.php * * @return void */ @@ -47,7 +45,7 @@ class SheetIterator implements IteratorInterface /** * Checks if current position is valid - * @link http://php.net/manual/en/iterator.valid.php + * @see http://php.net/manual/en/iterator.valid.php * * @return bool */ @@ -58,7 +56,7 @@ class SheetIterator implements IteratorInterface /** * Move forward to next element - * @link http://php.net/manual/en/iterator.next.php + * @see http://php.net/manual/en/iterator.next.php * * @return void */ @@ -75,7 +73,7 @@ class SheetIterator implements IteratorInterface /** * Return the current element - * @link http://php.net/manual/en/iterator.current.php + * @see http://php.net/manual/en/iterator.current.php * * @return \Box\Spout\Reader\XLSX\Sheet */ @@ -86,7 +84,7 @@ class SheetIterator implements IteratorInterface /** * Return the key of the current element - * @link http://php.net/manual/en/iterator.key.php + * @see http://php.net/manual/en/iterator.key.php * * @return int */ diff --git a/src/Spout/Writer/CSV/Manager/OptionsManager.php b/src/Spout/Writer/CSV/Manager/OptionsManager.php index e9e0eb2..8acee69 100644 --- a/src/Spout/Writer/CSV/Manager/OptionsManager.php +++ b/src/Spout/Writer/CSV/Manager/OptionsManager.php @@ -2,19 +2,17 @@ namespace Box\Spout\Writer\CSV\Manager; -use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Common\Manager\OptionsManagerAbstract; +use Box\Spout\Writer\Common\Entity\Options; /** * Class OptionsManager * CSV Writer options manager - * - * @package Box\Spout\Writer\CSV\Manager */ class OptionsManager extends OptionsManagerAbstract { /** - * @inheritdoc + * {@inheritdoc} */ protected function getSupportedOptions() { @@ -26,7 +24,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function setDefaultOptions() { diff --git a/src/Spout/Writer/CSV/Writer.php b/src/Spout/Writer/CSV/Writer.php index 8bf3c0f..7f9c814 100644 --- a/src/Spout/Writer/CSV/Writer.php +++ b/src/Spout/Writer/CSV/Writer.php @@ -2,16 +2,14 @@ namespace Box\Spout\Writer\CSV; -use Box\Spout\Writer\WriterAbstract; use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Helper\EncodingHelper; use Box\Spout\Writer\Common\Entity\Options; +use Box\Spout\Writer\WriterAbstract; /** * Class Writer * This class provides support to write data to CSV files - * - * @package Box\Spout\Writer\CSV */ class Writer extends WriterAbstract { @@ -34,6 +32,7 @@ class Writer extends WriterAbstract public function setFieldDelimiter($fieldDelimiter) { $this->optionsManager->setOption(Options::FIELD_DELIMITER, $fieldDelimiter); + return $this; } @@ -47,6 +46,7 @@ class Writer extends WriterAbstract public function setFieldEnclosure($fieldEnclosure) { $this->optionsManager->setOption(Options::FIELD_ENCLOSURE, $fieldEnclosure); + return $this; } @@ -60,6 +60,7 @@ class Writer extends WriterAbstract public function setShouldAddBOM($shouldAddBOM) { $this->optionsManager->setOption(Options::SHOULD_ADD_BOM, (bool) $shouldAddBOM); + return $this; } @@ -82,8 +83,8 @@ class Writer extends WriterAbstract * @param array $dataRow Array containing data to be written. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param \Box\Spout\Writer\Common\Entity\Style\Style $style Ignored here since CSV does not support styling. - * @return void * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return void */ protected function addRowToWriter(array $dataRow, $style) { diff --git a/src/Spout/Writer/Common/Creator/EntityFactory.php b/src/Spout/Writer/Common/Creator/EntityFactory.php index b44d099..04324aa 100644 --- a/src/Spout/Writer/Common/Creator/EntityFactory.php +++ b/src/Spout/Writer/Common/Creator/EntityFactory.php @@ -11,8 +11,6 @@ use Box\Spout\Writer\Common\Manager\SheetManager; /** * Class EntityFactory * Factory to create entities - * - * @package Box\Spout\Writer\Common\Creator */ class EntityFactory { diff --git a/src/Spout/Writer/Common/Creator/ManagerFactoryInterface.php b/src/Spout/Writer/Common/Creator/ManagerFactoryInterface.php index cc10606..0eab258 100644 --- a/src/Spout/Writer/Common/Creator/ManagerFactoryInterface.php +++ b/src/Spout/Writer/Common/Creator/ManagerFactoryInterface.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface; /** * Interface ManagerFactoryInterface - * - * @package Box\Spout\Writer\Common\Creator */ interface ManagerFactoryInterface { diff --git a/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php b/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php index f613e4b..f85b1a9 100644 --- a/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php +++ b/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Color; /** * Class BorderBuilder - * - * @package \Box\Spout\Writer\Common\Creator\Style */ class BorderBuilder { @@ -32,6 +30,7 @@ class BorderBuilder public function setBorderTop($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { $this->border->addPart(new BorderPart(Border::TOP, $color, $width, $style)); + return $this; } @@ -44,6 +43,7 @@ class BorderBuilder public function setBorderRight($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { $this->border->addPart(new BorderPart(Border::RIGHT, $color, $width, $style)); + return $this; } @@ -56,6 +56,7 @@ class BorderBuilder public function setBorderBottom($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { $this->border->addPart(new BorderPart(Border::BOTTOM, $color, $width, $style)); + return $this; } @@ -68,6 +69,7 @@ class BorderBuilder public function setBorderLeft($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { $this->border->addPart(new BorderPart(Border::LEFT, $color, $width, $style)); + return $this; } diff --git a/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php b/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php index 34e40d7..1a8c710 100644 --- a/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php +++ b/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleBuilder * Builder to create new styles - * - * @package Box\Spout\Writer\Common\Creator\Style */ class StyleBuilder { @@ -33,6 +31,7 @@ class StyleBuilder public function setFontBold() { $this->style->setFontBold(); + return $this; } @@ -45,6 +44,7 @@ class StyleBuilder public function setFontItalic() { $this->style->setFontItalic(); + return $this; } @@ -57,6 +57,7 @@ class StyleBuilder public function setFontUnderline() { $this->style->setFontUnderline(); + return $this; } @@ -69,6 +70,7 @@ class StyleBuilder public function setFontStrikethrough() { $this->style->setFontStrikethrough(); + return $this; } @@ -82,6 +84,7 @@ class StyleBuilder public function setFontSize($fontSize) { $this->style->setFontSize($fontSize); + return $this; } @@ -95,6 +98,7 @@ class StyleBuilder public function setFontColor($fontColor) { $this->style->setFontColor($fontColor); + return $this; } @@ -108,6 +112,7 @@ class StyleBuilder public function setFontName($fontName) { $this->style->setFontName($fontName); + return $this; } @@ -121,6 +126,7 @@ class StyleBuilder public function setShouldWrapText($shouldWrap = true) { $this->style->setShouldWrapText($shouldWrap); + return $this; } @@ -133,6 +139,7 @@ class StyleBuilder public function setBorder(Border $border) { $this->style->setBorder($border); + return $this; } @@ -146,6 +153,7 @@ class StyleBuilder public function setBackgroundColor($color) { $this->style->setBackgroundColor($color); + return $this; } diff --git a/src/Spout/Writer/Common/Entity/Cell.php b/src/Spout/Writer/Common/Entity/Cell.php index 77b5d08..f869e2c 100644 --- a/src/Spout/Writer/Common/Entity/Cell.php +++ b/src/Spout/Writer/Common/Entity/Cell.php @@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Helper\CellHelper; /** * Class Cell - * - * @package Box\Spout\Writer\Common\Entity */ class Cell { @@ -46,13 +44,13 @@ class Cell * The value of this cell * @var mixed|null */ - protected $value = null; + protected $value; /** * The cell type * @var int|null */ - protected $type = null; + protected $type; /** * Cell constructor. @@ -165,6 +163,6 @@ class Cell */ public function __toString() { - return (string)$this->value; + return (string) $this->value; } } diff --git a/src/Spout/Writer/Common/Entity/Options.php b/src/Spout/Writer/Common/Entity/Options.php index 36c1993..d7152bb 100644 --- a/src/Spout/Writer/Common/Entity/Options.php +++ b/src/Spout/Writer/Common/Entity/Options.php @@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity; /** * Class Options * Writers' options holder - * - * @package Box\Spout\Writer\Common\Entity */ abstract class Options { diff --git a/src/Spout/Writer/Common/Entity/Sheet.php b/src/Spout/Writer/Common/Entity/Sheet.php index ed183f7..ddb9d60 100644 --- a/src/Spout/Writer/Common/Entity/Sheet.php +++ b/src/Spout/Writer/Common/Entity/Sheet.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Manager\SheetManager; /** * Class Sheet * External representation of a worksheet - * - * @package Box\Spout\Writer\Common\Entity */ class Sheet { @@ -77,8 +75,8 @@ class Sheet * * @api * @param string $name Name of the sheet - * @return Sheet * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. + * @return Sheet */ public function setName($name) { diff --git a/src/Spout/Writer/Common/Entity/Style/Border.php b/src/Spout/Writer/Common/Entity/Style/Border.php index f872d34..ba5d1a2 100644 --- a/src/Spout/Writer/Common/Entity/Style/Border.php +++ b/src/Spout/Writer/Common/Entity/Style/Border.php @@ -4,8 +4,6 @@ namespace Box\Spout\Writer\Common\Entity\Style; /** * Class Border - * - * @package \Box\Spout\Writer\Common\Entity\Style */ class Border { @@ -37,7 +35,7 @@ class Border /** * @param string $name The name of the border part - * @return null|BorderPart + * @return BorderPart|null */ public function getPart($name) { @@ -81,6 +79,7 @@ class Border public function addPart(BorderPart $borderPart) { $this->parts[$borderPart->getName()] = $borderPart; + return $this; } } diff --git a/src/Spout/Writer/Common/Entity/Style/BorderPart.php b/src/Spout/Writer/Common/Entity/Style/BorderPart.php index 66a08c1..cbc6a62 100644 --- a/src/Spout/Writer/Common/Entity/Style/BorderPart.php +++ b/src/Spout/Writer/Common/Entity/Style/BorderPart.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Exception\Border\InvalidWidthException; /** * Class BorderPart - * - * @package \Box\Spout\Writer\Common\Entity\Style */ class BorderPart { @@ -41,7 +39,7 @@ class BorderPart 'solid', 'dashed', 'dotted', - 'double' + 'double', ]; /** diff --git a/src/Spout/Writer/Common/Entity/Style/Color.php b/src/Spout/Writer/Common/Entity/Style/Color.php index 356f606..6b3682e 100644 --- a/src/Spout/Writer/Common/Entity/Style/Color.php +++ b/src/Spout/Writer/Common/Entity/Style/Color.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Exception\InvalidColorException; /** * Class Color * This class provides constants and functions to work with colors - * - * @package Box\Spout\Writer\Common\Entity\Style */ class Color { @@ -52,8 +50,8 @@ class Color * Throws an exception is the color component value is outside of bounds (0 - 255) * * @param int $colorComponent - * @return void * @throws \Box\Spout\Writer\Exception\InvalidColorException + * @return void */ protected static function throwIfInvalidColorComponentValue($colorComponent) { diff --git a/src/Spout/Writer/Common/Entity/Style/Style.php b/src/Spout/Writer/Common/Entity/Style/Style.php index e82b365..a8018e8 100644 --- a/src/Spout/Writer/Common/Entity/Style/Style.php +++ b/src/Spout/Writer/Common/Entity/Style/Style.php @@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity\Style; /** * Class Style * Represents a style to be applied to a cell - * - * @package Box\Spout\Writer\Common\Entity\Style */ class Style { @@ -16,7 +14,7 @@ class Style const DEFAULT_FONT_NAME = 'Arial'; /** @var int|null Style ID */ - private $id = null; + private $id; /** @var bool Whether the font should be bold */ private $fontBold = false; @@ -62,18 +60,17 @@ class Style private $hasSetWrapText = false; /** @var Border */ - private $border = null; + private $border; /** @var bool Whether border properties should be applied */ private $shouldApplyBorder = false; /** @var string Background color */ - private $backgroundColor = null; + private $backgroundColor; /** @var bool */ private $hasSetBackgroundColor = false; - /** * @return int|null */ @@ -89,6 +86,7 @@ class Style public function setId($id) { $this->id = $id; + return $this; } @@ -108,6 +106,7 @@ class Style { $this->shouldApplyBorder = true; $this->border = $border; + return $this; } @@ -135,6 +134,7 @@ class Style $this->fontBold = true; $this->hasSetFontBold = true; $this->shouldApplyFont = true; + return $this; } @@ -162,6 +162,7 @@ class Style $this->fontItalic = true; $this->hasSetFontItalic = true; $this->shouldApplyFont = true; + return $this; } @@ -189,6 +190,7 @@ class Style $this->fontUnderline = true; $this->hasSetFontUnderline = true; $this->shouldApplyFont = true; + return $this; } @@ -216,6 +218,7 @@ class Style $this->fontStrikethrough = true; $this->hasSetFontStrikethrough = true; $this->shouldApplyFont = true; + return $this; } @@ -244,6 +247,7 @@ class Style $this->fontSize = $fontSize; $this->hasSetFontSize = true; $this->shouldApplyFont = true; + return $this; } @@ -274,6 +278,7 @@ class Style $this->fontColor = $fontColor; $this->hasSetFontColor = true; $this->shouldApplyFont = true; + return $this; } @@ -302,6 +307,7 @@ class Style $this->fontName = $fontName; $this->hasSetFontName = true; $this->shouldApplyFont = true; + return $this; } @@ -329,6 +335,7 @@ class Style { $this->shouldWrapText = $shouldWrap; $this->hasSetWrapText = true; + return $this; } @@ -357,6 +364,7 @@ class Style { $this->hasSetBackgroundColor = true; $this->backgroundColor = $color; + return $this; } @@ -369,7 +377,6 @@ class Style } /** - * * @return bool Whether the background color should be applied */ public function shouldApplyBackgroundColor() diff --git a/src/Spout/Writer/Common/Entity/Workbook.php b/src/Spout/Writer/Common/Entity/Workbook.php index e10a419..782310b 100644 --- a/src/Spout/Writer/Common/Entity/Workbook.php +++ b/src/Spout/Writer/Common/Entity/Workbook.php @@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Entity; /** * Class Workbook * Entity describing a workbook - * - * @package Box\Spout\Writer\Common\Entity */ class Workbook { @@ -47,4 +45,4 @@ class Workbook { return $this->internalId; } -} \ No newline at end of file +} diff --git a/src/Spout/Writer/Common/Entity/Worksheet.php b/src/Spout/Writer/Common/Entity/Worksheet.php index 1783a5f..74c4976 100644 --- a/src/Spout/Writer/Common/Entity/Worksheet.php +++ b/src/Spout/Writer/Common/Entity/Worksheet.php @@ -5,15 +5,13 @@ namespace Box\Spout\Writer\Common\Entity; /** * Class Worksheet * Entity describing a Worksheet - * - * @package Box\Spout\Writer\Common\Entity */ class Worksheet { /** @var string Path to the XML file that will contain the sheet data */ private $filePath; - /** @var Resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */ + /** @var resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */ private $filePointer; /** @var Sheet The "external" sheet */ @@ -49,7 +47,7 @@ class Worksheet } /** - * @return Resource + * @return resource */ public function getFilePointer() { @@ -57,7 +55,7 @@ class Worksheet } /** - * @param Resource $filePointer + * @param resource $filePointer */ public function setFilePointer($filePointer) { @@ -112,4 +110,4 @@ class Worksheet // sheet index is zero-based, while ID is 1-based return $this->externalSheet->getIndex() + 1; } -} \ No newline at end of file +} diff --git a/src/Spout/Writer/Common/Helper/CellHelper.php b/src/Spout/Writer/Common/Helper/CellHelper.php index 50ead93..df935a0 100644 --- a/src/Spout/Writer/Common/Helper/CellHelper.php +++ b/src/Spout/Writer/Common/Helper/CellHelper.php @@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Helper; /** * Class CellHelper * This class provides helper functions when working with cells - * - * @package Box\Spout\Writer\Common\Helper */ class CellHelper { @@ -36,8 +34,7 @@ class CellHelper $cellIndex = chr($capitalAAsciiValue + $modulus) . $cellIndex; // substracting 1 because it's zero-based - $columnIndex = intval($columnIndex / 26) - 1; - + $columnIndex = (int) ($columnIndex / 26) - 1; } while ($columnIndex >= 0); self::$columnIndexToCellIndexCache[$originalColumnIndex] = $cellIndex; @@ -74,6 +71,7 @@ class CellHelper public static function isNumeric($value) { $valueType = gettype($value); + return ($valueType === 'integer' || $valueType === 'double'); } diff --git a/src/Spout/Writer/Common/Helper/FileSystemWithRootFolderHelperInterface.php b/src/Spout/Writer/Common/Helper/FileSystemWithRootFolderHelperInterface.php index 8e7a7a5..79cd440 100644 --- a/src/Spout/Writer/Common/Helper/FileSystemWithRootFolderHelperInterface.php +++ b/src/Spout/Writer/Common/Helper/FileSystemWithRootFolderHelperInterface.php @@ -2,22 +2,20 @@ namespace Box\Spout\Writer\Common\Helper; -use \Box\Spout\Common\Helper\FileSystemHelperInterface; +use Box\Spout\Common\Helper\FileSystemHelperInterface; /** * Class FileSystemHelperInterface * This interface describes helper functions to help with the file system operations * like files/folders creation & deletion - * - * @package Box\Spout\Writer\Common\Helper */ interface FileSystemWithRootFolderHelperInterface extends FileSystemHelperInterface { /** * Creates all the folders needed to create a spreadsheet, 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(); diff --git a/src/Spout/Writer/Common/Helper/ZipHelper.php b/src/Spout/Writer/Common/Helper/ZipHelper.php index 95130d7..e970571 100644 --- a/src/Spout/Writer/Common/Helper/ZipHelper.php +++ b/src/Spout/Writer/Common/Helper/ZipHelper.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Creator\EntityFactory; /** * Class ZipHelper * This class provides helper functions to create zip files - * - * @package Box\Spout\Writer\Common\Helper */ class ZipHelper { @@ -40,7 +38,7 @@ class ZipHelper $zip = $this->entityFactory->createZipArchive(); $zipFilePath = $tmpFolderPath . self::ZIP_EXTENSION; - $zip->open($zipFilePath, \ZipArchive::CREATE|\ZipArchive::OVERWRITE); + $zip->open($zipFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); return $zip; } @@ -184,6 +182,7 @@ class ZipHelper protected function getNormalizedRealPath($path) { $realPath = realpath($path); + return str_replace(DIRECTORY_SEPARATOR, '/', $realPath); } diff --git a/src/Spout/Writer/Common/Manager/SheetManager.php b/src/Spout/Writer/Common/Manager/SheetManager.php index 723cbe2..708137c 100644 --- a/src/Spout/Writer/Common/Manager/SheetManager.php +++ b/src/Spout/Writer/Common/Manager/SheetManager.php @@ -9,8 +9,6 @@ use Box\Spout\Writer\Exception\InvalidSheetNameException; /** * Class SheetManager * Sheet manager - * - * @package Box\Spout\Writer\Common\Manager */ class SheetManager { @@ -42,8 +40,8 @@ class SheetManager * * @param string $name * @param Sheet $sheet The sheet whose future name is checked - * @return void * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. + * @return void */ public function throwIfNameIsInvalid($name, Sheet $sheet) { diff --git a/src/Spout/Writer/Common/Manager/Style/StyleManager.php b/src/Spout/Writer/Common/Manager/Style/StyleManager.php index 1f64166..14a4c7e 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleManager.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleManager.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleManager * Manages styles to be applied to a cell - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleManager implements StyleManagerInterface { @@ -57,6 +55,7 @@ class StyleManager implements StyleManagerInterface public function applyExtraStylesIfNeeded($style, $dataRow) { $updatedStyle = $this->applyWrapTextIfCellContainsNewLine($style, $dataRow); + return $updatedStyle; } diff --git a/src/Spout/Writer/Common/Manager/Style/StyleManagerInterface.php b/src/Spout/Writer/Common/Manager/Style/StyleManagerInterface.php index f9f7349..70de0ef 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleManagerInterface.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleManagerInterface.php @@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Interface StyleHManagernterface - * - * @package Box\Spout\Writer\Common\Manager\Style */ interface StyleManagerInterface { diff --git a/src/Spout/Writer/Common/Manager/Style/StyleMerger.php b/src/Spout/Writer/Common/Manager/Style/StyleMerger.php index b59e358..d254091 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleMerger.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleMerger.php @@ -2,15 +2,11 @@ namespace Box\Spout\Writer\Common\Manager\Style; -use Box\Spout\Writer\Common\Entity\Style\Color; use Box\Spout\Writer\Common\Entity\Style\Style; -use Box\Spout\Writer\XLSX\Helper\BorderHelper; /** * Class StyleMerger * Takes care of merging styles together - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleMerger { diff --git a/src/Spout/Writer/Common/Manager/Style/StyleRegistry.php b/src/Spout/Writer/Common/Manager/Style/StyleRegistry.php index 4a25cba..e817123 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleRegistry.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleRegistry.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleRegistry * Registry for all used styles - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleRegistry { @@ -72,6 +70,7 @@ class StyleRegistry protected function getStyleFromSerializedStyle($serializedStyle) { $styleId = $this->serializedStyleToStyleIdMappingTable[$serializedStyle]; + return $this->styleIdToStyleMappingTable[$styleId]; } diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php index c9fd024..b4308bb 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php @@ -4,23 +4,21 @@ namespace Box\Spout\Writer\Common\Manager; use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Manager\OptionsManagerInterface; +use Box\Spout\Writer\Common\Creator\EntityFactory; use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface; -use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface; use Box\Spout\Writer\Common\Entity\Options; -use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface; use Box\Spout\Writer\Common\Entity\Sheet; +use Box\Spout\Writer\Common\Entity\Style\Style; use Box\Spout\Writer\Common\Entity\Workbook; use Box\Spout\Writer\Common\Entity\Worksheet; +use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface; +use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface; use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\WriterException; -use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class WorkbookManagerAbstract * Abstract workbook manager, providing the generic interfaces to work with workbook. - * - * @package Box\Spout\Writer\Common\Manager */ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface { @@ -48,7 +46,6 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface /** @var Worksheet The worksheet where data will be written to */ protected $currentWorksheet; - /** * @param Workbook $workbook * @param OptionsManagerInterface $optionsManager @@ -65,8 +62,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface StyleManagerInterface $styleManager, FileSystemWithRootFolderHelperInterface $fileSystemHelper, EntityFactory $entityFactory, - ManagerFactoryInterface $managerFactory) - { + ManagerFactoryInterface $managerFactory + ) { $this->workbook = $workbook; $this->optionManager = $optionsManager; $this->worksheetManager = $worksheetManager; @@ -99,8 +96,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface * Creates a new sheet in the workbook and make it the current sheet. * The writing will resume where it stopped (i.e. data won't be truncated). * - * @return Worksheet The created sheet * @throws IOException If unable to open the sheet for writing + * @return Worksheet The created sheet */ public function addNewSheetAndMakeItCurrent() { @@ -113,8 +110,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface /** * Creates a new sheet in the workbook. The current sheet remains unchanged. * - * @return Worksheet The created sheet * @throws \Box\Spout\Common\Exception\IOException If unable to open the sheet for writing + * @return Worksheet The created sheet */ private function addNewSheet() { @@ -158,8 +155,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface * The writing will resume where it stopped (i.e. data won't be truncated). * * @param Sheet $sheet The "external" sheet to set as current - * @return void * @throws SheetNotFoundException If the given sheet does not exist in the workbook + * @return void */ public function setCurrentSheet(Sheet $sheet) { @@ -208,9 +205,9 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface * @param array $dataRow Array containing data to be written. Cannot be empty. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param Style $style Style to be applied to the row. - * @return void * @throws IOException If trying to create a new sheet and unable to open the sheet for writing * @throws WriterException If unable to write data + * @return void */ public function addRowToCurrentWorksheet($dataRow, Style $style) { @@ -238,6 +235,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface private function hasCurrentWorkseetReachedMaxRows() { $currentWorksheet = $this->getCurrentWorksheet(); + return ($currentWorksheet->getLastWrittenRowIndex() >= $this->getMaxRowsPerWorksheet()); } @@ -248,8 +246,8 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface * @param array $dataRow Array containing data to be written. Cannot be empty. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param Style $style Style to be applied to the row. - * @return void * @throws WriterException If unable to write data + * @return void */ private function addRowWithStyleToWorksheet(Worksheet $worksheet, $dataRow, Style $style) { diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php index dfaf263..dbc5780 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php @@ -4,17 +4,15 @@ namespace Box\Spout\Writer\Common\Manager; use Box\Spout\Common\Exception\IOException; use Box\Spout\Writer\Common\Entity\Sheet; +use Box\Spout\Writer\Common\Entity\Style\Style; use Box\Spout\Writer\Common\Entity\Workbook; use Box\Spout\Writer\Common\Entity\Worksheet; use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\WriterException; -use Box\Spout\Writer\Common\Entity\Style\Style; /** * Interface WorkbookManagerInterface * workbook manager interface, providing the generic interfaces to work with workbook. - * - * @package Box\Spout\Writer\Common\Manager */ interface WorkbookManagerInterface { @@ -27,8 +25,8 @@ interface WorkbookManagerInterface * Creates a new sheet in the workbook and make it the current sheet. * The writing will resume where it stopped (i.e. data won't be truncated). * - * @return Worksheet The created sheet * @throws IOException If unable to open the sheet for writing + * @return Worksheet The created sheet */ public function addNewSheetAndMakeItCurrent(); @@ -49,8 +47,8 @@ interface WorkbookManagerInterface * The writing will resume where it stopped (i.e. data won't be truncated). * * @param Sheet $sheet The "external" sheet to set as current - * @return void * @throws SheetNotFoundException If the given sheet does not exist in the workbook + * @return void */ public function setCurrentSheet(Sheet $sheet); @@ -62,9 +60,9 @@ interface WorkbookManagerInterface * @param array $dataRow Array containing data to be written. Cannot be empty. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param Style $style Style to be applied to the row. - * @return void * @throws IOException If trying to create a new sheet and unable to open the sheet for writing * @throws WriterException If unable to write data + * @return void */ public function addRowToCurrentWorksheet($dataRow, Style $style); @@ -77,4 +75,4 @@ interface WorkbookManagerInterface * @return void */ public function close($finalFilePointer); -} \ No newline at end of file +} diff --git a/src/Spout/Writer/Common/Manager/WorksheetManagerInterface.php b/src/Spout/Writer/Common/Manager/WorksheetManagerInterface.php index 8f41559..70e6bd5 100644 --- a/src/Spout/Writer/Common/Manager/WorksheetManagerInterface.php +++ b/src/Spout/Writer/Common/Manager/WorksheetManagerInterface.php @@ -2,14 +2,12 @@ namespace Box\Spout\Writer\Common\Manager; -use Box\Spout\Writer\Common\Entity\Worksheet; use Box\Spout\Writer\Common\Entity\Style\Style; +use Box\Spout\Writer\Common\Entity\Worksheet; /** * Interface WorksheetManagerInterface * Inteface for worksheet managers, providing the generic interfaces to work with worksheets. - * - * @package Box\Spout\Writer\Common\Manager */ interface WorksheetManagerInterface { @@ -20,9 +18,9 @@ interface 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 \Box\Spout\Common\Exception\IOException If the data cannot be written * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported + * @return void */ public function addRow(Worksheet $worksheet, $dataRow, $rowStyle); @@ -30,8 +28,8 @@ interface 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); @@ -42,4 +40,4 @@ interface WorksheetManagerInterface * @return void */ public function close(Worksheet $worksheet); -} \ No newline at end of file +} diff --git a/src/Spout/Writer/Exception/Border/InvalidNameException.php b/src/Spout/Writer/Exception/Border/InvalidNameException.php index 329323a..0807298 100644 --- a/src/Spout/Writer/Exception/Border/InvalidNameException.php +++ b/src/Spout/Writer/Exception/Border/InvalidNameException.php @@ -2,8 +2,8 @@ namespace Box\Spout\Writer\Exception\Border; -use Box\Spout\Writer\Exception\WriterException; use Box\Spout\Writer\Common\Entity\Style\BorderPart; +use Box\Spout\Writer\Exception\WriterException; class InvalidNameException extends WriterException { diff --git a/src/Spout/Writer/Exception/Border/InvalidStyleException.php b/src/Spout/Writer/Exception/Border/InvalidStyleException.php index f3261f0..2efbded 100644 --- a/src/Spout/Writer/Exception/Border/InvalidStyleException.php +++ b/src/Spout/Writer/Exception/Border/InvalidStyleException.php @@ -2,8 +2,8 @@ namespace Box\Spout\Writer\Exception\Border; -use Box\Spout\Writer\Exception\WriterException; use Box\Spout\Writer\Common\Entity\Style\BorderPart; +use Box\Spout\Writer\Exception\WriterException; class InvalidStyleException extends WriterException { diff --git a/src/Spout/Writer/Exception/Border/InvalidWidthException.php b/src/Spout/Writer/Exception/Border/InvalidWidthException.php index 0f24faf..9fae1ea 100644 --- a/src/Spout/Writer/Exception/Border/InvalidWidthException.php +++ b/src/Spout/Writer/Exception/Border/InvalidWidthException.php @@ -2,8 +2,8 @@ namespace Box\Spout\Writer\Exception\Border; -use Box\Spout\Writer\Exception\WriterException; use Box\Spout\Writer\Common\Entity\Style\BorderPart; +use Box\Spout\Writer\Exception\WriterException; class InvalidWidthException extends WriterException { diff --git a/src/Spout/Writer/Exception/InvalidColorException.php b/src/Spout/Writer/Exception/InvalidColorException.php index 49b4a0d..b4428f2 100644 --- a/src/Spout/Writer/Exception/InvalidColorException.php +++ b/src/Spout/Writer/Exception/InvalidColorException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception; * Class InvalidColorException * * @api - * @package Box\Spout\Writer\Exception */ class InvalidColorException extends WriterException { diff --git a/src/Spout/Writer/Exception/InvalidSheetNameException.php b/src/Spout/Writer/Exception/InvalidSheetNameException.php index ae0663e..6a5f934 100644 --- a/src/Spout/Writer/Exception/InvalidSheetNameException.php +++ b/src/Spout/Writer/Exception/InvalidSheetNameException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception; * Class InvalidSheetNameException * * @api - * @package Box\Spout\Writer\Exception */ class InvalidSheetNameException extends WriterException { diff --git a/src/Spout/Writer/Exception/SheetNotFoundException.php b/src/Spout/Writer/Exception/SheetNotFoundException.php index c0ded5a..bc6aaa9 100644 --- a/src/Spout/Writer/Exception/SheetNotFoundException.php +++ b/src/Spout/Writer/Exception/SheetNotFoundException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception; * Class SheetNotFoundException * * @api - * @package Box\Spout\Writer\Exception */ class SheetNotFoundException extends WriterException { diff --git a/src/Spout/Writer/Exception/WriterAlreadyOpenedException.php b/src/Spout/Writer/Exception/WriterAlreadyOpenedException.php index 657d611..8e049c8 100644 --- a/src/Spout/Writer/Exception/WriterAlreadyOpenedException.php +++ b/src/Spout/Writer/Exception/WriterAlreadyOpenedException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception; * Class WriterAlreadyOpenedException * * @api - * @package Box\Spout\Writer\Exception */ class WriterAlreadyOpenedException extends WriterException { diff --git a/src/Spout/Writer/Exception/WriterException.php b/src/Spout/Writer/Exception/WriterException.php index 3d1fa60..72ab1bd 100644 --- a/src/Spout/Writer/Exception/WriterException.php +++ b/src/Spout/Writer/Exception/WriterException.php @@ -7,7 +7,6 @@ use Box\Spout\Common\Exception\SpoutException; /** * Class WriterException * - * @package Box\Spout\Writer\Exception * @abstract */ abstract class WriterException extends SpoutException diff --git a/src/Spout/Writer/Exception/WriterNotOpenedException.php b/src/Spout/Writer/Exception/WriterNotOpenedException.php index 5b08477..518cf2b 100644 --- a/src/Spout/Writer/Exception/WriterNotOpenedException.php +++ b/src/Spout/Writer/Exception/WriterNotOpenedException.php @@ -6,7 +6,6 @@ namespace Box\Spout\Writer\Exception; * Class WriterNotOpenedException * * @api - * @package Box\Spout\Writer\Exception */ class WriterNotOpenedException extends WriterException { diff --git a/src/Spout/Writer/ODS/Creator/HelperFactory.php b/src/Spout/Writer/ODS/Creator/HelperFactory.php index decbe81..bcb64b5 100644 --- a/src/Spout/Writer/ODS/Creator/HelperFactory.php +++ b/src/Spout/Writer/ODS/Creator/HelperFactory.php @@ -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 { diff --git a/src/Spout/Writer/ODS/Creator/ManagerFactory.php b/src/Spout/Writer/ODS/Creator/ManagerFactory.php index e7bc2e7..ca84657 100644 --- a/src/Spout/Writer/ODS/Creator/ManagerFactory.php +++ b/src/Spout/Writer/ODS/Creator/ManagerFactory.php @@ -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); } } diff --git a/src/Spout/Writer/ODS/Helper/BorderHelper.php b/src/Spout/Writer/ODS/Helper/BorderHelper.php index a619ffd..101bb4c 100644 --- a/src/Spout/Writer/ODS/Helper/BorderHelper.php +++ b/src/Spout/Writer/ODS/Helper/BorderHelper.php @@ -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', diff --git a/src/Spout/Writer/ODS/Helper/FileSystemHelper.php b/src/Spout/Writer/ODS/Helper/FileSystemHelper.php index 661a8ca..65ed815 100644 --- a/src/Spout/Writer/ODS/Helper/FileSystemHelper.php +++ b/src/Spout/Writer/ODS/Helper/FileSystemHelper.php @@ -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 = << @@ -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; @@ -253,10 +254,10 @@ EOD; public function deleteWorksheetTempFolder() { $this->deleteFolderRecursively($this->sheetsContentTempFolder); + return $this; } - /** * Creates the "styles.xml" file under the root folder * diff --git a/src/Spout/Writer/ODS/Manager/OptionsManager.php b/src/Spout/Writer/ODS/Manager/OptionsManager.php index ccc81b9..4d29928 100644 --- a/src/Spout/Writer/ODS/Manager/OptionsManager.php +++ b/src/Spout/Writer/ODS/Manager/OptionsManager.php @@ -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() { diff --git a/src/Spout/Writer/ODS/Manager/Style/StyleManager.php b/src/Spout/Writer/ODS/Manager/Style/StyleManager.php index 0a9519e..c658b18 100644 --- a/src/Spout/Writer/ODS/Manager/Style/StyleManager.php +++ b/src/Spout/Writer/ODS/Manager/Style/StyleManager.php @@ -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; @@ -34,7 +32,7 @@ EOD; $content .= $this->getAutomaticStylesSectionContent($numWorksheets); $content .= $this->getMasterStylesSectionContent($numWorksheets); - $content .= << EOD; @@ -132,7 +130,6 @@ EOD; return $content; } - /** * Returns the contents of the "" section, inside "content.xml" file. * @@ -163,7 +160,7 @@ EOD; $content .= $this->getStyleSectionContent($style); } - $content .= << diff --git a/src/Spout/Writer/ODS/Manager/Style/StyleRegistry.php b/src/Spout/Writer/ODS/Manager/Style/StyleRegistry.php index 89c3af0..8d4f504 100644 --- a/src/Spout/Writer/ODS/Manager/Style/StyleRegistry.php +++ b/src/Spout/Writer/ODS/Manager/Style/StyleRegistry.php @@ -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 { diff --git a/src/Spout/Writer/ODS/Manager/WorkbookManager.php b/src/Spout/Writer/ODS/Manager/WorkbookManager.php index c95d90b..367c281 100644 --- a/src/Spout/Writer/ODS/Manager/WorkbookManager.php +++ b/src/Spout/Writer/ODS/Manager/WorkbookManager.php @@ -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); } -} \ No newline at end of file +} diff --git a/src/Spout/Writer/ODS/Manager/WorksheetManager.php b/src/Spout/Writer/ODS/Manager/WorksheetManager.php index dff564f..a0562b2 100644 --- a/src/Spout/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Spout/Writer/ODS/Manager/WorksheetManager.php @@ -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 .= ''; - } else if ($cell->isBoolean()) { + } elseif ($cell->isBoolean()) { $data .= ' office:value-type="boolean" calcext:value-type="boolean" office:boolean-value="' . $cell->getValue() . '">'; $data .= '' . $cell->getValue() . ''; $data .= ''; - } else if ($cell->isNumeric()) { + } elseif ($cell->isNumeric()) { $data .= ' office:value-type="float" calcext:value-type="float" office:value="' . $cell->getValue() . '">'; $data .= '' . $cell->getValue() . ''; $data .= ''; - } else if ($cell->isEmpty()) { + } elseif ($cell->isEmpty()) { $data .= '/>'; } else { throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cell->getValue())); diff --git a/src/Spout/Writer/ODS/Writer.php b/src/Spout/Writer/ODS/Writer.php index e753c79..9a05cf9 100644 --- a/src/Spout/Writer/ODS/Writer.php +++ b/src/Spout/Writer/ODS/Writer.php @@ -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; } } diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index 2cb4a00..0cdebf4 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -7,9 +7,9 @@ use Box\Spout\Common\Exception\InvalidArgumentException; use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Exception\SpoutException; use Box\Spout\Common\Helper\GlobalFunctionsHelper; +use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Style\Style; -use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Manager\Style\StyleMerger; use Box\Spout\Writer\Exception\WriterAlreadyOpenedException; use Box\Spout\Writer\Exception\WriterNotOpenedException; @@ -17,7 +17,6 @@ use Box\Spout\Writer\Exception\WriterNotOpenedException; /** * Class WriterAbstract * - * @package Box\Spout\Writer * @abstract */ abstract class WriterAbstract implements WriterInterface @@ -59,8 +58,8 @@ abstract class WriterAbstract implements WriterInterface OptionsManagerInterface $optionsManager, StyleMerger $styleMerger, GlobalFunctionsHelper $globalFunctionsHelper, - HelperFactory $helperFactory) - { + HelperFactory $helperFactory + ) { $this->optionsManager = $optionsManager; $this->styleMerger = $styleMerger; $this->globalFunctionsHelper = $globalFunctionsHelper; @@ -72,8 +71,8 @@ abstract class WriterAbstract implements WriterInterface /** * Opens the streamer and makes it ready to accept data. * - * @return void * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened + * @return void */ abstract protected function openWriter(); @@ -106,6 +105,7 @@ abstract class WriterAbstract implements WriterInterface { $this->optionsManager->setOption(Options::DEFAULT_ROW_STYLE, $defaultStyle); $this->resetRowStyleToDefault(); + return $this; } @@ -115,8 +115,8 @@ abstract class WriterAbstract implements WriterInterface * * @api * @param string $outputFilePath Path of the output file that will contain the data - * @return WriterAbstract * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable + * @return WriterAbstract */ public function openToFile($outputFilePath) { @@ -139,8 +139,8 @@ abstract class WriterAbstract implements WriterInterface * * @api * @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept - * @return WriterAbstract * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened + * @return WriterAbstract */ public function openToBrowser($outputFileName) { @@ -177,8 +177,8 @@ abstract class WriterAbstract implements WriterInterface * Checks if the pointer to the file/stream to write to is available. * Will throw an exception if not available. * - * @return void * @throws \Box\Spout\Common\Exception\IOException If the pointer is not available + * @return void */ protected function throwIfFilePointerIsNotAvailable() { @@ -192,8 +192,8 @@ abstract class WriterAbstract implements WriterInterface * Throws an exception if already opened. * * @param string $message Error message - * @return void * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened and must not be. + * @return void */ protected function throwIfWriterAlreadyOpened($message) { @@ -209,10 +209,10 @@ abstract class WriterAbstract implements WriterInterface * If empty, no data is added (i.e. not even as a blank row) * Example: $dataRow = ['data1', 1234, null, '', 'data5', false]; * @api - * @return WriterAbstract * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data * @throws \Box\Spout\Common\Exception\SpoutException If anything else goes wrong while writing data + * @return WriterAbstract */ public function addRow(array $dataRow) { @@ -244,10 +244,10 @@ abstract class WriterAbstract implements WriterInterface * @api * @param array $dataRow Array of array containing data to be streamed. * @param Style $style Style to be applied to the row. - * @return WriterAbstract * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterAbstract */ public function addRowWithStyle(array $dataRow, $style) { @@ -272,10 +272,10 @@ abstract class WriterAbstract implements WriterInterface * ['data11', 12, , '', 'data13'], * ['data21', 'data22', null, false], * ]; - * @return WriterAbstract * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterAbstract */ public function addRows(array $dataRows) { @@ -300,10 +300,10 @@ abstract class WriterAbstract implements WriterInterface * @api * @param array $dataRows Array of array containing data to be streamed. * @param Style $style Style to be applied to the rows. - * @return WriterAbstract * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterAbstract */ public function addRowsWithStyle(array $dataRows, $style) { diff --git a/src/Spout/Writer/WriterFactory.php b/src/Spout/Writer/WriterFactory.php index 85a680d..8395b29 100644 --- a/src/Spout/Writer/WriterFactory.php +++ b/src/Spout/Writer/WriterFactory.php @@ -14,8 +14,6 @@ use Box\Spout\Writer\Common\Manager\Style\StyleMerger; * Class WriterFactory * This factory is used to create writers, based on the type of the file to be read. * It supports CSV, XLSX and ODS formats. - * - * @package Box\Spout\Writer */ class WriterFactory { @@ -24,8 +22,8 @@ class WriterFactory * * @api * @param string $writerType Type of the writer to instantiate - * @return WriterInterface * @throws \Box\Spout\Common\Exception\UnsupportedTypeException + * @return WriterInterface */ public static function create($writerType) { diff --git a/src/Spout/Writer/WriterInterface.php b/src/Spout/Writer/WriterInterface.php index d9dee14..375dbd9 100644 --- a/src/Spout/Writer/WriterInterface.php +++ b/src/Spout/Writer/WriterInterface.php @@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Interface WriterInterface - * - * @package Box\Spout\Writer */ interface WriterInterface { @@ -16,8 +14,8 @@ interface WriterInterface * By using this method, the data will be written to a file. * * @param string $outputFilePath Path of the output file that will contain the data - * @return WriterInterface * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable + * @return WriterInterface */ public function openToFile($outputFilePath); @@ -26,8 +24,8 @@ interface WriterInterface * By using this method, the data will be outputted directly to the browser. * * @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept - * @return WriterInterface * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened + * @return WriterInterface */ public function openToBrowser($outputFileName); @@ -36,9 +34,9 @@ interface WriterInterface * * @param array $dataRow Array containing data to be streamed. * Example $dataRow = ['data1', 1234, null, '', 'data5']; - * @return WriterInterface * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yetthe writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterInterface */ public function addRow(array $dataRow); @@ -48,10 +46,10 @@ interface WriterInterface * * @param array $dataRow Array of array containing data to be streamed. * @param Style $style Style to be applied to the row. - * @return WriterInterface * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterInterface */ public function addRowWithStyle(array $dataRow, $style); @@ -63,10 +61,10 @@ interface WriterInterface * ['data11', 12, , '', 'data13'], * ['data21', 'data22', null], * ]; - * @return WriterInterface * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterInterface */ public function addRows(array $dataRows); @@ -76,10 +74,10 @@ interface WriterInterface * * @param array $dataRows Array of array containing data to be streamed. * @param Style $style Style to be applied to the rows. - * @return WriterInterface * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return WriterInterface */ public function addRowsWithStyle(array $dataRows, $style); diff --git a/src/Spout/Writer/WriterMultiSheetsAbstract.php b/src/Spout/Writer/WriterMultiSheetsAbstract.php index 7ecab1a..763df12 100644 --- a/src/Spout/Writer/WriterMultiSheetsAbstract.php +++ b/src/Spout/Writer/WriterMultiSheetsAbstract.php @@ -4,21 +4,20 @@ namespace Box\Spout\Writer; use Box\Spout\Common\Creator\HelperFactory; use Box\Spout\Common\Helper\GlobalFunctionsHelper; -use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Common\Manager\OptionsManagerInterface; +use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface; use Box\Spout\Writer\Common\Entity\Options; +use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Writer\Common\Entity\Worksheet; use Box\Spout\Writer\Common\Manager\Style\StyleMerger; +use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface; use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\WriterAlreadyOpenedException; use Box\Spout\Writer\Exception\WriterNotOpenedException; -use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface; -use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface; /** * Class WriterMultiSheetsAbstract * - * @package Box\Spout\Writer * @abstract */ abstract class WriterMultiSheetsAbstract extends WriterAbstract @@ -41,8 +40,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract StyleMerger $styleMerger, GlobalFunctionsHelper $globalFunctionsHelper, HelperFactory $helperFactory, - ManagerFactoryInterface $managerFactory) - { + ManagerFactoryInterface $managerFactory + ) { parent::__construct($optionsManager, $styleMerger, $globalFunctionsHelper, $helperFactory); $this->managerFactory = $managerFactory; } @@ -53,22 +52,23 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * * @api * @param bool $shouldCreateNewSheetsAutomatically Whether new sheets should be automatically created when the max rows limit per sheet is reached - * @return WriterMultiSheetsAbstract * @throws WriterAlreadyOpenedException If the writer was already opened + * @return WriterMultiSheetsAbstract */ public function setShouldCreateNewSheetsAutomatically($shouldCreateNewSheetsAutomatically) { $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.'); $this->optionsManager->setOption(Options::SHOULD_CREATE_NEW_SHEETS_AUTOMATICALLY, $shouldCreateNewSheetsAutomatically); + return $this; } /** * Configures the write and sets the current sheet pointer to a new sheet. * - * @return void * @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing + * @return void */ protected function openWriter() { @@ -82,8 +82,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * Returns all the workbook's sheets * * @api - * @return Sheet[] All the workbook's sheets * @throws WriterNotOpenedException If the writer has not been opened yet + * @return Sheet[] All the workbook's sheets */ public function getSheets() { @@ -104,8 +104,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * Creates a new sheet and make it the current sheet. The data will now be written to this sheet. * * @api - * @return Sheet The created sheet * @throws WriterNotOpenedException If the writer has not been opened yet + * @return Sheet The created sheet */ public function addNewSheetAndMakeItCurrent() { @@ -119,12 +119,13 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * Returns the current sheet * * @api - * @return Sheet The current sheet * @throws WriterNotOpenedException If the writer has not been opened yet + * @return Sheet The current sheet */ public function getCurrentSheet() { $this->throwIfWorkbookIsNotAvailable(); + return $this->workbookManager->getCurrentWorksheet()->getExternalSheet(); } @@ -134,9 +135,9 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * * @api * @param Sheet $sheet The sheet to set as current - * @return void * @throws WriterNotOpenedException If the writer has not been opened yet * @throws SheetNotFoundException If the given sheet does not exist in the workbook + * @return void */ public function setCurrentSheet($sheet) { @@ -147,8 +148,8 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract /** * Checks if the workbook has been created. Throws an exception if not created yet. * - * @return void * @throws WriterNotOpenedException If the workbook is not created yet + * @return void */ protected function throwIfWorkbookIsNotAvailable() { @@ -165,9 +166,9 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract * @param array $dataRow Array containing data to be written. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param \Box\Spout\Writer\Common\Entity\Style\Style $style Style to be applied to the row. - * @return void * @throws WriterNotOpenedException If the book is not created yet * @throws \Box\Spout\Common\Exception\IOException If unable to write data + * @return void */ protected function addRowToWriter(array $dataRow, $style) { @@ -187,4 +188,3 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract } } } - diff --git a/src/Spout/Writer/XLSX/Creator/HelperFactory.php b/src/Spout/Writer/XLSX/Creator/HelperFactory.php index 1272c74..8eea878 100644 --- a/src/Spout/Writer/XLSX/Creator/HelperFactory.php +++ b/src/Spout/Writer/XLSX/Creator/HelperFactory.php @@ -4,17 +4,15 @@ namespace Box\Spout\Writer\XLSX\Creator; 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\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\XLSX\Helper\FileSystemHelper; /** * Class HelperFactory * Factory for helpers needed by the XLSX Writer - * - * @package Box\Spout\Writer\XLSX\Creator */ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory { diff --git a/src/Spout/Writer/XLSX/Creator/ManagerFactory.php b/src/Spout/Writer/XLSX/Creator/ManagerFactory.php index f8d413c..b8d1f07 100644 --- a/src/Spout/Writer/XLSX/Creator/ManagerFactory.php +++ b/src/Spout/Writer/XLSX/Creator/ManagerFactory.php @@ -2,10 +2,10 @@ namespace Box\Spout\Writer\XLSX\Creator; +use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Creator\EntityFactory; use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface; use Box\Spout\Writer\Common\Entity\Options; -use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Manager\SheetManager; use Box\Spout\Writer\XLSX\Manager\SharedStringsManager; use Box\Spout\Writer\XLSX\Manager\Style\StyleManager; @@ -16,8 +16,6 @@ use Box\Spout\Writer\XLSX\Manager\WorksheetManager; /** * Class ManagerFactory * Factory for managers needed by the XLSX Writer - * - * @package Box\Spout\Writer\XLSX\Creator */ class ManagerFactory implements ManagerFactoryInterface { @@ -75,8 +73,7 @@ class ManagerFactory implements ManagerFactoryInterface OptionsManagerInterface $optionsManager, StyleManager $styleManager, SharedStringsManager $sharedStringsManager - ) - { + ) { $stringsEscaper = $this->helperFactory->createStringsEscaper(); $stringsHelper = $this->helperFactory->createStringHelper(); @@ -89,6 +86,7 @@ class ManagerFactory implements ManagerFactoryInterface public function createSheetManager() { $stringHelper = $this->helperFactory->createStringHelper(); + return new SheetManager($stringHelper); } @@ -99,6 +97,7 @@ class ManagerFactory implements ManagerFactoryInterface private function createStyleManager(OptionsManagerInterface $optionsManager) { $styleRegistry = $this->createStyleRegistry($optionsManager); + return new StyleManager($styleRegistry); } @@ -109,6 +108,7 @@ class ManagerFactory implements ManagerFactoryInterface private function createStyleRegistry(OptionsManagerInterface $optionsManager) { $defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE); + return new StyleRegistry($defaultRowStyle); } @@ -119,6 +119,7 @@ class ManagerFactory implements ManagerFactoryInterface private function createSharedStringsManager($xlFolder) { $stringEscaper = $this->helperFactory->createStringsEscaper(); + return new SharedStringsManager($xlFolder, $stringEscaper); } } diff --git a/src/Spout/Writer/XLSX/Helper/BorderHelper.php b/src/Spout/Writer/XLSX/Helper/BorderHelper.php index 1b0183a..56c1d82 100644 --- a/src/Spout/Writer/XLSX/Helper/BorderHelper.php +++ b/src/Spout/Writer/XLSX/Helper/BorderHelper.php @@ -9,29 +9,29 @@ class BorderHelper { public static $xlsxStyleMap = [ Border::STYLE_SOLID => [ - Border::WIDTH_THIN => 'thin', + Border::WIDTH_THIN => 'thin', Border::WIDTH_MEDIUM => 'medium', - Border::WIDTH_THICK => 'thick' + Border::WIDTH_THICK => 'thick', ], Border::STYLE_DOTTED => [ - Border::WIDTH_THIN => 'dotted', + Border::WIDTH_THIN => 'dotted', Border::WIDTH_MEDIUM => 'dotted', - Border::WIDTH_THICK => 'dotted', + Border::WIDTH_THICK => 'dotted', ], Border::STYLE_DASHED => [ - Border::WIDTH_THIN => 'dashed', + Border::WIDTH_THIN => 'dashed', Border::WIDTH_MEDIUM => 'mediumDashed', - Border::WIDTH_THICK => 'mediumDashed', + Border::WIDTH_THICK => 'mediumDashed', ], Border::STYLE_DOUBLE => [ - Border::WIDTH_THIN => 'double', + Border::WIDTH_THIN => 'double', Border::WIDTH_MEDIUM => 'double', - Border::WIDTH_THICK => 'double', + Border::WIDTH_THICK => 'double', ], Border::STYLE_NONE => [ - Border::WIDTH_THIN => 'none', + Border::WIDTH_THIN => 'none', Border::WIDTH_MEDIUM => 'none', - Border::WIDTH_THICK => 'none', + Border::WIDTH_THICK => 'none', ], ]; diff --git a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php index c73d111..8bba670 100644 --- a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php +++ b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php @@ -11,8 +11,6 @@ use Box\Spout\Writer\XLSX\Manager\Style\StyleManager; * Class FileSystemHelper * This class provides helper functions to help with the file system operations * like files/folders creation & deletion for XLSX files - * - * @package Box\Spout\Writer\XLSX\Helper */ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper implements FileSystemWithRootFolderHelperInterface { @@ -94,8 +92,8 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme /** * Creates all the folders needed to create a XLSX 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() { @@ -109,20 +107,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 */ private function createRootFolder() { $this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('xlsx', true)); + return $this; } /** * Creates the "_rels" folder under the root folder as well as the ".rels" file in it * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the ".rels" file + * @return FileSystemHelper */ private function createRelsFolderAndFile() { @@ -136,12 +135,12 @@ class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper impleme /** * Creates the ".rels" file under the "_rels" folder (under root) * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the file + * @return FileSystemHelper */ private function createRelsFile() { - $relsFileContents = << @@ -158,8 +157,8 @@ EOD; /** * Creates the "docProps" folder under the root folder as well as the "app.xml" and "core.xml" files in it * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or one of the files + * @return FileSystemHelper */ private function createDocPropsFolderAndFiles() { @@ -174,8 +173,8 @@ EOD; /** * Creates the "app.xml" file under the "docProps" folder * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the file + * @return FileSystemHelper */ private function createAppXmlFile() { @@ -196,8 +195,8 @@ EOD; /** * Creates the "core.xml" file under the "docProps" folder * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the file + * @return FileSystemHelper */ private function createCoreXmlFile() { @@ -219,8 +218,8 @@ EOD; /** * Creates the "xl" folder under the root folder as well as its subfolders * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the folders + * @return FileSystemHelper */ private function createXlFolderAndSubFolders() { @@ -234,24 +233,26 @@ EOD; /** * Creates the "_rels" folder under the "xl" folder * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder + * @return FileSystemHelper */ private function createXlRelsFolder() { $this->xlRelsFolder = $this->createFolder($this->xlFolder, self::RELS_FOLDER_NAME); + return $this; } /** * Creates the "worksheets" folder under the "xl" folder * - * @return FileSystemHelper * @throws \Box\Spout\Common\Exception\IOException If unable to create the folder + * @return FileSystemHelper */ private function createXlWorksheetsFolder() { $this->xlWorksheetsFolder = $this->createFolder($this->xlFolder, self::WORKSHEETS_FOLDER_NAME); + return $this; } @@ -263,7 +264,7 @@ EOD; */ public function createContentTypesFile($worksheets) { - $contentTypesXmlFileContents = << @@ -271,12 +272,12 @@ EOD; EOD; - /** @var Worksheet $worksheet */ - foreach ($worksheets as $worksheet) { - $contentTypesXmlFileContents .= ''; - } + /** @var Worksheet $worksheet */ + foreach ($worksheets as $worksheet) { + $contentTypesXmlFileContents .= ''; + } - $contentTypesXmlFileContents .= << @@ -297,7 +298,7 @@ EOD; */ public function createWorkbookFile($worksheets) { - $workbookXmlFileContents = << @@ -310,7 +311,7 @@ EOD; $workbookXmlFileContents .= ''; } - $workbookXmlFileContents .= << EOD; @@ -328,7 +329,7 @@ EOD; */ public function createWorkbookRelsFile($worksheets) { - $workbookRelsXmlFileContents = << diff --git a/src/Spout/Writer/XLSX/Manager/OptionsManager.php b/src/Spout/Writer/XLSX/Manager/OptionsManager.php index 3aac2a7..53718bc 100644 --- a/src/Spout/Writer/XLSX/Manager/OptionsManager.php +++ b/src/Spout/Writer/XLSX/Manager/OptionsManager.php @@ -2,15 +2,13 @@ namespace Box\Spout\Writer\XLSX\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 * XLSX Writer options manager - * - * @package Box\Spout\Writer\XLSX\Manager */ class OptionsManager extends OptionsManagerAbstract { @@ -32,7 +30,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function getSupportedOptions() { @@ -45,7 +43,7 @@ class OptionsManager extends OptionsManagerAbstract } /** - * @inheritdoc + * {@inheritdoc} */ protected function setDefaultOptions() { diff --git a/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php b/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php index feb762b..2a60c3c 100644 --- a/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php +++ b/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php @@ -8,14 +8,12 @@ use Box\Spout\Common\Helper\Escaper; /** * Class SharedStringsManager * This class provides functions to write shared strings - * - * @package Box\Spout\Writer\XLSX\Manager */ class SharedStringsManager { const SHARED_STRINGS_FILE_NAME = 'sharedStrings.xml'; - const SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER = << EOD; @@ -58,7 +55,7 @@ EOD; $content .= $this->getCellXfsSectionContent(); $content .= $this->getCellStylesSectionContent(); - $content .= << EOD; @@ -187,7 +184,7 @@ EOD; */ protected function getCellStyleXfsSectionContent() { - return << @@ -239,7 +236,7 @@ EOD; */ protected function getCellStylesSectionContent() { - return << diff --git a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php index f91484a..8039454 100644 --- a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php +++ b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleRegistry * Registry for all used styles - * - * @package Box\Spout\Writer\XLSX\Manager\Style */ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry { @@ -80,7 +78,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry $this->registeredFills[$backgroundColor] = $styleId; $this->styleIdToFillMappingTable[$styleId] = $this->fillIndex++; } - } else { // The fillId maps a style to a fill declaration // When there is no background color definition - we default to 0 @@ -122,7 +119,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry $this->registeredBorders[$serializedBorder] = $styleId; $this->styleIdToBorderMappingTable[$styleId] = count($this->registeredBorders); } - } else { // If no border should be applied - the mapping is the default border: 0 $this->styleIdToBorderMappingTable[$styleId] = 0; diff --git a/src/Spout/Writer/XLSX/Manager/WorkbookManager.php b/src/Spout/Writer/XLSX/Manager/WorkbookManager.php index 7adfd8c..944516b 100644 --- a/src/Spout/Writer/XLSX/Manager/WorkbookManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorkbookManager.php @@ -10,8 +10,6 @@ use Box\Spout\Writer\XLSX\Manager\Style\StyleManager; /** * Class WorkbookManager * XLSX workbook manager, providing the interfaces to work with workbook. - * - * @package Box\Spout\Writer\XLSX\Manager */ class WorkbookManager extends WorkbookManagerAbstract { @@ -45,6 +43,7 @@ class WorkbookManager extends WorkbookManagerAbstract public function getWorksheetFilePath(Sheet $sheet) { $worksheetFilesFolder = $this->fileSystemHelper->getXlWorksheetsFolder(); + return $worksheetFilesFolder . '/' . strtolower($sheet->getName()) . '.xml'; } @@ -75,4 +74,4 @@ class WorkbookManager extends WorkbookManagerAbstract ->createStylesFile($this->styleManager) ->zipRootFolderAndCopyToStream($finalFilePointer); } -} \ No newline at end of file +} diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php index ab06723..8eb39f2 100644 --- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php @@ -5,21 +5,19 @@ namespace Box\Spout\Writer\XLSX\Manager; use Box\Spout\Common\Exception\InvalidArgumentException; use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Helper\StringHelper; -use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Helper\CellHelper; use Box\Spout\Common\Manager\OptionsManagerInterface; -use Box\Spout\Writer\Common\Entity\Options; +use Box\Spout\Writer\Common\Creator\EntityFactory; use Box\Spout\Writer\Common\Entity\Cell; -use Box\Spout\Writer\Common\Entity\Worksheet; -use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface; +use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Style\Style; +use Box\Spout\Writer\Common\Entity\Worksheet; +use Box\Spout\Writer\Common\Helper\CellHelper; +use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface; use Box\Spout\Writer\XLSX\Manager\Style\StyleManager; /** * Class WorksheetManager * XLSX worksheet manager, providing the interfaces to work with XLSX worksheets. - * - * @package Box\Spout\Writer\XLSX\Manager */ class WorksheetManager implements WorksheetManagerInterface { @@ -31,7 +29,7 @@ class WorksheetManager implements WorksheetManagerInterface */ const MAX_CHARACTERS_PER_CELL = 32767; - const SHEET_XML_FILE_HEADER = << EOD; @@ -70,8 +68,8 @@ EOD; SharedStringsManager $sharedStringsManager, \Box\Spout\Common\Helper\Escaper\XLSX $stringsEscaper, StringHelper $stringHelper, - EntityFactory $entityFactory) - { + EntityFactory $entityFactory + ) { $this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS); $this->styleManager = $styleManager; $this->sharedStringsManager = $sharedStringsManager; @@ -88,13 +86,12 @@ EOD; return $this->sharedStringsManager; } - /** * 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) { @@ -111,8 +108,8 @@ EOD; * 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) { @@ -128,9 +125,9 @@ EOD; * @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) { @@ -162,9 +159,9 @@ EOD; * @param array $dataRow Array containing data to be written. Cannot be empty. * Example $dataRow = ['data1', 1234, null, '', 'data5']; * @param \Box\Spout\Writer\Common\Entity\Style\Style $style Style to be applied to the row. NULL means use default style. - * @return void * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported + * @return void */ private function addNonEmptyRow(Worksheet $worksheet, $dataRow, $style) { @@ -174,7 +171,7 @@ EOD; $rowXML = ''; - foreach($dataRow as $cellValue) { + foreach ($dataRow as $cellValue) { $rowXML .= $this->getCellXML($rowIndex, $cellNumber, $cellValue, $style->getId()); $cellNumber++; } @@ -194,8 +191,8 @@ EOD; * @param int $cellNumber * @param mixed $cellValue * @param int $styleId - * @return string * @throws InvalidArgumentException If the given value cannot be processed + * @return string */ private function getCellXML($rowIndex, $cellNumber, $cellValue, $styleId) { @@ -203,7 +200,7 @@ EOD; $cellXML = 'isString()) { $cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue()); - } else if ($cell->isBoolean()) { - $cellXML .= ' t="b">' . intval($cell->getValue()) . ''; - } else if ($cell->isNumeric()) { + } elseif ($cell->isBoolean()) { + $cellXML .= ' t="b">' . (int) ($cell->getValue()) . ''; + } elseif ($cell->isNumeric()) { $cellXML .= '>' . $cell->getValue() . ''; - } else if ($cell->isEmpty()) { + } elseif ($cell->isEmpty()) { if ($this->styleManager->shouldApplyStyleOnEmptyCell($styleId)) { $cellXML .= '/>'; } else { @@ -235,8 +232,8 @@ EOD; * Returns the XML fragment for a cell containing a non empty string * * @param string $cellValue The cell value - * @return string The XML fragment representing the cell * @throws InvalidArgumentException If the string exceeds the maximum number of characters allowed per cell + * @return string The XML fragment representing the cell */ private function getCellXMLFragmentForNonEmptyString($cellValue) { diff --git a/src/Spout/Writer/XLSX/Writer.php b/src/Spout/Writer/XLSX/Writer.php index f270921..9fd3143 100644 --- a/src/Spout/Writer/XLSX/Writer.php +++ b/src/Spout/Writer/XLSX/Writer.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\WriterMultiSheetsAbstract; /** * Class Writer * This class provides base support to write data to XLSX files - * - * @package Box\Spout\Writer\XLSX */ class Writer extends WriterMultiSheetsAbstract { @@ -22,14 +20,15 @@ class Writer extends WriterMultiSheetsAbstract * * @api * @param string $tempFolder Temporary folder where the files to create the XLSX 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; } @@ -39,14 +38,15 @@ class Writer extends WriterMultiSheetsAbstract * * @api * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used - * @return Writer * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened + * @return Writer */ public function setShouldUseInlineStrings($shouldUseInlineStrings) { $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.'); $this->optionsManager->setOption(Options::SHOULD_USE_INLINE_STRINGS, $shouldUseInlineStrings); + return $this; } } diff --git a/tests/Spout/Common/Helper/EncodingHelperTest.php b/tests/Spout/Common/Helper/EncodingHelperTest.php index d142d4e..ce48d8c 100644 --- a/tests/Spout/Common/Helper/EncodingHelperTest.php +++ b/tests/Spout/Common/Helper/EncodingHelperTest.php @@ -6,8 +6,6 @@ use Box\Spout\TestUsingResource; /** * Class EncodingHelperTest - * - * @package Box\Spout\Common\Helper */ class EncodingHelperTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Common/Helper/Escaper/ODSTest.php b/tests/Spout/Common/Helper/Escaper/ODSTest.php index 02d7ded..2702cc0 100644 --- a/tests/Spout/Common/Helper/Escaper/ODSTest.php +++ b/tests/Spout/Common/Helper/Escaper/ODSTest.php @@ -6,8 +6,6 @@ use Box\Spout\Common\Helper\Escaper; /** * Class ODSTest - * - * @package Box\Spout\Common\Helper\Escaper */ class ODSTest extends \PHPUnit_Framework_TestCase { @@ -22,8 +20,8 @@ class ODSTest extends \PHPUnit_Framework_TestCase ["\n", "\n"], ["\r", "\r"], ["\t", "\t"], - ["\v", "�"], - ["\f", "�"], + ["\v", '�'], + ["\f", '�'], ]; } diff --git a/tests/Spout/Common/Helper/Escaper/XLSXTest.php b/tests/Spout/Common/Helper/Escaper/XLSXTest.php index 540cf04..f657f71 100644 --- a/tests/Spout/Common/Helper/Escaper/XLSXTest.php +++ b/tests/Spout/Common/Helper/Escaper/XLSXTest.php @@ -6,8 +6,6 @@ use Box\Spout\Common\Helper\Escaper; /** * Class XLSXTest - * - * @package Box\Spout\Common\Helper\Escaper */ class XLSXTest extends \PHPUnit_Framework_TestCase { @@ -26,8 +24,8 @@ class XLSXTest extends \PHPUnit_Framework_TestCase [chr(4), '_x0004_'], ['_x0000_', '_x005F_x0000_'], [chr(21), '_x0015_'], - ['control '.chr(21).' character', 'control _x0015_ character'], - ['control\'s '.chr(21).' "character"', 'control\'s _x0015_ "character"'], + ['control ' . chr(21) . ' character', 'control _x0015_ character'], + ['control\'s ' . chr(21) . ' "character"', 'control\'s _x0015_ "character"'], ]; } @@ -61,8 +59,8 @@ class XLSXTest extends \PHPUnit_Framework_TestCase ['_x0004_', chr(4)], ['_x005F_x0000_', '_x0000_'], ['_x0015_', chr(21)], - ['control _x0015_ character', 'control '.chr(21).' character'], - ['control's _x0015_ "character"', 'control's '.chr(21).' "character"'], + ['control _x0015_ character', 'control ' . chr(21) . ' character'], + ['control's _x0015_ "character"', 'control's ' . chr(21) . ' "character"'], ]; } diff --git a/tests/Spout/Common/Helper/FileSystemHelperTest.php b/tests/Spout/Common/Helper/FileSystemHelperTest.php index a73e7f2..52a3fdd 100644 --- a/tests/Spout/Common/Helper/FileSystemHelperTest.php +++ b/tests/Spout/Common/Helper/FileSystemHelperTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Common\Helper; /** * Class FileSystemHelperTest - * - * @package Box\Spout\Common\Helper */ class FileSystemHelperTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Common/Manager/OptionsManagerTest.php b/tests/Spout/Common/Manager/OptionsManagerTest.php index 7a205f6..c3f25f7 100644 --- a/tests/Spout/Common/Manager/OptionsManagerTest.php +++ b/tests/Spout/Common/Manager/OptionsManagerTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Common\Manager; /** * Class OptionsManagerTest - * - * @package Box\Spout\Common\Manager */ class OptionsManagerTest extends \PHPUnit_Framework_TestCase { @@ -49,7 +47,6 @@ class OptionsManagerTest extends \PHPUnit_Framework_TestCase } } - // TODO: Convert this to anonymous class when PHP < 7 support is dropped class FakeOptionsManager extends OptionsManagerAbstract { diff --git a/tests/Spout/Reader/CSV/ReaderTest.php b/tests/Spout/Reader/CSV/ReaderTest.php index e35bb5a..2a20b71 100644 --- a/tests/Spout/Reader/CSV/ReaderTest.php +++ b/tests/Spout/Reader/CSV/ReaderTest.php @@ -3,19 +3,15 @@ namespace Box\Spout\Reader\CSV; use Box\Spout\Common\Creator\HelperFactory; +use Box\Spout\Common\Helper\EncodingHelper; use Box\Spout\Common\Helper\GlobalFunctionsHelper; use Box\Spout\Reader\CSV\Creator\EntityFactory; use Box\Spout\Reader\CSV\Manager\OptionsManager; -use Box\Spout\Reader\ReaderFactory; -use Box\Spout\Common\Type; -use Box\Spout\Common\Helper\EncodingHelper; use Box\Spout\Reader\ReaderInterface; use Box\Spout\TestUsingResource; /** * Class ReaderTest - * - * @package Box\Spout\Reader\CSV */ class ReaderTest extends \PHPUnit_Framework_TestCase { @@ -79,7 +75,6 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $reader->open($resourcePath); } - /** * @return void */ @@ -144,7 +139,9 @@ class ReaderTest extends \PHPUnit_Framework_TestCase { $allRows = $this->getAllRowsForFile( 'csv_with_multiple_empty_lines.csv', - ',', '"', EncodingHelper::ENCODING_UTF8, + ',', + '"', + EncodingHelper::ENCODING_UTF8, $shouldPreserveEmptyRows = true ); @@ -379,7 +376,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['1', '2', '3'], - ['0', '0', '0'] + ['0', '0', '0'], ]; $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); } @@ -395,7 +392,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['0', '', ''], - ['1', '1', ''] + ['1', '1', ''], ]; $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); } @@ -490,8 +487,8 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $fieldDelimiter = ',', $fieldEnclosure = '"', $encoding = EncodingHelper::ENCODING_UTF8, - $shouldPreserveEmptyRows = false) - { + $shouldPreserveEmptyRows = false + ) { $allRows = []; $resourcePath = $this->getResourcePath($fileName); @@ -514,5 +511,4 @@ class ReaderTest extends \PHPUnit_Framework_TestCase return $allRows; } - } diff --git a/tests/Spout/Reader/CSV/SheetTest.php b/tests/Spout/Reader/CSV/SheetTest.php index ae18c2f..8812d89 100644 --- a/tests/Spout/Reader/CSV/SheetTest.php +++ b/tests/Spout/Reader/CSV/SheetTest.php @@ -8,8 +8,6 @@ use Box\Spout\TestUsingResource; /** * Class SheetTest - * - * @package Box\Spout\Reader\CSV */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/CSV/SpoutTestStream.php b/tests/Spout/Reader/CSV/SpoutTestStream.php index f8409bd..3bfd06e 100644 --- a/tests/Spout/Reader/CSV/SpoutTestStream.php +++ b/tests/Spout/Reader/CSV/SpoutTestStream.php @@ -6,8 +6,6 @@ namespace Box\Spout\Reader\CSV; * Class SpoutTestStream * Custom stream that reads CSV files located in the tests/resources/csv folder. * For example: spout://foobar will point to tests/resources/csv/foobar.csv - * - * @package Box\Spout\Reader\CSV */ class SpoutTestStream { @@ -30,6 +28,7 @@ class SpoutTestStream public function url_stat($path, $flag) { $filePath = $this->getFilePathFromStreamPath($path); + return stat($filePath); } @@ -40,6 +39,7 @@ class SpoutTestStream private function getFilePathFromStreamPath($streamPath) { $fileName = parse_url($streamPath, PHP_URL_HOST); + return self::PATH_TO_CSV_RESOURCES . $fileName . self::CSV_EXTENSION; } @@ -68,6 +68,7 @@ class SpoutTestStream public function stream_read($numBytes) { $this->position += $numBytes; + return fread($this->fileHandle, $numBytes); } @@ -93,7 +94,7 @@ class SpoutTestStream if ($whence === SEEK_SET) { $this->position = $offset; - } else if ($whence === SEEK_CUR) { + } elseif ($whence === SEEK_CUR) { $this->position += $offset; } else { // not implemented diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index 63810a4..7c699f6 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -9,8 +9,6 @@ use Box\Spout\TestUsingResource; /** * Class ReaderTest - * - * @package Box\Spout\Reader\ODS */ class ReaderTest extends \PHPUnit_Framework_TestCase { @@ -134,9 +132,9 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $allRows = $this->getAllRowsForFile($fileName); $expectedRows = [ - ['header1','header2','header3','header4'], - ['val11','val12','val13','val14'], - ['val21','','val23','val23'], + ['header1', 'header2', 'header3', 'header4'], + ['val11', 'val12', 'val13', 'val14'], + ['val21', '', 'val23', 'val23'], ['', 10.43, 29.11], ]; @@ -150,7 +148,6 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedRows, $allRows); } - /** * @return void */ @@ -278,7 +275,6 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals([$expectedRow], $allRows); } - /** * @NOTE: The LIBXML_NOENT is used to ACTUALLY substitute entities (and should therefore not be used) * @@ -450,7 +446,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['1', '2', '3'], - ['0', '0', '0'] + ['0', '0', '0'], ]; $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); } @@ -466,7 +462,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['0', '', ''], - ['1', '1', ''] + ['1', '1', ''], ]; $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); } @@ -513,7 +509,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $allRows = $this->getAllRowsForFile('sheet_with_inline_font_formatting.ods'); $expectedRows = [ - ['I am a yellow bird'] + ['I am a yellow bird'], ]; $this->assertEquals($expectedRows, $allRows, 'Text formatted inline should be read'); diff --git a/tests/Spout/Reader/ODS/SheetTest.php b/tests/Spout/Reader/ODS/SheetTest.php index cc3bd03..e5dfdf8 100644 --- a/tests/Spout/Reader/ODS/SheetTest.php +++ b/tests/Spout/Reader/ODS/SheetTest.php @@ -8,8 +8,6 @@ use Box\Spout\TestUsingResource; /** * Class SheetTest - * - * @package Box\Spout\Reader\ODS */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/ReaderFactoryTest.php b/tests/Spout/Reader/ReaderFactoryTest.php index 57a0b55..5bef063 100644 --- a/tests/Spout/Reader/ReaderFactoryTest.php +++ b/tests/Spout/Reader/ReaderFactoryTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader; /** * Class ReaderFactoryTest - * - * @package Box\Spout\Writer */ class ReaderFactoryTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/Wrapper/XMLReaderTest.php b/tests/Spout/Reader/Wrapper/XMLReaderTest.php index 3b22378..3f76208 100644 --- a/tests/Spout/Reader/Wrapper/XMLReaderTest.php +++ b/tests/Spout/Reader/Wrapper/XMLReaderTest.php @@ -3,12 +3,9 @@ namespace Box\Spout\Reader\Wrapper; use Box\Spout\TestUsingResource; -use Box\Spout\Reader\Exception\XMLProcessingException; /** * Class XMLReaderTest - * - * @package Box\Spout\Reader\Wrapper */ class XMLReaderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/XLSX/Helper/CellHelperTest.php b/tests/Spout/Reader/XLSX/Helper/CellHelperTest.php index a410d9d..0f9ca9d 100644 --- a/tests/Spout/Reader/XLSX/Helper/CellHelperTest.php +++ b/tests/Spout/Reader/XLSX/Helper/CellHelperTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader\XLSX\Helper; /** * Class CellHelperTest - * - * @package Box\Spout\Reader\XLSX\Helper */ class CellHelperTest extends \PHPUnit_Framework_TestCase { @@ -15,9 +13,9 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase public function dataProviderForTestFillMissingArrayIndexes() { return [ - [ null, [] ], - [ [], [] ], - [ [1 => 1, 3 => 3], ['FILL', 1, 'FILL', 3] ] + [null, []], + [[], []], + [[1 => 1, 3 => 3], ['FILL', 1, 'FILL', 3]], ]; } diff --git a/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php b/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php index 558a725..ef58574 100644 --- a/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php +++ b/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php @@ -6,8 +6,6 @@ use Box\Spout\Common\Helper\Escaper; /** * Class CellValueFormatterTest - * - * @package Box\Spout\Reader\XLSX\Helper */ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase { @@ -47,7 +45,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase ->expects($this->atLeastOnce()) ->method('item') ->with(0) - ->will($this->returnValue((object)['nodeValue' => $nodeValue])); + ->will($this->returnValue((object) ['nodeValue' => $nodeValue])); $nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock(); @@ -162,7 +160,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase ->expects($this->atLeastOnce()) ->method('item') ->with(0) - ->will($this->returnValue((object)['nodeValue' => $value])); + ->will($this->returnValue((object) ['nodeValue' => $value])); $nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock(); $nodeMock diff --git a/tests/Spout/Reader/XLSX/Helper/DateFormatHelperTest.php b/tests/Spout/Reader/XLSX/Helper/DateFormatHelperTest.php index cca02a7..5d7eef2 100644 --- a/tests/Spout/Reader/XLSX/Helper/DateFormatHelperTest.php +++ b/tests/Spout/Reader/XLSX/Helper/DateFormatHelperTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Reader\XLSX\Helper; /** * Class DateFormatHelperTest - * - * @package Box\Spout\Reader\XLSX\Helper */ class DateFormatHelperTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactoryTest.php b/tests/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactoryTest.php index 5323f01..51db365 100644 --- a/tests/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactoryTest.php +++ b/tests/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactoryTest.php @@ -6,8 +6,6 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory; /** * Class CachingStrategyFactoryTest - * - * @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching */ class CachingStrategyFactoryTest extends \PHPUnit_Framework_TestCase { @@ -21,9 +19,9 @@ class CachingStrategyFactoryTest extends \PHPUnit_Framework_TestCase [CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE, -1, 'FileBasedStrategy'], [CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE + 10, -1, 'FileBasedStrategy'], [CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE - 10, -1, 'InMemoryStrategy'], - [10 , CachingStrategyFactory::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB * 10, 'FileBasedStrategy'], + [10, CachingStrategyFactory::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB * 10, 'FileBasedStrategy'], [15, CachingStrategyFactory::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB * 10, 'FileBasedStrategy'], - [5 , CachingStrategyFactory::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB * 10, 'InMemoryStrategy'], + [5, CachingStrategyFactory::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB * 10, 'InMemoryStrategy'], ]; } diff --git a/tests/Spout/Reader/XLSX/Manager/SharedStringsManagerTest.php b/tests/Spout/Reader/XLSX/Manager/SharedStringsManagerTest.php index 51a4097..8a46345 100644 --- a/tests/Spout/Reader/XLSX/Manager/SharedStringsManagerTest.php +++ b/tests/Spout/Reader/XLSX/Manager/SharedStringsManagerTest.php @@ -12,8 +12,6 @@ use Box\Spout\TestUsingResource; /** * Class SharedStringsManagerTest - * - * @package Box\Spout\Reader\XLSX\Manager */ class SharedStringsManagerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php b/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php index 917cc5f..4127795 100644 --- a/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php +++ b/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php @@ -9,12 +9,9 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory; /** * Class StyleManagerTest - * - * @package Box\Spout\Reader\XLSX\Manager */ class StyleManagerTest extends \PHPUnit_Framework_TestCase { - /** * @param array $styleAttributes * @param array $customNumberFormats diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index b6b0313..e51f2df 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -9,8 +9,6 @@ use Box\Spout\TestUsingResource; /** * Class ReaderTest - * - * @package Box\Spout\Reader\XLSX */ class ReaderTest extends \PHPUnit_Framework_TestCase { @@ -51,7 +49,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase ['one_sheet_with_shared_strings.xlsx', 5, 5], ['one_sheet_with_inline_strings.xlsx', 5, 5], ['two_sheets_with_shared_strings.xlsx', 10, 5], - ['two_sheets_with_inline_strings.xlsx', 10, 5] + ['two_sheets_with_inline_strings.xlsx', 10, 5], ]; } @@ -236,7 +234,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase \DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-28 23:59:59'), \DateTime::createFromFormat('Y-m-d H:i:s', '1900-03-01 00:00:00'), \DateTime::createFromFormat('Y-m-d H:i:s', '1900-02-28 11:00:00'), // 1900-02-29 should be converted to 1900-02-28 - ] + ], ]; $this->assertEquals($expectedRows, $allRows); } @@ -258,7 +256,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase \DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 23:29:00'), \DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 01:42:25'), \DateTime::createFromFormat('Y-m-d H:i:s', '1900-01-01 13:42:25'), - ] + ], ]; $this->assertEquals($expectedRows, $allRows); } @@ -579,7 +577,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['1', '2', '3'], - ['0', '0', '0'] + ['0', '0', '0'], ]; $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); } @@ -595,12 +593,11 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $expectedRows = [ ['A', 'B', 'C'], ['0', '', ''], - ['1', '1', ''] + ['1', '1', ''], ]; $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); } - /** * https://github.com/box/spout/issues/195 * @return void @@ -618,7 +615,6 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed'); } - /** * @param string $fileName * @param bool $shouldFormatDates diff --git a/tests/Spout/Reader/XLSX/SheetTest.php b/tests/Spout/Reader/XLSX/SheetTest.php index b8c332b..b4291fb 100644 --- a/tests/Spout/Reader/XLSX/SheetTest.php +++ b/tests/Spout/Reader/XLSX/SheetTest.php @@ -8,8 +8,6 @@ use Box\Spout\TestUsingResource; /** * Class SheetTest - * - * @package Box\Spout\Reader\XLSX */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/ReflectionHelper.php b/tests/Spout/ReflectionHelper.php index c6d860f..c078f3b 100644 --- a/tests/Spout/ReflectionHelper.php +++ b/tests/Spout/ReflectionHelper.php @@ -5,7 +5,7 @@ */ class ReflectionHelper { - private static $privateVarsToReset = array(); + private static $privateVarsToReset = []; /** * Resets any static vars that were set to their @@ -20,7 +20,7 @@ class ReflectionHelper self::setStaticValue($class, $valueName, $originalValue, $saveOriginalValue = false); } } - self::$privateVarsToReset = array(); + self::$privateVarsToReset = []; } /** diff --git a/tests/Spout/TestUsingResource.php b/tests/Spout/TestUsingResource.php index 2b200d9..551f86b 100644 --- a/tests/Spout/TestUsingResource.php +++ b/tests/Spout/TestUsingResource.php @@ -4,8 +4,6 @@ namespace Box\Spout; /** * Trait TestUsingResource - * - * @package Box\Spout */ trait TestUsingResource { diff --git a/tests/Spout/Writer/CSV/WriterTest.php b/tests/Spout/Writer/CSV/WriterTest.php index 4fa7bfc..4f679c0 100644 --- a/tests/Spout/Writer/CSV/WriterTest.php +++ b/tests/Spout/Writer/CSV/WriterTest.php @@ -2,16 +2,14 @@ namespace Box\Spout\Writer\CSV; -use Box\Spout\TestUsingResource; -use Box\Spout\Common\Type; use Box\Spout\Common\Helper\EncodingHelper; +use Box\Spout\Common\Type; +use Box\Spout\TestUsingResource; use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\WriterFactory; /** * Class WriterTest - * - * @package Box\Spout\Writer\CSV */ class WriterTest extends \PHPUnit_Framework_TestCase { @@ -184,7 +182,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase public function testWriteShouldAcceptCellObjects() { $allRows = [ - [new Cell('String Value'), new Cell(1)] + [new Cell('String Value'), new Cell(1)], ]; $writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_cell_objects.csv'); $writtenContent = $this->trimWrittenContent($writtenContent); @@ -197,7 +195,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase * @param string $fieldDelimiter * @param string $fieldEnclosure * @param bool $shouldAddBOM - * @return null|string + * @return string|null */ private function writeToCsvFileAndReturnWrittenContent($allRows, $fileName, $fieldDelimiter = ',', $fieldEnclosure = '"', $shouldAddBOM = true) { diff --git a/tests/Spout/Writer/Common/Creator/StyleBuilderTest.php b/tests/Spout/Writer/Common/Creator/StyleBuilderTest.php index f250e8e..36e94d4 100644 --- a/tests/Spout/Writer/Common/Creator/StyleBuilderTest.php +++ b/tests/Spout/Writer/Common/Creator/StyleBuilderTest.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Manager\Style\StyleMerger; /** * Class StyleManagerTest - * - * @package Box\Spout\Writer\Common\Creator\Style */ class StyleBuilderTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/Common/Entity/SheetTest.php b/tests/Spout/Writer/Common/Entity/SheetTest.php index 37ddabf..678449e 100644 --- a/tests/Spout/Writer/Common/Entity/SheetTest.php +++ b/tests/Spout/Writer/Common/Entity/SheetTest.php @@ -7,8 +7,6 @@ use Box\Spout\Writer\Common\Manager\SheetManager; /** * Class SheetTest - * - * @package Box\Spout\Writer\Common\Entity */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/Common/Entity/Style/BorderTest.php b/tests/Spout/Writer/Common/Entity/Style/BorderTest.php index e9cd1d2..4117c91 100644 --- a/tests/Spout/Writer/Common/Entity/Style/BorderTest.php +++ b/tests/Spout/Writer/Common/Entity/Style/BorderTest.php @@ -9,8 +9,6 @@ use Box\Spout\Writer\Common\Entity\Style\Color; /** * Class BorderTest - * - * @package Box\Spout\Writer\Common\EntityStyle */ class BorderTest extends \PHPUnit_Framework_TestCase { @@ -21,7 +19,7 @@ class BorderTest extends \PHPUnit_Framework_TestCase { $noConstructorParams = new Border(); $withConstructorParams = new Border([ - new BorderPart(Border::LEFT) + new BorderPart(Border::LEFT), ]); } @@ -72,7 +70,7 @@ class BorderTest extends \PHPUnit_Framework_TestCase { $border = new Border(); $border->setParts([ - new BorderPart(Border::LEFT) + new BorderPart(Border::LEFT), ]); $this->assertEquals(1, count($border->getParts()), 'It should be possible to set the border parts'); diff --git a/tests/Spout/Writer/Common/Entity/Style/ColorTest.php b/tests/Spout/Writer/Common/Entity/Style/ColorTest.php index 34ffe24..15ad990 100644 --- a/tests/Spout/Writer/Common/Entity/Style/ColorTest.php +++ b/tests/Spout/Writer/Common/Entity/Style/ColorTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Writer\Common\Entity\Style; /** * Class ColorTest - * - * @package Box\Spout\Writer\Common\Entity\Style */ class ColorTest extends \PHPUnit_Framework_TestCase { @@ -14,7 +12,6 @@ class ColorTest extends \PHPUnit_Framework_TestCase */ public function dataProviderForTestRGB() { - return [ [0, 0, 0, Color::BLACK], [255, 255, 255, Color::WHITE], diff --git a/tests/Spout/Writer/Common/Helper/CellHelperTest.php b/tests/Spout/Writer/Common/Helper/CellHelperTest.php index a07046f..1468bfa 100644 --- a/tests/Spout/Writer/Common/Helper/CellHelperTest.php +++ b/tests/Spout/Writer/Common/Helper/CellHelperTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Writer\Common\Helper; /** * Class CellHelperTest - * - * @package Box\Spout\Writer\Common\Helper */ class CellHelperTest extends \PHPUnit_Framework_TestCase { @@ -41,14 +39,14 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase public function testIsEmpty() { $this->assertTrue(CellHelper::isEmpty(null)); - $this->assertTrue(CellHelper::isEmpty("")); + $this->assertTrue(CellHelper::isEmpty('')); - $this->assertFalse(CellHelper::isEmpty("string")); + $this->assertFalse(CellHelper::isEmpty('string')); $this->assertFalse(CellHelper::isEmpty(0)); $this->assertFalse(CellHelper::isEmpty(1)); $this->assertFalse(CellHelper::isEmpty(true)); $this->assertFalse(CellHelper::isEmpty(false)); - $this->assertFalse(CellHelper::isEmpty(["string"])); + $this->assertFalse(CellHelper::isEmpty(['string'])); $this->assertFalse(CellHelper::isEmpty(new \stdClass())); } @@ -57,14 +55,14 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase */ public function testIsNonEmptyString() { - $this->assertTrue(CellHelper::isNonEmptyString("string")); + $this->assertTrue(CellHelper::isNonEmptyString('string')); - $this->assertFalse(CellHelper::isNonEmptyString("")); + $this->assertFalse(CellHelper::isNonEmptyString('')); $this->assertFalse(CellHelper::isNonEmptyString(0)); $this->assertFalse(CellHelper::isNonEmptyString(1)); $this->assertFalse(CellHelper::isNonEmptyString(true)); $this->assertFalse(CellHelper::isNonEmptyString(false)); - $this->assertFalse(CellHelper::isNonEmptyString(["string"])); + $this->assertFalse(CellHelper::isNonEmptyString(['string'])); $this->assertFalse(CellHelper::isNonEmptyString(new \stdClass())); $this->assertFalse(CellHelper::isNonEmptyString(null)); } @@ -83,8 +81,8 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase $this->assertTrue(CellHelper::isNumeric(0b10100111001)); $this->assertTrue(CellHelper::isNumeric(1337e0)); - $this->assertFalse(CellHelper::isNumeric("0")); - $this->assertFalse(CellHelper::isNumeric("42")); + $this->assertFalse(CellHelper::isNumeric('0')); + $this->assertFalse(CellHelper::isNumeric('42')); $this->assertFalse(CellHelper::isNumeric(true)); $this->assertFalse(CellHelper::isNumeric([2])); $this->assertFalse(CellHelper::isNumeric(new \stdClass())); @@ -101,10 +99,10 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase $this->assertFalse(CellHelper::isBoolean(0)); $this->assertFalse(CellHelper::isBoolean(1)); - $this->assertFalse(CellHelper::isBoolean("0")); - $this->assertFalse(CellHelper::isBoolean("1")); - $this->assertFalse(CellHelper::isBoolean("true")); - $this->assertFalse(CellHelper::isBoolean("false")); + $this->assertFalse(CellHelper::isBoolean('0')); + $this->assertFalse(CellHelper::isBoolean('1')); + $this->assertFalse(CellHelper::isBoolean('true')); + $this->assertFalse(CellHelper::isBoolean('false')); $this->assertFalse(CellHelper::isBoolean([true])); $this->assertFalse(CellHelper::isBoolean(new \stdClass())); $this->assertFalse(CellHelper::isBoolean(null)); diff --git a/tests/Spout/Writer/Common/Manager/Style/StyleManagerTest.php b/tests/Spout/Writer/Common/Manager/Style/StyleManagerTest.php index ea2b1f6..7e2a117 100644 --- a/tests/Spout/Writer/Common/Manager/Style/StyleManagerTest.php +++ b/tests/Spout/Writer/Common/Manager/Style/StyleManagerTest.php @@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; /** * Class StyleManagerTest - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleManagerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/Common/Manager/Style/StyleMergerTest.php b/tests/Spout/Writer/Common/Manager/Style/StyleMergerTest.php index d3b7d2d..ed87af4 100644 --- a/tests/Spout/Writer/Common/Manager/Style/StyleMergerTest.php +++ b/tests/Spout/Writer/Common/Manager/Style/StyleMergerTest.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleMergerTest - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleMergerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/Common/Manager/Style/StyleRegistryTest.php b/tests/Spout/Writer/Common/Manager/Style/StyleRegistryTest.php index b11b2ed..52a2d36 100644 --- a/tests/Spout/Writer/Common/Manager/Style/StyleRegistryTest.php +++ b/tests/Spout/Writer/Common/Manager/Style/StyleRegistryTest.php @@ -2,16 +2,11 @@ namespace Box\Spout\Writer\Common\Manager\Style; -use Box\Spout\Writer\Common\Creator\Style\BorderBuilder; use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; -use Box\Spout\Writer\Common\Entity\Style\Border; -use Box\Spout\Writer\Common\Entity\Style\Color; use Box\Spout\Writer\Common\Entity\Style\Style; /** * Class StyleRegistryTest - * - * @package Box\Spout\Writer\Common\Manager\Style */ class StyleRegistryTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/ODS/Manager/Style/StyleRegistryTest.php b/tests/Spout/Writer/ODS/Manager/Style/StyleRegistryTest.php index ef5a9e5..ae3ecf4 100644 --- a/tests/Spout/Writer/ODS/Manager/Style/StyleRegistryTest.php +++ b/tests/Spout/Writer/ODS/Manager/Style/StyleRegistryTest.php @@ -6,8 +6,6 @@ use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; /** * Class StyleRegistryTest - * - * @package Box\Spout\Writer\ODS\Manager\Style */ class StyleRegistryTest extends \PHPUnit_Framework_TestCase { @@ -17,6 +15,7 @@ class StyleRegistryTest extends \PHPUnit_Framework_TestCase private function getStyleRegistry() { $defaultStyle = (new StyleBuilder())->build(); + return new StyleRegistry($defaultStyle); } @@ -29,10 +28,10 @@ class StyleRegistryTest extends \PHPUnit_Framework_TestCase $this->assertEquals(1, count($styleRegistry->getUsedFonts()), 'There should only be the default font name'); - $style1 = (new StyleBuilder())->setFontName("MyFont1")->build(); + $style1 = (new StyleBuilder())->setFontName('MyFont1')->build(); $styleRegistry->registerStyle($style1); - $style2 = (new StyleBuilder())->setFontName("MyFont2")->build(); + $style2 = (new StyleBuilder())->setFontName('MyFont2')->build(); $styleRegistry->registerStyle($style2); $this->assertEquals(3, count($styleRegistry->getUsedFonts()), 'There should be 3 fonts registered'); diff --git a/tests/Spout/Writer/ODS/SheetTest.php b/tests/Spout/Writer/ODS/SheetTest.php index f8ed2d3..685fddb 100644 --- a/tests/Spout/Writer/ODS/SheetTest.php +++ b/tests/Spout/Writer/ODS/SheetTest.php @@ -9,8 +9,6 @@ use Box\Spout\Writer\WriterFactory; /** * Class SheetTest - * - * @package Box\Spout\Writer\ODS */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/ODS/WriterTest.php b/tests/Spout/Writer/ODS/WriterTest.php index 38c0aaf..e42226b 100644 --- a/tests/Spout/Writer/ODS/WriterTest.php +++ b/tests/Spout/Writer/ODS/WriterTest.php @@ -6,14 +6,12 @@ use Box\Spout\Common\Exception\SpoutException; use Box\Spout\Common\Type; use Box\Spout\Reader\Wrapper\XMLReader; use Box\Spout\TestUsingResource; -use Box\Spout\Writer\Common\Helper\ZipHelper; use Box\Spout\Writer\Common\Entity\Cell; +use Box\Spout\Writer\Common\Helper\ZipHelper; use Box\Spout\Writer\WriterFactory; /** * Class WriterTest - * - * @package Box\Spout\Writer\ODS */ class WriterTest extends \PHPUnit_Framework_TestCase { @@ -280,6 +278,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase [['foo', 'bar'], 2, 0], ]; } + /** * @dataProvider dataProviderForTestAddRowShouldUseNumberColumnsRepeatedForRepeatedValues * @@ -300,7 +299,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase if ($expectedNumTableCells === 1) { $tableCellNode = $tableCellNodes->item(0); - $numColumnsRepeated = intval($tableCellNode->getAttribute('table:number-columns-repeated')); + $numColumnsRepeated = (int) ($tableCellNode->getAttribute('table:number-columns-repeated')); $this->assertEquals($expectedNumColumnsRepeated, $numColumnsRepeated); } else { foreach ($tableCellNodes as $tableCellNode) { @@ -501,7 +500,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase foreach ($dataRows as $dataRow) { /** @var Cell $cell */ foreach ($dataRow as $cell) { - $this->assertValueWasWritten($fileName, (string)$cell->getValue(), ''); + $this->assertValueWasWritten($fileName, (string) $cell->getValue(), ''); } } } @@ -570,7 +569,6 @@ class WriterTest extends \PHPUnit_Framework_TestCase $xmlContents = file_get_contents('zip://' . $pathToContentFile); $this->assertContains($value, $xmlContents, $message); - } /** @@ -611,6 +609,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase private function getSheetXmlNode($fileName, $sheetIndex) { $xmlReader = $this->moveReaderToCorrectTableNode($fileName, $sheetIndex); + return $xmlReader->expand(); } @@ -622,6 +621,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase private function getSheetXmlNodeAsString($fileName, $sheetIndex) { $xmlReader = $this->moveReaderToCorrectTableNode($fileName, $sheetIndex); + return $xmlReader->readOuterXml(); } diff --git a/tests/Spout/Writer/ODS/WriterWithStyleTest.php b/tests/Spout/Writer/ODS/WriterWithStyleTest.php index a2f694f..cd6e21e 100644 --- a/tests/Spout/Writer/ODS/WriterWithStyleTest.php +++ b/tests/Spout/Writer/ODS/WriterWithStyleTest.php @@ -5,18 +5,15 @@ namespace Box\Spout\Writer\ODS; use Box\Spout\Common\Type; use Box\Spout\Reader\Wrapper\XMLReader; use Box\Spout\TestUsingResource; -use Box\Spout\Writer\ODS\Helper\BorderHelper; -use Box\Spout\Writer\Common\Entity\Style\Border; use Box\Spout\Writer\Common\Creator\Style\BorderBuilder; +use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; +use Box\Spout\Writer\Common\Entity\Style\Border; use Box\Spout\Writer\Common\Entity\Style\Color; use Box\Spout\Writer\Common\Entity\Style\Style; -use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; use Box\Spout\Writer\WriterFactory; /** * Class WriterWithStyleTest - * - * @package Box\Spout\Writer\ODS */ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { @@ -277,7 +274,6 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $borderBottomGreenThickSolid = (new BorderBuilder()) ->setBorderBottom(Color::GREEN, Border::WIDTH_THICK, Border::STYLE_SOLID)->build(); - $borderTopRedThinDashed = (new BorderBuilder()) ->setBorderTop(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build(); diff --git a/tests/Spout/Writer/WriterFactoryTest.php b/tests/Spout/Writer/WriterFactoryTest.php index 528eff3..f972549 100644 --- a/tests/Spout/Writer/WriterFactoryTest.php +++ b/tests/Spout/Writer/WriterFactoryTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Writer; /** * Class WriterFactoryTest - * - * @package Box\Spout\Writer */ class WriterFactoryTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/XLSX/Manager/Style/StyleManagerTest.php b/tests/Spout/Writer/XLSX/Manager/Style/StyleManagerTest.php index 867fbf7..733e4a2 100644 --- a/tests/Spout/Writer/XLSX/Manager/Style/StyleManagerTest.php +++ b/tests/Spout/Writer/XLSX/Manager/Style/StyleManagerTest.php @@ -4,8 +4,6 @@ namespace Box\Spout\Writer\XLSX\Manager\Style; /** * Class StyleManagerTest - * - * @package Box\Spout\Writer\XLSX\Manager\Style */ class StyleManagerTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/XLSX/Manager/Style/StyleRegistryTest.php b/tests/Spout/Writer/XLSX/Manager/Style/StyleRegistryTest.php index 0cbd5e3..3b77d0b 100644 --- a/tests/Spout/Writer/XLSX/Manager/Style/StyleRegistryTest.php +++ b/tests/Spout/Writer/XLSX/Manager/Style/StyleRegistryTest.php @@ -8,8 +8,6 @@ use Box\Spout\Writer\Common\Entity\Style\Color; /** * Class StyleRegistryTest - * - * @package Box\Spout\Writer\XLSX\Manager\Style */ class StyleRegistryTest extends \PHPUnit_Framework_TestCase { @@ -19,6 +17,7 @@ class StyleRegistryTest extends \PHPUnit_Framework_TestCase private function getStyleRegistry() { $defaultStyle = (new StyleBuilder())->build(); + return new StyleRegistry($defaultStyle); } @@ -53,7 +52,7 @@ class StyleRegistryTest extends \PHPUnit_Framework_TestCase public function testRegisterStyleAlsoRegistersBorders() { $styleRegistry = $this->getStyleRegistry(); - + $borderLeft = (new BorderBuilder())->setBorderLeft()->build(); $borderRight = (new BorderBuilder())->setBorderRight()->build(); diff --git a/tests/Spout/Writer/XLSX/SheetTest.php b/tests/Spout/Writer/XLSX/SheetTest.php index 03558d4..5df4d57 100644 --- a/tests/Spout/Writer/XLSX/SheetTest.php +++ b/tests/Spout/Writer/XLSX/SheetTest.php @@ -9,8 +9,6 @@ use Box\Spout\Writer\WriterFactory; /** * Class SheetTest - * - * @package Box\Spout\Writer\XLSX */ class SheetTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Spout/Writer/XLSX/WriterTest.php b/tests/Spout/Writer/XLSX/WriterTest.php index 62009aa..18dfd70 100644 --- a/tests/Spout/Writer/XLSX/WriterTest.php +++ b/tests/Spout/Writer/XLSX/WriterTest.php @@ -11,8 +11,6 @@ use Box\Spout\Writer\XLSX\Manager\WorksheetManager; /** * Class WriterTest - * - * @package Box\Spout\Writer\XLSX */ class WriterTest extends \PHPUnit_Framework_TestCase { @@ -485,7 +483,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_add_row_should_escape_control_characters.xlsx'; $dataRows = [ - ['control '.chr(21).' character'], + ['control ' . chr(21) . ' character'], ]; $this->writeToXLSXFile($dataRows, $fileName); @@ -540,7 +538,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase [new Cell('i am a string')], ]; $dataRowsInline = [ - [new Cell(51465), new Cell(true), new Cell(51465.5)] + [new Cell(51465), new Cell(true), new Cell(51465.5)], ]; $dataRows = array_merge($dataRowsShared, $dataRowsInline); @@ -550,7 +548,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase foreach ($dataRowsShared as $dataRow) { /** @var Cell $cell */ foreach ($dataRow as $cell) { - $this->assertSharedStringWasWritten($fileName, (string)$cell->getValue()); + $this->assertSharedStringWasWritten($fileName, (string) $cell->getValue()); } } @@ -630,7 +628,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase $pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml'; $xmlContents = file_get_contents('zip://' . $pathToSheetFile); - $this->assertContains((string)$inlineData, $xmlContents, $message); + $this->assertContains((string) $inlineData, $xmlContents, $message); } /** @@ -646,7 +644,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase $pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml'; $xmlContents = file_get_contents('zip://' . $pathToSheetFile); - $this->assertNotContains((string)$inlineData, $xmlContents, $message); + $this->assertNotContains((string) $inlineData, $xmlContents, $message); } /** diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index 2c152cc..84b8440 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -5,19 +5,17 @@ namespace Box\Spout\Writer\XLSX; use Box\Spout\Common\Type; use Box\Spout\Reader\Wrapper\XMLReader; use Box\Spout\TestUsingResource; -use Box\Spout\Writer\Common\Entity\Style\Border; use Box\Spout\Writer\Common\Creator\Style\BorderBuilder; +use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; +use Box\Spout\Writer\Common\Entity\Style\Border; use Box\Spout\Writer\Common\Entity\Style\Color; use Box\Spout\Writer\Common\Entity\Style\Style; -use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; use Box\Spout\Writer\Common\Manager\Style\StyleMerger; use Box\Spout\Writer\WriterFactory; use Box\Spout\Writer\XLSX\Manager\OptionsManager; /** * Class WriterWithStyleTest - * - * @package Box\Spout\Writer\XLSX */ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { @@ -289,7 +287,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_add_background_color.xlsx'; $dataRows = [ - ["BgColor"], + ['BgColor'], ]; $style = (new StyleBuilder())->setBackgroundColor(Color::WHITE)->build(); $this->writeToXLSXFile($dataRows, $fileName, $style); @@ -307,7 +305,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2, $styleXfsElements->getAttribute('count'), '2 cell xfs present - a default one and a custom one'); $customFillId = $styleXfsElements->lastChild->getAttribute('fillId'); - $this->assertEquals(2, (int)$customFillId, 'The custom fill id should have the index 2'); + $this->assertEquals(2, (int) $customFillId, 'The custom fill id should have the index 2'); } /** @@ -317,13 +315,13 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_add_background_color_shared_definition.xlsx'; $dataRows = [ - ["row-bold-background-red"], - ["row-background-red"], + ['row-bold-background-red'], + ['row-background-red'], ]; $styles = [ (new StyleBuilder())->setBackgroundColor(Color::RED)->setFontBold()->build(), - (new StyleBuilder())->setBackgroundColor(Color::RED)->build() + (new StyleBuilder())->setBackgroundColor(Color::RED)->build(), ]; $this->writeToXLSXFileWithMultipleStyles($dataRows, $fileName, $styles); @@ -343,10 +341,10 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase ); $firstCustomId = $styleXfsElements->childNodes->item(1)->getAttribute('fillId'); - $this->assertEquals(2, (int)$firstCustomId, 'The first custom fill id should have the index 2'); + $this->assertEquals(2, (int) $firstCustomId, 'The first custom fill id should have the index 2'); $secondCustomId = $styleXfsElements->childNodes->item(2)->getAttribute('fillId'); - $this->assertEquals(2, (int)$secondCustomId, 'The second custom fill id should have the index 2'); + $this->assertEquals(2, (int) $secondCustomId, 'The second custom fill id should have the index 2'); } /** @@ -365,7 +363,6 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $borderBottomGreenThickSolid = (new BorderBuilder()) ->setBorderBottom(Color::GREEN, Border::WIDTH_THICK, Border::STYLE_SOLID)->build(); - $borderTopRedThinDashed = (new BorderBuilder()) ->setBorderTop(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build(); @@ -407,15 +404,15 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $borderElements = $this->getXmlSectionFromStylesXmlFile($fileName, 'borders'); $correctOrdering = [ - 'left', 'right', 'top', 'bottom' + 'left', 'right', 'top', 'bottom', ]; - /** @var $borderNode \DOMElement */ + /** @var \DOMElement $borderNode */ foreach ($borderElements->childNodes as $borderNode) { $borderParts = $borderNode->childNodes; $ordering = []; - /** @var $part \DOMText */ + /** @var \DOMText $part */ foreach ($borderParts as $part) { if ($part instanceof \DOMElement) { $ordering[] = $part->nodeName; @@ -423,7 +420,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase } $this->assertEquals($correctOrdering, $ordering, 'The border parts are in correct ordering'); - }; + } } /** @@ -478,7 +475,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $emptyStyle, $fontStyle, $borderRightStyle, - $borderRightFontBoldStyle + $borderRightFontBoldStyle, ]; $this->writeToXLSXFileWithMultipleStyles($dataRows, $fileName, $styles); @@ -507,9 +504,9 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $shouldApplyBorder = ((int) $node->getAttribute('applyBorder') === 1); if ($shouldApplyBorder) { $bordersApplied++; - $this->assertTrue((int)$node->getAttribute('borderId') > 0, 'BorderId is greater than 0'); + $this->assertTrue((int) $node->getAttribute('borderId') > 0, 'BorderId is greater than 0'); } else { - $this->assertTrue((int)$node->getAttribute('borderId') === 0, 'BorderId is 0'); + $this->assertTrue((int) $node->getAttribute('borderId') === 0, 'BorderId is 0'); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 902b4e9..df50f53 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,9 +1,10 @@