Skip to content

Commit 4085906

Browse files
committed
Updated cssdoc::save() to return the compiled code instead of true if saved, as it returns the code if no file is specified.
Updated tests.
1 parent 046af60 commit 4085906

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/cssdoc.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ public function minify(array $minify = []) : void {
456456
}
457457

458458
/**
459-
* Compile the property to a string
459+
* Compile the document to a string
460460
*
461-
* @param array $options An array of compilation options
461+
* @param array $options An array indicating output options, this is merged with cssdoc::$output
462462
* @return void
463463
*/
464464
public function compile(array $options = []) : string {
@@ -467,25 +467,23 @@ public function compile(array $options = []) : string {
467467
}
468468

469469
/**
470-
* Compile the document as an HTML string and save it to the specified location
470+
* Compile the document and save it to the specified location
471471
*
472-
* @param array $options An array indicating output options, this is merged with htmldoc::$output
473-
* @return string The compiled HTML
472+
* @param string|null $file The file location to save the document to, or null to just return the compiled code
473+
* @param array $options An array indicating output options, this is merged with cssdoc::$output
474+
* @return string|bool The compiled CSS, or false if the file could not be saved
474475
*/
475476
public function save(string $file = null, array $options = []) {
476477
$css = $this->compile($options);
477478

478-
// send back as string
479-
if (!$file) {
480-
return $css;
481-
482479
// save file
483-
} elseif (\file_put_contents($file, $css) === false) {
480+
if ($file && \file_put_contents($file, $css) === false) {
484481
\trigger_error('File could not be written', E_USER_WARNING);
485-
} else {
486-
return true;
482+
return false;
487483
}
488-
return false;
484+
485+
// send back as string
486+
return $css;
489487
}
490488

491489
public function collection(array $rules) {

tests/cssdocTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function testCanMinifyCss() {
154154
// test save method
155155
$this->assertEquals($minified, $obj->save());
156156
$file = __DIR__.'/test.css';
157-
$this->assertEquals(true, $obj->save($file, ['style' => 'beautify']));
157+
$this->assertEquals($obj->compile(['style' => 'beautify']), $obj->save($file, ['style' => 'beautify']));
158158
$this->assertEquals(true, file_exists($file));
159159
unlink($file);
160160
}

0 commit comments

Comments
 (0)