Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
CRAP
80.00% covered (warning)
80.00%
8 / 10
OutputFileToString
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
4.13
80.00% covered (warning)
80.00%
8 / 10
 copyFromFile
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getContents
0.00% covered (danger)
0.00%
0 / 1
2.50
50.00% covered (danger)
50.00%
2 / 4
 readFromMultipart
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
<?php
namespace Shellbox\Command;
use Shellbox\FileUtils;
use Shellbox\Multipart\MultipartReader;
use Shellbox\ShellboxError;
/**
 * Encapsulation of an output file that is read into a string
 */
class OutputFileToString extends OutputFile {
    /** @var string */
    private $contents;
    public function copyFromFile( $sourcePath ) {
        $this->contents = FileUtils::getContents( $sourcePath );
        $this->received = true;
    }
    public function getContents() {
        if ( $this->contents === null ) {
            throw new ShellboxError( __METHOD__ . ' was called too early or ' .
                'on a non-existent file' );
        }
        return $this->contents;
    }
    public function readFromMultipart( MultipartReader $multipartReader ) {
        $this->contents = $multipartReader->readPartAsString();
        $this->received = true;
    }
}