Skip to content

Commit

Permalink
move some arrays to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed May 24, 2018
1 parent 4a5699f commit 0d31da4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 10 additions & 9 deletions src/Wrapped/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class Parser {
ErrorCodes::InvalidParameter => InvalidParameterException::class
];

const MODE_STRINGS = [
'R' => FileInfo::MODE_READONLY,
'H' => FileInfo::MODE_HIDDEN,
'S' => FileInfo::MODE_SYSTEM,
'D' => FileInfo::MODE_DIRECTORY,
'A' => FileInfo::MODE_ARCHIVE,
'N' => FileInfo::MODE_NORMAL
];

/**
* @param TimeZoneProvider $timeZoneProvider
*/
Expand Down Expand Up @@ -109,15 +118,7 @@ public function checkConnectionError($line) {

public function parseMode($mode) {
$result = 0;
$modeStrings = array(
'R' => FileInfo::MODE_READONLY,
'H' => FileInfo::MODE_HIDDEN,
'S' => FileInfo::MODE_SYSTEM,
'D' => FileInfo::MODE_DIRECTORY,
'A' => FileInfo::MODE_ARCHIVE,
'N' => FileInfo::MODE_NORMAL
);
foreach ($modeStrings as $char => $val) {
foreach (self::MODE_STRINGS as $char => $val) {
if (strpos($mode, $char) !== false) {
$result |= $val;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Wrapped/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class Share extends AbstractShare {
*/
private $system;

const MODE_MAP = [
FileInfo::MODE_READONLY => 'r',
FileInfo::MODE_HIDDEN => 'h',
FileInfo::MODE_ARCHIVE => 'a',
FileInfo::MODE_SYSTEM => 's'
];

/**
* @param IServer $server
* @param string $name
Expand Down Expand Up @@ -327,13 +334,7 @@ public function write($target) {
*/
public function setMode($path, $mode) {
$modeString = '';
$modeMap = array(
FileInfo::MODE_READONLY => 'r',
FileInfo::MODE_HIDDEN => 'h',
FileInfo::MODE_ARCHIVE => 'a',
FileInfo::MODE_SYSTEM => 's'
);
foreach ($modeMap as $modeByte => $string) {
foreach (self::MODE_MAP as $modeByte => $string) {
if ($mode & $modeByte) {
$modeString .= $string;
}
Expand Down

0 comments on commit 0d31da4

Please sign in to comment.