mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
reduce code complexity a bit
This commit is contained in:
parent
b43c129ed9
commit
2601885185
2 changed files with 43 additions and 38 deletions
|
|
@ -20,6 +20,8 @@ use Icewind\SMB\Exception\NotEmptyException;
|
||||||
use Icewind\SMB\Exception\NotFoundException;
|
use Icewind\SMB\Exception\NotFoundException;
|
||||||
|
|
||||||
class Parser {
|
class Parser {
|
||||||
|
const MSG_NOT_FOUND = 'Error opening local file ';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Icewind\SMB\TimeZoneProvider
|
* @var \Icewind\SMB\TimeZoneProvider
|
||||||
*/
|
*/
|
||||||
|
|
@ -32,24 +34,24 @@ class Parser {
|
||||||
$this->timeZoneProvider = $timeZoneProvider;
|
$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) {
|
public function checkForError($output, $path) {
|
||||||
if (count($output) === 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (strpos($output[0], 'does not exist')) {
|
if (strpos($output[0], 'does not exist')) {
|
||||||
throw new NotFoundException($path);
|
throw new NotFoundException($path);
|
||||||
}
|
}
|
||||||
$parts = explode(' ', $output[0]);
|
$error = $this->getErrorCode($output[0]);
|
||||||
$error = false;
|
|
||||||
foreach ($parts as $part) {
|
|
||||||
if (substr($part, 0, 9) === 'NT_STATUS') {
|
|
||||||
$error = $part;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$notFoundMsg = 'Error opening local file ';
|
if (substr($output[0], 0, strlen(self::MSG_NOT_FOUND)) === self::MSG_NOT_FOUND) {
|
||||||
if (substr($output[0], 0, strlen($notFoundMsg)) === $notFoundMsg) {
|
$localPath = substr($output[0], strlen(self::MSG_NOT_FOUND));
|
||||||
$localPath = substr($output[0], strlen($notFoundMsg));
|
|
||||||
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing');
|
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +75,6 @@ class Parser {
|
||||||
throw Exception::unknown($path, $error);
|
throw Exception::unknown($path, $error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the first line holds a connection failure
|
* check if the first line holds a connection failure
|
||||||
|
|
|
||||||
|
|
@ -401,8 +401,12 @@ class Share extends AbstractShare {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function parseOutput($lines, $path = '') {
|
protected function parseOutput($lines, $path = '') {
|
||||||
|
if (count($lines) === 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
return $this->parser->checkForError($lines, $path);
|
return $this->parser->checkForError($lines, $path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string
|
* @param string $string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue