formatting

This commit is contained in:
Robin Appelman 2021-03-02 19:25:43 +01:00
commit fdc0e3f113
21 changed files with 118 additions and 111 deletions

View file

@ -23,7 +23,6 @@
namespace Icewind\Streams; namespace Icewind\Streams;
abstract class HashWrapper extends Wrapper { abstract class HashWrapper extends Wrapper {
/** /**
@ -76,5 +75,4 @@ abstract class HashWrapper extends Wrapper {
} }
return parent::stream_close(); return parent::stream_close();
} }
} }

View file

@ -48,8 +48,16 @@ class UrlCallback extends Wrapper implements Url {
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
*/ */
public static function wrap($source, $fopen = null, $opendir = null, $mkdir = null, $rename = null, $rmdir = null, public static function wrap(
$unlink = null, $stat = null) { $source,
$fopen = null,
$opendir = null,
$mkdir = null,
$rename = null,
$rmdir = null,
$unlink = null,
$stat = null
) {
return new Path(static::class, [ return new Path(static::class, [
'source' => $source, 'source' => $source,
'fopen' => $fopen, 'fopen' => $fopen,

View file

@ -21,7 +21,6 @@
namespace Icewind\Streams; namespace Icewind\Streams;
class WrapperHandler { class WrapperHandler {
const NO_SOURCE_DIR = 1; const NO_SOURCE_DIR = 1;

View file

@ -21,7 +21,6 @@
namespace Icewind\Streams\Tests; namespace Icewind\Streams\Tests;
use Icewind\Streams\CountWrapper; use Icewind\Streams\CountWrapper;
class CountWrapperTest extends WrapperTest { class CountWrapperTest extends WrapperTest {

View file

@ -9,36 +9,39 @@ namespace Icewind\Streams\Tests;
class DirectoryFilter extends \PHPUnit_Framework_TestCase { class DirectoryFilter extends \PHPUnit_Framework_TestCase {
public function testFilterAcceptAll() { public function testFilterAcceptAll() {
$this->filter(array('a', 'b', 'c'), $this->filter(
['a', 'b', 'c'],
function () { function () {
return true; return true;
}, },
array('a', 'b', 'c') ['a', 'b', 'c']
); );
} }
public function testFilterRejectAll() { public function testFilterRejectAll() {
$this->filter(array('a', 'b', 'c'), $this->filter(
['a', 'b', 'c'],
function () { function () {
return false; return false;
}, },
array() []
); );
} }
public function testFilterRejectLong() { public function testFilterRejectLong() {
$this->filter(array('a', 'bb', 'c'), $this->filter(
['a', 'bb', 'c'],
function ($file) { function ($file) {
return strlen($file) < 2; return strlen($file) < 2;
}, },
array('a', 'c') ['a', 'c']
); );
} }
private function filter(array $files, callable $filter, array $expected) { private function filter(array $files, callable $filter, array $expected) {
$source = \Icewind\Streams\IteratorDirectory::wrap($files); $source = \Icewind\Streams\IteratorDirectory::wrap($files);
$filtered = \Icewind\Streams\DirectoryFilter::wrap($source, $filter); $filtered = \Icewind\Streams\DirectoryFilter::wrap($source, $filter);
$result = array(); $result = [];
while (($file = readdir($filtered)) !== false) { while (($file = readdir($filtered)) !== false) {
$result[] = $file; $result[] = $file;
} }

View file

@ -19,12 +19,12 @@ class DirectoryWrapper extends IteratorDirectory {
} }
public function testManipulateContent() { public function testManipulateContent() {
$source = \Icewind\Streams\IteratorDirectory::wrap(array('asd', 'bar')); $source = \Icewind\Streams\IteratorDirectory::wrap(['asd', 'bar']);
$wrapped = DirectoryWrapperDummy::wrap($source); $wrapped = DirectoryWrapperDummy::wrap($source);
$result = array(); $result = [];
while (($file = readdir($wrapped)) !== false) { while (($file = readdir($wrapped)) !== false) {
$result[] = $file; $result[] = $file;
} }
$this->assertEquals(array('asd_', 'bar_'), $result); $this->assertEquals(['asd_', 'bar_'], $result);
} }
} }

View file

@ -21,7 +21,7 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testNoContext() { public function testNoContext() {
$context = stream_context_create(array()); $context = stream_context_create([]);
stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory'); stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
try { try {
opendir('iterator://', $context); opendir('iterator://', $context);
@ -36,11 +36,11 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
* @expectedException \BadMethodCallException * @expectedException \BadMethodCallException
*/ */
public function testNoSource() { public function testNoSource() {
$context = stream_context_create(array( $context = stream_context_create([
'dir' => array( 'dir' => [
'foo' => 'bar' 'foo' => 'bar'
) ]
)); ]);
stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory'); stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
try { try {
opendir('iterator://', $context); opendir('iterator://', $context);
@ -60,16 +60,16 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
public function fileListProvider() { public function fileListProvider() {
$longList = array_fill(0, 500, 'foo'); $longList = array_fill(0, 500, 'foo');
return array( return [
array( [
array( [
'foo', 'foo',
'bar', 'bar',
'qwerty' 'qwerty'
) ]
), ],
array( [
array( [
'with spaces', 'with spaces',
'under_scores', 'under_scores',
'日本語', '日本語',
@ -78,24 +78,24 @@ class IteratorDirectory extends \PHPUnit_Framework_TestCase {
'0', '0',
'double "quotes"', 'double "quotes"',
"single 'quotes'" "single 'quotes'"
) ]
), ],
array( [
array( [
'single item' 'single item'
) ]
), ],
array( [
$longList $longList
), ],
array( [
array() []
) ]
); ];
} }
protected function basicTest($fileList, $dh) { protected function basicTest($fileList, $dh) {
$result = array(); $result = [];
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
$result[] = $file; $result[] = $file;

View file

@ -20,7 +20,7 @@ class NullWrapperTest extends WrapperTest {
public function testNoContext() { public function testNoContext() {
$this->expectException(\BadMethodCallException::class); $this->expectException(\BadMethodCallException::class);
stream_wrapper_register('null', '\Icewind\Streams\NullWrapper'); stream_wrapper_register('null', '\Icewind\Streams\NullWrapper');
$context = stream_context_create(array()); $context = stream_context_create([]);
try { try {
fopen('null://', 'r+', false, $context); fopen('null://', 'r+', false, $context);
stream_wrapper_unregister('null'); stream_wrapper_unregister('null');
@ -33,11 +33,11 @@ class NullWrapperTest extends WrapperTest {
public function testNoSource() { public function testNoSource() {
$this->expectException(\BadMethodCallException::class); $this->expectException(\BadMethodCallException::class);
stream_wrapper_register('null', '\Icewind\Streams\NullWrapper'); stream_wrapper_register('null', '\Icewind\Streams\NullWrapper');
$context = stream_context_create(array( $context = stream_context_create([
'null' => array( 'null' => [
'source' => 'bar' 'source' => 'bar'
) ]
)); ]);
try { try {
fopen('null://', 'r+', false, $context); fopen('null://', 'r+', false, $context);
} catch (\Exception $e) { } catch (\Exception $e) {

View file

@ -8,7 +8,7 @@
namespace Icewind\Streams\Tests; namespace Icewind\Streams\Tests;
class UrlCallback extends \PHPUnit_Framework_TestCase { class UrlCallback extends \PHPUnit_Framework_TestCase {
protected $tempDirs = array(); protected $tempDirs = [];
protected function getTempDir() { protected function getTempDir() {
$dir = sys_get_temp_dir() . '/streams_' . uniqid(); $dir = sys_get_temp_dir() . '/streams_' . uniqid();
@ -30,7 +30,7 @@ class UrlCallback extends \PHPUnit_Framework_TestCase {
* @var \SplFileInfo $file * @var \SplFileInfo $file
*/ */
foreach ($iterator as $file) { foreach ($iterator as $file) {
if (in_array($file->getBasename(), array('.', '..'))) { if (in_array($file->getBasename(), ['.', '..'])) {
continue; continue;
} elseif ($file->isDir()) { } elseif ($file->isDir()) {
rmdir($file->getPathname()); rmdir($file->getPathname());

View file

@ -109,7 +109,7 @@ abstract class WrapperTest extends TestCase {
public function testReadDir() { public function testReadDir() {
$source = opendir(__DIR__); $source = opendir(__DIR__);
$content = array(); $content = [];
while (($name = readdir($source)) !== false) { while (($name = readdir($source)) !== false) {
$content[] = $name; $content[] = $name;
} }
@ -117,7 +117,7 @@ abstract class WrapperTest extends TestCase {
$source = opendir(__DIR__); $source = opendir(__DIR__);
$wrapped = $this->wrapSource($source); $wrapped = $this->wrapSource($source);
$wrappedContent = array(); $wrappedContent = [];
while (($name = readdir($wrapped)) !== false) { while (($name = readdir($wrapped)) !== false) {
$wrappedContent[] = $name; $wrappedContent[] = $name;
} }
@ -126,7 +126,7 @@ abstract class WrapperTest extends TestCase {
public function testRewindDir() { public function testRewindDir() {
$source = opendir(__DIR__); $source = opendir(__DIR__);
$content = array(); $content = [];
while (($name = readdir($source)) !== false) { while (($name = readdir($source)) !== false) {
$content[] = $name; $content[] = $name;
} }