From 44d63f027aedc865342e1f87e30234c91a5df359 Mon Sep 17 00:00:00 2001 From: aswinkumar863 Date: Sun, 17 Apr 2022 17:46:59 +0530 Subject: [PATCH] Fixed coding standard with return typehints --- src/PhpSpreadsheet/Worksheet/Table.php | 74 +++++-------------- src/PhpSpreadsheet/Worksheet/Table/Column.php | 56 ++++---------- .../Worksheet/Table/TableStyle.php | 48 +++--------- src/PhpSpreadsheet/Writer/Xlsx/Table.php | 2 +- 4 files changed, 46 insertions(+), 134 deletions(-) diff --git a/src/PhpSpreadsheet/Worksheet/Table.php b/src/PhpSpreadsheet/Worksheet/Table.php index 0198dd2e..b2d29ce7 100644 --- a/src/PhpSpreadsheet/Worksheet/Table.php +++ b/src/PhpSpreadsheet/Worksheet/Table.php @@ -73,20 +73,16 @@ class Table /** * Get Table name. - * - * @return string */ - public function getName() + public function getName(): string { return $this->name; } /** * Set Table name. - * - * @return $this */ - public function setName(string $name) + public function setName(string $name): self { $name = trim($name); @@ -117,20 +113,16 @@ class Table /** * Get show Header Row. - * - * @return bool */ - public function getShowHeaderRow() + public function getShowHeaderRow(): bool { return $this->showHeaderRow; } /** * Set show Header Row. - * - * @return $this */ - public function setShowHeaderRow(bool $showHeaderRow) + public function setShowHeaderRow(bool $showHeaderRow): self { $this->showHeaderRow = $showHeaderRow; @@ -139,20 +131,16 @@ class Table /** * Get show Totals Row. - * - * @return bool */ - public function getShowTotalsRow() + public function getShowTotalsRow(): bool { return $this->showTotalsRow; } /** * Set show Totals Row. - * - * @return $this */ - public function setShowTotalsRow(bool $showTotalsRow) + public function setShowTotalsRow(bool $showTotalsRow): self { $this->showTotalsRow = $showTotalsRow; @@ -161,18 +149,14 @@ class Table /** * Get Table Range. - * - * @return string */ - public function getRange() + public function getRange(): string { return $this->range; } /** * Set Table Cell Range. - * - * @return $this */ public function setRange(string $range): self { @@ -210,8 +194,6 @@ class Table /** * Set Table Cell Range to max row. - * - * @return $this */ public function setRangeToMaxRow(): self { @@ -228,20 +210,16 @@ class Table /** * Get Table's Worksheet. - * - * @return null|Worksheet */ - public function getWorksheet() + public function getWorksheet(): ?Worksheet { return $this->workSheet; } /** * Set Table's Worksheet. - * - * @return $this */ - public function setWorksheet(?Worksheet $worksheet = null) + public function setWorksheet(?Worksheet $worksheet = null): self { if ($this->name !== '' && $worksheet !== null) { $spreadsheet = $worksheet->getParent(); @@ -265,7 +243,7 @@ class Table * * @return Table\Column[] */ - public function getColumns() + public function getColumns(): array { return $this->columns; } @@ -277,7 +255,7 @@ class Table * * @return int The column offset within the table range */ - public function isColumnInRange($column) + public function isColumnInRange(string $column): int { if (empty($this->range)) { throw new PhpSpreadsheetException('No table range is defined.'); @@ -299,7 +277,7 @@ class Table * * @return int The offset of the specified column within the table range */ - public function getColumnOffset($column) + public function getColumnOffset($column): int { return $this->isColumnInRange($column); } @@ -308,10 +286,8 @@ class Table * Get a specified Table Column. * * @param string $column Column name (e.g. A) - * - * @return Table\Column */ - public function getColumn($column) + public function getColumn($column): Table\Column { $this->isColumnInRange($column); @@ -326,10 +302,8 @@ class Table * Get a specified Table Column by it's offset. * * @param int $columnOffset Column offset within range (starting from 0) - * - * @return Table\Column */ - public function getColumnByOffset($columnOffset) + public function getColumnByOffset($columnOffset): Table\Column { [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range); $pColumn = Coordinate::stringFromColumnIndex($rangeStart[0] + $columnOffset); @@ -342,10 +316,8 @@ class Table * * @param string|Table\Column $columnObjectOrString * A simple string containing a Column ID like 'A' is permitted - * - * @return $this */ - public function setColumn($columnObjectOrString) + public function setColumn($columnObjectOrString): self { if ((is_string($columnObjectOrString)) && (!empty($columnObjectOrString))) { $column = $columnObjectOrString; @@ -371,10 +343,8 @@ class Table * Clear a specified Table Column. * * @param string $column Column name (e.g. A) - * - * @return $this */ - public function clearColumn($column) + public function clearColumn($column): self { $this->isColumnInRange($column); @@ -394,10 +364,8 @@ class Table * * @param string $fromColumn Column name (e.g. A) * @param string $toColumn Column name (e.g. B) - * - * @return $this */ - public function shiftColumn($fromColumn, $toColumn) + public function shiftColumn($fromColumn, $toColumn): self { $fromColumn = strtoupper($fromColumn); $toColumn = strtoupper($toColumn); @@ -417,20 +385,16 @@ class Table /** * Get table Style. - * - * @return TableStyle */ - public function getStyle() + public function getStyle(): Table\TableStyle { return $this->style; } /** * Set table Style. - * - * @return $this */ - public function setStyle(TableStyle $style) + public function setStyle(TableStyle $style): self { $this->style = $style; diff --git a/src/PhpSpreadsheet/Worksheet/Table/Column.php b/src/PhpSpreadsheet/Worksheet/Table/Column.php index 385ba171..a7c445f5 100644 --- a/src/PhpSpreadsheet/Worksheet/Table/Column.php +++ b/src/PhpSpreadsheet/Worksheet/Table/Column.php @@ -69,10 +69,8 @@ class Column /** * Get Table column index as string eg: 'A'. - * - * @return string */ - public function getColumnIndex() + public function getColumnIndex(): string { return $this->columnIndex; } @@ -81,10 +79,8 @@ class Column * Set Table column index as string eg: 'A'. * * @param string $column Column (e.g. A) - * - * @return $this */ - public function setColumnIndex($column) + public function setColumnIndex($column): self { // Uppercase coordinate $column = strtoupper($column); @@ -99,20 +95,16 @@ class Column /** * Get show Filter Button. - * - * @return bool */ - public function getShowFilterButton() + public function getShowFilterButton(): bool { return $this->showFilterButton; } /** * Set show Filter Button. - * - * @return $this */ - public function setShowFilterButton(bool $showFilterButton) + public function setShowFilterButton(bool $showFilterButton): self { $this->showFilterButton = $showFilterButton; @@ -121,20 +113,16 @@ class Column /** * Get total Row Label. - * - * @return string */ - public function getTotalsRowLabel() + public function getTotalsRowLabel(): ?string { return $this->totalsRowLabel; } /** * Set total Row Label. - * - * @return $this */ - public function setTotalsRowLabel(string $totalsRowLabel) + public function setTotalsRowLabel(string $totalsRowLabel): self { $this->totalsRowLabel = $totalsRowLabel; @@ -143,20 +131,16 @@ class Column /** * Get total Row Function. - * - * @return string */ - public function getTotalsRowFunction() + public function getTotalsRowFunction(): ?string { return $this->totalsRowFunction; } /** * Set total Row Function. - * - * @return $this */ - public function setTotalsRowFunction(string $totalsRowFunction) + public function setTotalsRowFunction(string $totalsRowFunction): self { $this->totalsRowFunction = $totalsRowFunction; @@ -165,20 +149,16 @@ class Column /** * Get total Row Formula. - * - * @return string */ - public function getTotalsRowFormula() + public function getTotalsRowFormula(): ?string { return $this->totalsRowFormula; } /** * Set total Row Formula. - * - * @return $this */ - public function setTotalsRowFormula(string $totalsRowFormula) + public function setTotalsRowFormula(string $totalsRowFormula): self { $this->totalsRowFormula = $totalsRowFormula; @@ -187,20 +167,16 @@ class Column /** * Get column Formula. - * - * @return string */ - public function getColumnFormula() + public function getColumnFormula(): ?string { return $this->columnFormula; } /** * Set column Formula. - * - * @return $this */ - public function setColumnFormula(string $columnFormula) + public function setColumnFormula(string $columnFormula): self { $this->columnFormula = $columnFormula; @@ -209,20 +185,16 @@ class Column /** * Get this Column's Table. - * - * @return null|Table */ - public function getTable() + public function getTable(): ?Table { return $this->table; } /** * Set this Column's Table. - * - * @return $this */ - public function setTable(?Table $table = null) + public function setTable(?Table $table = null): self { $this->table = $table; diff --git a/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php b/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php index ccf13729..78643c72 100644 --- a/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php +++ b/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php @@ -122,20 +122,16 @@ class TableStyle /** * Get theme. - * - * @return string */ - public function getTheme() + public function getTheme(): string { return $this->theme; } /** * Set theme. - * - * @return $this */ - public function setTheme(string $theme) + public function setTheme(string $theme): self { $this->theme = $theme; @@ -144,20 +140,16 @@ class TableStyle /** * Get show First Column. - * - * @return bool */ - public function getShowFirstColumn() + public function getShowFirstColumn(): bool { return $this->showFirstColumn; } /** * Set show First Column. - * - * @return $this */ - public function setShowFirstColumn(bool $showFirstColumn) + public function setShowFirstColumn(bool $showFirstColumn): self { $this->showFirstColumn = $showFirstColumn; @@ -166,20 +158,16 @@ class TableStyle /** * Get show Last Column. - * - * @return bool */ - public function getShowLastColumn() + public function getShowLastColumn(): bool { return $this->showLastColumn; } /** * Set show Last Column. - * - * @return $this */ - public function setShowLastColumn(bool $showLastColumn) + public function setShowLastColumn(bool $showLastColumn): self { $this->showLastColumn = $showLastColumn; @@ -188,20 +176,16 @@ class TableStyle /** * Get show Row Stripes. - * - * @return bool */ - public function getShowRowStripes() + public function getShowRowStripes(): bool { return $this->showRowStripes; } /** * Set show Row Stripes. - * - * @return $this */ - public function setShowRowStripes(bool $showRowStripes) + public function setShowRowStripes(bool $showRowStripes): self { $this->showRowStripes = $showRowStripes; @@ -210,20 +194,16 @@ class TableStyle /** * Get show Column Stripes. - * - * @return bool */ - public function getShowColumnStripes() + public function getShowColumnStripes(): bool { return $this->showColumnStripes; } /** * Set show Column Stripes. - * - * @return $this */ - public function setShowColumnStripes(bool $showColumnStripes) + public function setShowColumnStripes(bool $showColumnStripes): self { $this->showColumnStripes = $showColumnStripes; @@ -232,20 +212,16 @@ class TableStyle /** * Get this Style's Table. - * - * @return null|Table */ - public function getTable() + public function getTable(): ?Table { return $this->table; } /** * Set this Style's Table. - * - * @return $this */ - public function setTable(?Table $table = null) + public function setTable(?Table $table = null): self { $this->table = $table; diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Table.php b/src/PhpSpreadsheet/Writer/Xlsx/Table.php index be9f5183..67dbd19b 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Table.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Table.php @@ -15,7 +15,7 @@ class Table extends WriterPart * * @return string XML Output */ - public function writeTable(WorksheetTable $table, $tableRef) + public function writeTable(WorksheetTable $table, $tableRef): string { // Create XML writer $objWriter = null;