Skip to content

Commit

Permalink
Add early exit and simplify condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Phrlog authored and sebastianbergmann committed Oct 28, 2019
1 parent ea510c5 commit 62b52dd
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/Util/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,33 @@ class Printer
*/
public function __construct($out = null)
{
if ($out !== null) {
if (\is_string($out)) {
if (\strpos($out, 'socket://') === 0) {
$out = \explode(':', \str_replace('socket://', '', $out));

if (\count($out) !== 2) {
throw new Exception;
}

$this->out = \fsockopen($out[0], $out[1]);
} else {
if (\strpos($out, 'php://') === false && !Filesystem::createDirectory(\dirname($out))) {
throw new Exception(\sprintf('Directory "%s" was not created', \dirname($out)));
}

$this->out = \fopen($out, 'wt');
}

$this->outTarget = $out;
} else {
$this->out = $out;
if ($out === null) {
return;
}

if (\is_string($out) === false) {
$this->out = $out;

return;
}

if (\strpos($out, 'socket://') === 0) {
$out = \explode(':', \str_replace('socket://', '', $out));

if (\count($out) !== 2) {
throw new Exception;
}

$this->out = \fsockopen($out[0], $out[1]);
} else {
if (\strpos($out, 'php://') === false && !Filesystem::createDirectory(\dirname($out))) {
throw new Exception(\sprintf('Directory "%s" was not created', \dirname($out)));
}

$this->out = \fopen($out, 'wt');
}

$this->outTarget = $out;
}

/**
Expand Down

0 comments on commit 62b52dd

Please sign in to comment.