diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4afdf82 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=false +indent_style=space +indent_size=4 + +[{composer.lock,.babelrc,.stylelintrc,.eslintrc,jest.config,*.bowerrc,*.jsb3,*.jsb2,*.json}] +indent_style=space +indent_size=2 + +[{Makefile.*,Makefile,GNUmakefile,makefile,*.mk}] +indent_style=tab +tab_width=4 + +[{*.module,*.hphp,*.phtml,*.php5,*.php4,*.php,*.inc}] +indent_style=tab +tab_width=4 + +[{*.yml,*.yaml}] +indent_style=space +indent_size=2 + diff --git a/.gitignore b/.gitignore index 4f38912..966ac1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea vendor composer.lock +.php_cs.cache + diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..a2fdf19 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,15 @@ +exclude('vendor') + ->in(__DIR__) +; +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'braces' => ['position_after_functions_and_oop_constructs' => 'same'], + 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => false], + ]) + ->setIndent("\t") + ->setFinder($finder) + ; diff --git a/.travis.yml b/.travis.yml index 668128a..98ac39a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,7 @@ install: script: - vendor/bin/phpunit --coverage-clover clover.xml -c tests/phpunit.xml + - vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff --diff-format udiff after_script: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/composer.json b/composer.json index 708c59b..5cb22ee 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ ], "require" : { "php": ">=5.6", - "icewind/streams": ">=0.2.0" + "icewind/streams": ">=0.2.0", + "friendsofphp/php-cs-fixer": "^2.13" }, "require-dev": { "phpunit/phpunit": "^5.7" diff --git a/src/AbstractServer.php b/src/AbstractServer.php index 5114d53..aa2adfa 100644 --- a/src/AbstractServer.php +++ b/src/AbstractServer.php @@ -21,7 +21,6 @@ namespace Icewind\SMB; - abstract class AbstractServer implements IServer { const LOCALE = 'en_US.UTF-8'; diff --git a/src/AbstractShare.php b/src/AbstractShare.php index 0af03ff..b53c253 100644 --- a/src/AbstractShare.php +++ b/src/AbstractShare.php @@ -13,7 +13,7 @@ abstract class AbstractShare implements IShare { private $forbiddenCharacters; public function __construct() { - $this->forbiddenCharacters = array('?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"); + $this->forbiddenCharacters = ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"]; } protected function verifyPath($path) { diff --git a/src/AnonymousAuth.php b/src/AnonymousAuth.php index 6d1feac..737cc7c 100644 --- a/src/AnonymousAuth.php +++ b/src/AnonymousAuth.php @@ -21,7 +21,6 @@ namespace Icewind\SMB; - class AnonymousAuth implements IAuth { public function getUsername() { return null; diff --git a/src/BasicAuth.php b/src/BasicAuth.php index 0032dc5..9d7f9b5 100644 --- a/src/BasicAuth.php +++ b/src/BasicAuth.php @@ -21,7 +21,6 @@ namespace Icewind\SMB; - class BasicAuth implements IAuth { /** @var string */ private $username; @@ -62,5 +61,4 @@ class BasicAuth implements IAuth { public function setExtraSmbClientOptions($smbClientState) { // noop } - } diff --git a/src/Exception/AccessDeniedException.php b/src/Exception/AccessDeniedException.php index 4b7d22b..adc4234 100644 --- a/src/Exception/AccessDeniedException.php +++ b/src/Exception/AccessDeniedException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class AccessDeniedException extends ConnectException {} +class AccessDeniedException extends ConnectException { +} diff --git a/src/Exception/AlreadyExistsException.php b/src/Exception/AlreadyExistsException.php index 4636b9d..aaa5226 100644 --- a/src/Exception/AlreadyExistsException.php +++ b/src/Exception/AlreadyExistsException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class AlreadyExistsException extends InvalidRequestException {} +class AlreadyExistsException extends InvalidRequestException { +} diff --git a/src/Exception/AuthenticationException.php b/src/Exception/AuthenticationException.php index ddf5d7e..9626d79 100644 --- a/src/Exception/AuthenticationException.php +++ b/src/Exception/AuthenticationException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class AuthenticationException extends ConnectException{} +class AuthenticationException extends ConnectException { +} diff --git a/src/Exception/ConnectException.php b/src/Exception/ConnectException.php index 310d441..9aa174b 100644 --- a/src/Exception/ConnectException.php +++ b/src/Exception/ConnectException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class ConnectException extends Exception {} +class ConnectException extends Exception { +} diff --git a/src/Exception/ConnectionException.php b/src/Exception/ConnectionException.php index 2103356..d27752e 100644 --- a/src/Exception/ConnectionException.php +++ b/src/Exception/ConnectionException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class ConnectionException extends ConnectException {} +class ConnectionException extends ConnectException { +} diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php index 93f2c1b..4954518 100644 --- a/src/Exception/Exception.php +++ b/src/Exception/Exception.php @@ -8,7 +8,7 @@ namespace Icewind\SMB\Exception; class Exception extends \Exception { - static public function unknown($path, $error) { + public static function unknown($path, $error) { $message = 'Unknown error (' . $error . ')'; if ($path) { $message .= ' for ' . $path; @@ -23,7 +23,7 @@ class Exception extends \Exception { * @param string $path * @return Exception */ - static public function fromMap(array $exceptionMap, $error, $path) { + public static function fromMap(array $exceptionMap, $error, $path) { if (isset($exceptionMap[$error])) { $exceptionClass = $exceptionMap[$error]; if (is_numeric($error)) { diff --git a/src/Exception/FileInUseException.php b/src/Exception/FileInUseException.php index 46460eb..4408d39 100644 --- a/src/Exception/FileInUseException.php +++ b/src/Exception/FileInUseException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class FileInUseException extends InvalidRequestException {} +class FileInUseException extends InvalidRequestException { +} diff --git a/src/Exception/ForbiddenException.php b/src/Exception/ForbiddenException.php index 117d6a4..31c0518 100644 --- a/src/Exception/ForbiddenException.php +++ b/src/Exception/ForbiddenException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class ForbiddenException extends InvalidRequestException {} +class ForbiddenException extends InvalidRequestException { +} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index f12bb3a..a21d069 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class InvalidArgumentException extends InvalidRequestException {} +class InvalidArgumentException extends InvalidRequestException { +} diff --git a/src/Exception/InvalidHostException.php b/src/Exception/InvalidHostException.php index 4b17f1a..2358b7f 100644 --- a/src/Exception/InvalidHostException.php +++ b/src/Exception/InvalidHostException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class InvalidHostException extends ConnectException {} +class InvalidHostException extends ConnectException { +} diff --git a/src/Exception/InvalidParameterException.php b/src/Exception/InvalidParameterException.php index 163b571..5ffbf4f 100644 --- a/src/Exception/InvalidParameterException.php +++ b/src/Exception/InvalidParameterException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class InvalidParameterException extends InvalidRequestException {} +class InvalidParameterException extends InvalidRequestException { +} diff --git a/src/Exception/InvalidPathException.php b/src/Exception/InvalidPathException.php index 4bba74f..2b7859d 100644 --- a/src/Exception/InvalidPathException.php +++ b/src/Exception/InvalidPathException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class InvalidPathException extends InvalidRequestException {} +class InvalidPathException extends InvalidRequestException { +} diff --git a/src/Exception/InvalidTypeException.php b/src/Exception/InvalidTypeException.php index 63b7930..00da288 100644 --- a/src/Exception/InvalidTypeException.php +++ b/src/Exception/InvalidTypeException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class InvalidTypeException extends InvalidRequestException {} +class InvalidTypeException extends InvalidRequestException { +} diff --git a/src/Exception/NoLoginServerException.php b/src/Exception/NoLoginServerException.php index 43f7f9a..8f0c553 100644 --- a/src/Exception/NoLoginServerException.php +++ b/src/Exception/NoLoginServerException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class NoLoginServerException extends ConnectException {} +class NoLoginServerException extends ConnectException { +} diff --git a/src/Exception/NotEmptyException.php b/src/Exception/NotEmptyException.php index 789a76b..0e606d6 100644 --- a/src/Exception/NotEmptyException.php +++ b/src/Exception/NotEmptyException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class NotEmptyException extends InvalidRequestException {} +class NotEmptyException extends InvalidRequestException { +} diff --git a/src/Exception/NotFoundException.php b/src/Exception/NotFoundException.php index 9ce97cd..29ea2d8 100644 --- a/src/Exception/NotFoundException.php +++ b/src/Exception/NotFoundException.php @@ -7,4 +7,5 @@ namespace Icewind\SMB\Exception; -class NotFoundException extends InvalidRequestException {} +class NotFoundException extends InvalidRequestException { +} diff --git a/src/INotifyHandler.php b/src/INotifyHandler.php index 1ee59b2..c3ee3ff 100644 --- a/src/INotifyHandler.php +++ b/src/INotifyHandler.php @@ -8,7 +8,6 @@ namespace Icewind\SMB; - interface INotifyHandler { // https://msdn.microsoft.com/en-us/library/dn392331.aspx const NOTIFY_ADDED = 1; diff --git a/src/KerberosAuth.php b/src/KerberosAuth.php index 9510a6d..0e91202 100644 --- a/src/KerberosAuth.php +++ b/src/KerberosAuth.php @@ -45,5 +45,4 @@ class KerberosAuth implements IAuth { smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true); smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false); } - } diff --git a/src/Native/NativeFileInfo.php b/src/Native/NativeFileInfo.php index 3466797..9043189 100644 --- a/src/Native/NativeFileInfo.php +++ b/src/Native/NativeFileInfo.php @@ -30,7 +30,10 @@ class NativeFileInfo implements IFileInfo { /** * @var array|null */ - protected $statCache; + protected $statCache = null; + + /** @var callable|null */ + protected $statCallback = null; /** * @var int @@ -41,13 +44,20 @@ class NativeFileInfo implements IFileInfo { * @param NativeShare $share * @param string $path * @param string $name - * @param array $stat + * @param array|callable $stat */ - public function __construct($share, $path, $name, $stat = null) { + public function __construct($share, $path, $name, $stat) { $this->share = $share; $this->path = $path; $this->name = $name; - $this->statCache = $stat; + + if (is_array($stat)) { + $this->statCache = $stat; + } elseif (is_callable($stat)) { + $this->statCallback = $stat; + } else { + throw new \InvalidArgumentException('$stat needs to be an array or callback'); + } } /** @@ -69,7 +79,7 @@ class NativeFileInfo implements IFileInfo { */ protected function stat() { if (is_null($this->statCache)) { - $this->statCache = $this->share->getStat($this->getPath()); + $this->statCache = call_user_func($this->statCallback); } return $this->statCache; } diff --git a/src/Native/NativeReadStream.php b/src/Native/NativeReadStream.php index 3ef5b21..fe0af76 100644 --- a/src/Native/NativeReadStream.php +++ b/src/Native/NativeReadStream.php @@ -25,7 +25,6 @@ class NativeReadStream extends NativeStream { $this->readBuffer = fopen('php://memory', 'r+'); return parent::stream_open($path, $mode, $options, $opened_path); - } /** @@ -39,13 +38,13 @@ class NativeReadStream extends NativeStream { */ public static function wrap($state, $smbStream, $mode, $url) { stream_wrapper_register('nativesmb', NativeReadStream::class); - $context = stream_context_create(array( - 'nativesmb' => array( + $context = stream_context_create([ + 'nativesmb' => [ 'state' => $state, 'handle' => $smbStream, 'url' => $url - ) - )); + ] + ]); $fh = fopen('nativesmb://', $mode, false, $context); stream_wrapper_unregister('nativesmb'); return $fh; diff --git a/src/Native/NativeServer.php b/src/Native/NativeServer.php index a5b502b..aadb05d 100644 --- a/src/Native/NativeServer.php +++ b/src/Native/NativeServer.php @@ -35,7 +35,7 @@ class NativeServer extends AbstractServer { */ public function listShares() { $this->connect(); - $shares = array(); + $shares = []; $dh = $this->state->opendir('smb://' . $this->getHost()); while ($share = $this->state->readdir($dh)) { if ($share['type'] === 'file share') { diff --git a/src/Native/NativeShare.php b/src/Native/NativeShare.php index ad8a056..d1252d6 100644 --- a/src/Native/NativeShare.php +++ b/src/Native/NativeShare.php @@ -87,13 +87,16 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\InvalidTypeException */ public function dir($path) { - $files = array(); + $files = []; $dh = $this->getState()->opendir($this->buildUrl($path)); while ($file = $this->getState()->readdir($dh)) { $name = $file['name']; if ($name !== '.' and $name !== '..') { - $files [] = new NativeFileInfo($this, $path . '/' . $name, $name); + $fullPath = $path . '/' . $name; + $files [] = new NativeFileInfo($this, $fullPath, $name, function () use ($fullPath) { + return $this->getStat($fullPath); + }); } } @@ -115,7 +118,7 @@ class NativeShare extends AbstractShare { * @param string $path * @return array */ - public function getStat($path) { + private function getStat($path) { return $this->getState()->stat($this->buildUrl($path)); } @@ -295,11 +298,10 @@ class NativeShare extends AbstractShare { * * @param string $path * @param string $attribute attribute to get the info - * @param mixed $value - * @return string the attribute value + * @param string|int $value + * @return mixed the attribute value */ public function setAttribute($path, $attribute, $value) { - if ($attribute === 'system.dos_attr.mode' and is_int($value)) { $value = '0x' . dechex($value); } diff --git a/src/Native/NativeStream.php b/src/Native/NativeStream.php index 3b3c65d..dd92edc 100644 --- a/src/Native/NativeStream.php +++ b/src/Native/NativeStream.php @@ -48,13 +48,13 @@ class NativeStream implements File { */ public static function wrap($state, $smbStream, $mode, $url) { stream_wrapper_register('nativesmb', NativeStream::class); - $context = stream_context_create(array( - 'nativesmb' => array( + $context = stream_context_create([ + 'nativesmb' => [ 'state' => $state, 'handle' => $smbStream, 'url' => $url - ) - )); + ] + ]); $fh = fopen('nativesmb://', $mode, false, $context); stream_wrapper_unregister('nativesmb'); return $fh; diff --git a/src/Native/NativeWriteStream.php b/src/Native/NativeWriteStream.php index f5143a0..39eca81 100644 --- a/src/Native/NativeWriteStream.php +++ b/src/Native/NativeWriteStream.php @@ -25,7 +25,6 @@ class NativeWriteStream extends NativeStream { $this->writeBuffer = fopen('php://memory', 'r+'); return parent::stream_open($path, $mode, $options, $opened_path); - } /** @@ -39,13 +38,13 @@ class NativeWriteStream extends NativeStream { */ public static function wrap($state, $smbStream, $mode, $url) { stream_wrapper_register('nativesmb', NativeWriteStream::class); - $context = stream_context_create(array( - 'nativesmb' => array( + $context = stream_context_create([ + 'nativesmb' => [ 'state' => $state, 'handle' => $smbStream, 'url' => $url - ) - )); + ] + ]); $fh = fopen('nativesmb://', $mode, false, $context); stream_wrapper_unregister('nativesmb'); return $fh; diff --git a/src/Options.php b/src/Options.php index 0afd852..7a0d014 100644 --- a/src/Options.php +++ b/src/Options.php @@ -21,7 +21,6 @@ namespace Icewind\SMB; - class Options implements IOptions { /** @var int */ private $timeout = 20; diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 78e0b72..807b0b8 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -21,7 +21,6 @@ namespace Icewind\SMB; - use Icewind\SMB\Exception\DependencyException; use Icewind\SMB\Native\NativeServer; use Icewind\SMB\Wrapped\Server; diff --git a/src/System.php b/src/System.php index 4571951..5f0130d 100644 --- a/src/System.php +++ b/src/System.php @@ -52,7 +52,7 @@ class System implements ISystem { protected function getBinaryPath($binary) { if (!isset($this->paths[$binary])) { $result = null; - $output = array(); + $output = []; exec("which $binary 2>&1", $output, $result); $this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : false; } diff --git a/src/TimeZoneProvider.php b/src/TimeZoneProvider.php index 14deb57..a4b6745 100644 --- a/src/TimeZoneProvider.php +++ b/src/TimeZoneProvider.php @@ -30,7 +30,8 @@ class TimeZoneProvider implements ITimeZoneProvider { $net = $this->system->getNetPath(); // for local domain names we can assume same timezone if ($net && $host && strpos($host, '.') !== false) { - $command = sprintf('%s time zone -S %s', + $command = sprintf( + '%s time zone -S %s', $net, escapeshellarg($host) ); diff --git a/src/Wrapped/Connection.php b/src/Wrapped/Connection.php index 7eddb85..de0a1de 100644 --- a/src/Wrapped/Connection.php +++ b/src/Wrapped/Connection.php @@ -20,7 +20,7 @@ class Connection extends RawConnection { /** @var Parser */ private $parser; - public function __construct($command, Parser $parser, $env = array()) { + public function __construct($command, Parser $parser, $env = []) { parent::__construct($command, $env); $this->parser = $parser; } @@ -65,7 +65,7 @@ class Connection extends RawConnection { $promptLine = $this->readLine(); //first line is prompt $this->parser->checkConnectionError($promptLine); - $output = array(); + $output = []; $line = $this->readLine(); if ($line === false) { $this->unknownError($promptLine); diff --git a/src/Wrapped/NotifyHandler.php b/src/Wrapped/NotifyHandler.php index a32ae3c..0907343 100644 --- a/src/Wrapped/NotifyHandler.php +++ b/src/Wrapped/NotifyHandler.php @@ -8,7 +8,6 @@ namespace Icewind\SMB\Wrapped; - use Icewind\SMB\Change; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\RevisionMismatchException; diff --git a/src/Wrapped/Parser.php b/src/Wrapped/Parser.php index a99cb53..9eee686 100644 --- a/src/Wrapped/Parser.php +++ b/src/Wrapped/Parser.php @@ -141,7 +141,7 @@ class Parser { $value = trim($value); if (!isset($data[$name])) { - $data[$name] = $value; + $data[$name] = $value; } } return [ @@ -156,7 +156,7 @@ class Parser { array_pop($output); $regex = '/^\s*(.*?)\s\s\s\s+(?:([NDHARS]*)\s+)?([0-9]+)\s+(.*)$/'; //2 spaces, filename, optional type, size, date - $content = array(); + $content = []; foreach ($output as $line) { if (preg_match($regex, $line, $matches)) { list(, $name, $mode, $size, $time) = $matches; @@ -171,14 +171,14 @@ class Parser { } public function parseListShares($output) { - $shareNames = array(); + $shareNames = []; foreach ($output as $line) { if (strpos($line, '|')) { list($type, $name, $description) = explode('|', $line); if (strtolower($type) === 'disk') { $shareNames[$name] = $description; } - } else if (strpos($line, 'Disk')) { + } elseif (strpos($line, 'Disk')) { // new output format list($name, $description) = explode('Disk', $line); $shareNames[trim($name)] = trim($description); diff --git a/src/Wrapped/Server.php b/src/Wrapped/Server.php index d15428a..b3763a7 100644 --- a/src/Wrapped/Server.php +++ b/src/Wrapped/Server.php @@ -42,7 +42,8 @@ class Server extends AbstractServer { * @throws ConnectException */ public function listShares() { - $command = sprintf('%s %s %s -L %s', + $command = sprintf( + '%s %s %s -L %s', $this->system->getSmbclientPath(), $this->getAuthFileArgument(), $this->getAuth()->getExtraCommandLineArguments(), @@ -73,7 +74,7 @@ class Server extends AbstractServer { $shareNames = $parser->parseListShares($output); - $shares = array(); + $shares = []; foreach ($shareNames as $name => $description) { $shares[] = $this->getShare($name); } diff --git a/src/Wrapped/Share.php b/src/Wrapped/Share.php index c7e78fd..f112781 100644 --- a/src/Wrapped/Share.php +++ b/src/Wrapped/Share.php @@ -76,7 +76,8 @@ class Share extends AbstractShare { } protected function getConnection() { - $command = sprintf('%s%s -t %s %s %s %s', + $command = sprintf( + '%s%s -t %s %s %s %s', $this->system->getStdBufPath() ? $this->system->getStdBufPath() . ' -o0 ' : '', $this->system->getSmbclientPath(), $this->server->getOptions()->getTimeout(), @@ -161,7 +162,7 @@ class Share extends AbstractShare { if ($path !== "" && $path !== "/") { $parent = dirname($path); $dir = $this->dir($parent); - $file = array_values(array_filter($dir, function(IFileInfo $info) use ($path) { + $file = array_values(array_filter($dir, function (IFileInfo $info) use ($path) { return $info->getPath() === $path; })); if ($file) { diff --git a/tests/AbstractShareTest.php b/tests/AbstractShareTest.php index bff3897..6d65999 100644 --- a/tests/AbstractShareTest.php +++ b/tests/AbstractShareTest.php @@ -44,47 +44,47 @@ abstract class AbstractShareTest extends TestCase { } public function nameProvider() { - return array( - array('simple'), - array('with spaces_and-underscores'), - array("single'quote'"), - array("foo ; asd -- bar"), - array('日本語'), - array('url %2F +encode'), - array('a somewhat longer filename than the other with more charaters as the all the other filenames'), - array('$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫ') - ); + return [ + ['simple'], + ['with spaces_and-underscores'], + ["single'quote'"], + ["foo ; asd -- bar"], + ['日本語'], + ['url %2F +encode'], + ['a somewhat longer filename than the other with more charaters as the all the other filenames'], + ['$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫ'] + ]; } public function invalidPathProvider() { // / ? < > \ : * | " are illegal characters in path on windows - return array( - array("new\nline"), - array("\rreturn"), - array('null' . chr(0) . 'byte'), - array('foo?bar'), - array('foo'), - array('foo:bar'), - array('foo*bar'), - array('foo|bar'), - array('foo"bar"') - ); + return [ + ["new\nline"], + ["\rreturn"], + ['null' . chr(0) . 'byte'], + ['foo?bar'], + ['foo'], + ['foo:bar'], + ['foo*bar'], + ['foo|bar'], + ['foo"bar"'] + ]; } public function fileDataProvider() { - return array( - array('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'), - array('Mixed language, 日本語 が わからか and Various _/* characters \\|” €') - ); + return [ + ['Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'], + ['Mixed language, 日本語 が わからか and Various _/* characters \\|” €'] + ]; } public function nameAndDataProvider() { $names = $this->nameProvider(); $data = $this->fileDataProvider(); - $result = array(); + $result = []; foreach ($names as $name) { foreach ($data as $text) { - $result[] = array($name[0], $text[0]); + $result[] = [$name[0], $text[0]]; } } return $result; @@ -122,7 +122,7 @@ abstract class AbstractShareTest extends TestCase { } public function testRootStartsEmpty() { - $this->assertEquals(array(), $this->share->dir($this->root)); + $this->assertEquals([], $this->share->dir($this->root)); } /** @@ -625,16 +625,16 @@ abstract class AbstractShareTest extends TestCase { public function pathProvider() { // / ? < > \ : * | " are illegal characters in path on windows - return array( - array('dir/sub/foo.txt'), - array('bar.txt'), - array("single'quote'/sub/foo.txt"), - array('日本語/url %2F +encode/asd.txt'), - array( + return [ + ['dir/sub/foo.txt'], + ['bar.txt'], + ["single'quote'/sub/foo.txt"], + ['日本語/url %2F +encode/asd.txt'], + [ 'a somewhat longer folder than the other with more charaters as the all the other filenames/' . 'followed by a somewhat long file name after that.txt' - ) - ); + ] + ]; } /** diff --git a/tests/NotifyHandlerTest.php b/tests/NotifyHandlerTest.php index 4fc57d3..137d4cc 100644 --- a/tests/NotifyHandlerTest.php +++ b/tests/NotifyHandlerTest.php @@ -84,7 +84,6 @@ class NotifyHandlerTest extends TestCase { try { $share->mkdir('sub'); } catch (AlreadyExistsException $e) { - } $process = $share->notify('sub'); usleep(1000 * 100);// give it some time to start listening diff --git a/tests/ParserTest.php b/tests/ParserTest.php index ec427ad..d0c3f74 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -7,22 +7,21 @@ namespace Icewind\SMB\Test; - use Icewind\SMB\IFileInfo; use Icewind\SMB\Wrapped\FileInfo; class ParserTest extends \PHPUnit_Framework_TestCase { public function modeProvider() { - return array( - array('D', IFileInfo::MODE_DIRECTORY), - array('A', IFileInfo::MODE_ARCHIVE), - array('S', IFileInfo::MODE_SYSTEM), - array('H', IFileInfo::MODE_HIDDEN), - array('R', IFileInfo::MODE_READONLY), - array('N', IFileInfo::MODE_NORMAL), - array('RA', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE), - array('RAH', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE | IFileInfo::MODE_HIDDEN) - ); + return [ + ['D', IFileInfo::MODE_DIRECTORY], + ['A', IFileInfo::MODE_ARCHIVE], + ['S', IFileInfo::MODE_SYSTEM], + ['H', IFileInfo::MODE_HIDDEN], + ['R', IFileInfo::MODE_READONLY], + ['N', IFileInfo::MODE_NORMAL], + ['RA', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE], + ['RAH', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE | IFileInfo::MODE_HIDDEN] + ]; } /** * @dataProvider modeProvider @@ -33,9 +32,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase { } public function statProvider() { - return array( - array( - array( + return [ + [ + [ 'altname: test.txt', 'create_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'access_time: Tue Oct 15 02:58:48 PM 2013 CEST', @@ -43,15 +42,15 @@ class ParserTest extends \PHPUnit_Framework_TestCase { 'change_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'attributes: (80)', 'stream: [::$DATA], 29634 bytes' - ), - array( + ], + [ 'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'), - 'mode' => IFileInfo::MODE_NORMAL, - 'size' => 29634 - ) - ), - array( - array( + 'mode' => IFileInfo::MODE_NORMAL, + 'size' => 29634 + ] + ], + [ + [ 'altname: folder', 'create_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'access_time: Tue Oct 15 02:58:48 PM 2013 CEST', @@ -59,15 +58,15 @@ class ParserTest extends \PHPUnit_Framework_TestCase { 'change_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'attributes: D (10)', 'stream: [::$DATA], 29634 bytes' - ), - array( + ], + [ 'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'), - 'mode' => IFileInfo::MODE_DIRECTORY, - 'size' => 29634 - ) - ), - array( - array( + 'mode' => IFileInfo::MODE_DIRECTORY, + 'size' => 29634 + ] + ], + [ + [ 'altname: .hidden', 'create_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'access_time: Tue Oct 15 02:58:48 PM 2013 CEST', @@ -75,14 +74,14 @@ class ParserTest extends \PHPUnit_Framework_TestCase { 'change_time: Sat Oct 12 07:05:58 PM 2013 CEST', 'attributes: HA (22)', 'stream: [::$DATA], 29634 bytes' - ), - array( + ], + [ 'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'), - 'mode' => IFileInfo::MODE_HIDDEN + IFileInfo::MODE_ARCHIVE, - 'size' => 29634 - ) - ) - ); + 'mode' => IFileInfo::MODE_HIDDEN + IFileInfo::MODE_ARCHIVE, + 'size' => 29634 + ] + ] + ]; } /** @@ -94,21 +93,26 @@ class ParserTest extends \PHPUnit_Framework_TestCase { } public function dirProvider() { - return array( - array( - array( + return [ + [ + [ ' . D 0 Tue Aug 26 19:11:56 2014', ' .. DR 0 Sun Oct 28 15:24:02 2012', ' c.pdf N 29634 Sat Oct 12 19:05:58 2013', '', ' 62536 blocks of size 8388608. 57113 blocks available' - ), - array( - new FileInfo('/c.pdf', 'c.pdf', 29634, strtotime('12 Oct 2013 19:05:58 CEST'), - IFileInfo::MODE_NORMAL) - ) - ) - ); + ], + [ + new FileInfo( + '/c.pdf', + 'c.pdf', + 29634, + strtotime('12 Oct 2013 19:05:58 CEST'), + IFileInfo::MODE_NORMAL + ) + ] + ] + ]; } /** diff --git a/tests/ServerFactoryTest.php b/tests/ServerFactoryTest.php index 82e7de1..cb39999 100644 --- a/tests/ServerFactoryTest.php +++ b/tests/ServerFactoryTest.php @@ -21,7 +21,6 @@ namespace Icewind\SMB\Test; - use Icewind\SMB\AnonymousAuth; use Icewind\SMB\IAuth; use Icewind\SMB\Native\NativeServer;