Skip to content

Commit c54ef78

Browse files
committed
Code formatting
1 parent 6051a6b commit c54ef78

File tree

3 files changed

+97
-67
lines changed

3 files changed

+97
-67
lines changed

src/ActiveExcelSheet.php

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ActiveExcelSheet extends ExcelSheet
3333
*/
3434
public function getQuery()
3535
{
36-
if ($this->_query===null) {
36+
if ($this->_query === null) {
3737
throw new \Exception('No query set');
3838
}
3939
return $this->_query;
@@ -56,12 +56,13 @@ public function getData()
5656
}
5757

5858
/**
59-
* @return string[] list of attributes for the table columns. If no attributes are set,
60-
* attributes are set to `ActiveRecord::attributes()` for the main query record.
59+
* @return string[] list of attributes for the table columns. If no
60+
* attributes are set, attributes are set to `ActiveRecord::attributes()`
61+
* for the main query record.
6162
*/
6263
public function getAttributes()
6364
{
64-
if ($this->_attributes===null) {
65+
if ($this->_attributes === null) {
6566
$class = $this->getQuery()->modelClass;
6667
$model = new $class;
6768
$this->_attributes = $model->attributes();
@@ -86,11 +87,12 @@ public function setData($value)
8687
}
8788

8889
/**
89-
* @return string[] the column titles. If not set, the respective attribute label is used
90+
* @return string[] the column titles. If not set, the respective attribute
91+
* label is used
9092
*/
9193
public function getTitles()
9294
{
93-
if ($this->_titles===null) {
95+
if ($this->_titles === null) {
9496
$class = $this->getQuery()->modelClass;
9597
$model = new $class;
9698
$this->_titles = array_map(function ($a) use ($model) {
@@ -101,16 +103,17 @@ public function getTitles()
101103
}
102104

103105
/**
104-
* @param string[]|false $value the column titles indexed by 0-based column index.
105-
* The array is merged with the default titles from `getTitles()` (=attribute labels).
106-
* If an empty array or `false`, no titles will be generated.
106+
* @param string[]|false $value the column titles indexed by 0-based column
107+
* index. The array is merged with the default titles from `getTitles()`
108+
* (=attribute labels). If an empty array or `false`, no titles will be
109+
* generated.
107110
*/
108111
public function setTitles($value)
109112
{
110113
if (!$value) {
111114
$this->_titles = $value;
112115
} else {
113-
if ($this->_titles===null) {
116+
if ($this->_titles === null) {
114117
$this->getTitles(); // Sets attribute labels as defaults
115118
}
116119
foreach ($value as $i => $v) {
@@ -120,12 +123,13 @@ public function setTitles($value)
120123
}
121124

122125
/**
123-
* @param string[] $value the format strings for the column cells indexed by 0-based column index.
124-
* If not set, the formats are auto-generated from the DB column types.
126+
* @param string[] $value the format strings for the column cells indexed
127+
* by 0-based column index. If not set, the formats are auto-generated
128+
* from the DB column types.
125129
*/
126130
public function getFormats()
127131
{
128-
if ($this->_formats===null) {
132+
if ($this->_formats === null) {
129133
$this->_formats = [];
130134
$attrs = $this->getAttributes();
131135
$types = $this->getColumnTypes();
@@ -149,16 +153,17 @@ public function getFormats()
149153
}
150154

151155
/**
152-
* @param string[]|false $value the format strings for the column cells indexed by 0-based column index.
153-
* The array is merged with the default formats from `getFormats()` (auto-generated from DB columns).
154-
* If an empty array or `false`, no formats are applied.
156+
* @param string[]|false $value the format strings for the column cells
157+
* indexed by 0-based column index. The array is merged with the default
158+
* formats from `getFormats()` (auto-generated from DB columns). If an
159+
* empty array or `false`, no formats are applied.
155160
*/
156161
public function setFormats($value)
157162
{
158163
if (!$value) {
159164
$this->_formats = $value;
160165
} else {
161-
if ($this->_formats===null) {
166+
if ($this->_formats === null) {
162167
$this->getFormats(); // Sets auto-generated formats as defaults
163168
}
164169
foreach ($value as $i => $v) {
@@ -168,12 +173,13 @@ public function setFormats($value)
168173
}
169174

170175
/**
171-
* @return Callable[] the value formatters for the column cells indexed by 0-based column index.
172-
* If not set, the formatters are aut-generated from the DB column types.
176+
* @return Callable[] the value formatters for the column cells indexed by
177+
* 0-based column index. If not set, the formatters are aut-generated from
178+
* the DB column types.
173179
*/
174180
public function getFormatters()
175181
{
176-
if ($this->_formatters===null) {
182+
if ($this->_formatters === null) {
177183
$this->_formatters = [];
178184
$attrs = $this->getAttributes();
179185
$types = $this->getColumnTypes();
@@ -192,16 +198,17 @@ public function getFormatters()
192198
}
193199

194200
/**
195-
* @param Callable[]|null $value the value formatters for the column cells indexed by 0-based column index.
196-
* The array is merged with the default formats from `getFormatters()` (auto-generated from DB columns).
197-
* If an empty array or `false`, no formatters are applied.
201+
* @param Callable[]|null $value the value formatters for the column cells
202+
* indexed by 0-based column index. The array is merged with the default
203+
* formats from `getFormatters()` (auto-generated from DB columns). If an
204+
* empty array or `false`, no formatters are applied.
198205
*/
199206
public function setFormatters($value)
200207
{
201208
if (!$value) {
202209
$this->_formatters = $value;
203210
} else {
204-
if ($this->_formatters===null) {
211+
if ($this->_formatters === null) {
205212
$this->getFormatters(); // Sets auto-generated formatters as defaults
206213
}
207214
foreach ($value as $i => $v) {
@@ -211,11 +218,12 @@ public function setFormatters($value)
211218
}
212219

213220
/**
214-
* @return yii\db\ColumnSchema[] the DB column types `ColumnSchema::$type` indexed by 0-based column index
221+
* @return yii\db\ColumnSchema[] the DB column types `ColumnSchema::$type`
222+
* indexed by 0-based column index
215223
*/
216224
protected function getColumnTypes()
217225
{
218-
if ($this->_columnTypes===null) {
226+
if ($this->_columnTypes === null) {
219227
$class = $this->getQuery()->modelClass;
220228
$model = new $class;
221229
$this->_columnTypes = array_map(function ($attr) use ($model) {
@@ -238,19 +246,24 @@ protected function renderRow($data, $row, $formats, $formatters, $callbacks, $ty
238246
}
239247

240248
/**
241-
* Returns either the ColumnSchema or a new instance of the related model for the given attribute name.
249+
* Returns either the ColumnSchema or a new instance of the related model
250+
* for the given attribute name.
242251
*
243-
* The name can be specified in dot format, like `company.name` in which case the ColumnSchema for
244-
* the `name` attribute in the related `company` record would be returned.
252+
* The name can be specified in dot format, like `company.name` in which
253+
* case the ColumnSchema for the `name` attribute in the related `company`
254+
* record would be returned.
245255
*
246-
* If the attribute is a relation name (which could also use dot notation) then `$isRelation` must
247-
* be set to `true`. In this case an instance of the related ActiveRecord class is returned.
256+
* If the attribute is a relation name (which could also use dot notation)
257+
* then `$isRelation` must be set to `true`. In this case an instance of
258+
* the related ActiveRecord class is returned.
248259
*
249260
* @param yii\db\ActiveRecord $model the model where the attribute exist
250261
* @param string $attribute name of the attribute
251-
* @param mixed $isRelation whether the name specifies a relation, in which case an `ActiveRecord`
252-
* is returned. Default is `false`, which returns a `ColumnSchema`.
253-
* @return yii\db\ColumnSchema|yii\db\ActiveRecord the type instance of the attribute
262+
* @param mixed $isRelation whether the name specifies a relation, in which
263+
* case an `ActiveRecord` is returned. Default is `false`, which returns a
264+
* `ColumnSchema`.
265+
* @return yii\db\ColumnSchema|yii\db\ActiveRecord the type instance of the
266+
* attribute
254267
*/
255268
public static function getType($model, $attribute, $isRelation = false)
256269
{

src/ExcelFile.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
class ExcelFile extends Object
1212
{
1313
/**
14-
* @var string the writer class to use. Default is `\PHPExcel_Writer_Excel2007`.
14+
* @var string the writer class to use. Default is
15+
* `\PHPExcel_Writer_Excel2007`.
1516
*/
1617
public $writerClass = '\PHPExcel_Writer_Excel2007';
1718

1819
/**
1920
* @var array options to pass to the constructor of \mikehaertl\tmp\File,
20-
* indexed by option name. Available keys are 'suffix', 'prefix' and 'directory'.
21-
* This is only useful if creation of the temporary file fails for some reason.
21+
* indexed by option name. Available keys are 'suffix', 'prefix' and
22+
* 'directory'. This is only useful if creation of the temporary file
23+
* fails for some reason.
2224
*/
2325
public $fileOptions = [];
2426

@@ -34,7 +36,7 @@ class ExcelFile extends Object
3436
*/
3537
public function getWriter()
3638
{
37-
if ($this->_writer===null) {
39+
if ($this->_writer === null) {
3840
$class = $this->writerClass;
3941
$this->_writer = new $class($this->getWorkbook());
4042
}
@@ -46,7 +48,7 @@ public function getWriter()
4648
*/
4749
public function getWorkbook()
4850
{
49-
if ($this->_workbook===null) {
51+
if ($this->_workbook === null) {
5052
$this->_workbook = new \PHPExcel();
5153
}
5254
return $this->_workbook;
@@ -57,7 +59,7 @@ public function getWorkbook()
5759
*/
5860
public function getTmpFile()
5961
{
60-
if ($this->_tmpFile===null) {
62+
if ($this->_tmpFile === null) {
6163
$suffix = isset($this->fileOptions['suffix']) ? $this->fileOptions['suffix'] : null;
6264
$prefix = isset($this->fileOptions['prefix']) ? $this->fileOptions['prefix'] : null;
6365
$directory = isset($this->fileOptions['directory']) ? $this->fileOptions['directory'] : null;
@@ -75,9 +77,9 @@ public function getSheets()
7577
}
7678

7779
/**
78-
* @param array $value the sheet configuration. This must be an array where keys
79-
* are sheet names and values are arrays with the configuration options for an
80-
* instance if `ExcelSheet`.
80+
* @param array $value the sheet configuration. This must be an array where
81+
* keys are sheet names and values are arrays with the configuration
82+
* options for an instance if `ExcelSheet`.
8183
*/
8284
public function setSheets($value)
8385
{
@@ -99,8 +101,10 @@ public function saveAs($filename)
99101
/**
100102
* Send the Excel file for download
101103
*
102-
* @param string|null $filename the filename to send. If empty, the file is streamed inline.
103-
* @param bool $inline whether to force inline display of the file, even if filename is present.
104+
* @param string|null $filename the filename to send. If empty, the file is
105+
* streamed inline.
106+
* @param bool $inline whether to force inline display of the file, even if
107+
* filename is present.
104108
*/
105109
public function send($filename = null, $inline = false)
106110
{
@@ -126,7 +130,9 @@ public function createSheets()
126130
} elseif (!is_object($config)) {
127131
throw new \Exception('Invalid sheet configuration');
128132
}
129-
$sheet = (0===$i++) ? $workbook->getActiveSheet() : $workbook->createSheet();
133+
$i++;
134+
$sheet = ($i === 0) ?
135+
$workbook->getActiveSheet() : $workbook->createSheet();
130136
if (is_string($title)) {
131137
$sheet->setTitle($title);
132138
}

0 commit comments

Comments
 (0)