reduce code complexity a bit

This commit is contained in:
Robin Appelman 2016-08-26 23:59:48 +02:00
commit 2601885185
2 changed files with 43 additions and 38 deletions

View file

@ -20,6 +20,8 @@ use Icewind\SMB\Exception\NotEmptyException;
use Icewind\SMB\Exception\NotFoundException;
class Parser {
const MSG_NOT_FOUND = 'Error opening local file ';
/**
* @var \Icewind\SMB\TimeZoneProvider
*/
@ -32,24 +34,24 @@ class Parser {
$this->timeZoneProvider = $timeZoneProvider;
}
private function getErrorCode($line) {
$parts = explode(' ', $line);
foreach ($parts as $part) {
if (substr($part, 0, 9) === 'NT_STATUS') {
return $part;
}
}
return false;
}
public function checkForError($output, $path) {
if (count($output) === 0) {
return true;
} else {
if (strpos($output[0], 'does not exist')) {
throw new NotFoundException($path);
}
$parts = explode(' ', $output[0]);
$error = false;
foreach ($parts as $part) {
if (substr($part, 0, 9) === 'NT_STATUS') {
$error = $part;
}
}
$error = $this->getErrorCode($output[0]);
$notFoundMsg = 'Error opening local file ';
if (substr($output[0], 0, strlen($notFoundMsg)) === $notFoundMsg) {
$localPath = substr($output[0], strlen($notFoundMsg));
if (substr($output[0], 0, strlen(self::MSG_NOT_FOUND)) === self::MSG_NOT_FOUND) {
$localPath = substr($output[0], strlen(self::MSG_NOT_FOUND));
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing');
}
@ -73,7 +75,6 @@ class Parser {
throw Exception::unknown($path, $error);
}
}
}
/**
* check if the first line holds a connection failure

View file

@ -401,8 +401,12 @@ class Share extends AbstractShare {
* @return bool
*/
protected function parseOutput($lines, $path = '') {
if (count($lines) === 0) {
return true;
} else {
return $this->parser->checkForError($lines, $path);
}
}
/**
* @param string $string