Skip to content

Commit fad4a97

Browse files
mhetrerameshStyleCIBot
authored andcommitted
Apply fixes from StyleCI
1 parent 9ba55f2 commit fad4a97

File tree

3 files changed

+62
-54
lines changed

3 files changed

+62
-54
lines changed

phpunit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
require __DIR__.'/vendor/autoload.php';
3+
require __DIR__.'/vendor/autoload.php';

src/BackblazeAdapter.php

+36-29
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Mhetreramesh\Flysystem;
44

55
use BackblazeB2\Client;
6+
use GuzzleHttp\Psr7;
67
use League\Flysystem\Adapter\AbstractAdapter;
78
use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait;
89
use League\Flysystem\Config;
9-
use GuzzleHttp\Psr7;
10-
11-
class BackblazeAdapter extends AbstractAdapter {
1210

11+
class BackblazeAdapter extends AbstractAdapter
12+
{
1313
use NotSupportingVisibilityTrait;
1414

1515
protected $client;
@@ -37,9 +37,10 @@ public function write($path, $contents, Config $config)
3737
{
3838
$file = $this->getClient()->upload([
3939
'BucketName' => $this->bucketName,
40-
'FileName' => $path,
41-
'Body' => $contents
40+
'FileName' => $path,
41+
'Body' => $contents,
4242
]);
43+
4344
return $this->getFileInfo($file);
4445
}
4546

@@ -50,9 +51,10 @@ public function writeStream($path, $resource, Config $config)
5051
{
5152
$file = $this->getClient()->upload([
5253
'BucketName' => $this->bucketName,
53-
'FileName' => $path,
54-
'Body' => $resource
54+
'FileName' => $path,
55+
'Body' => $resource,
5556
]);
57+
5658
return $this->getFileInfo($file);
5759
}
5860

@@ -63,9 +65,10 @@ public function update($path, $contents, Config $config)
6365
{
6466
$file = $this->getClient()->upload([
6567
'BucketName' => $this->bucketName,
66-
'FileName' => $path,
67-
'Body' => $contents
68+
'FileName' => $path,
69+
'Body' => $contents,
6870
]);
71+
6972
return $this->getFileInfo($file);
7073
}
7174

@@ -76,9 +79,10 @@ public function updateStream($path, $resource, Config $config)
7679
{
7780
$file = $this->getClient()->upload([
7881
'BucketName' => $this->bucketName,
79-
'FileName' => $path,
80-
'Body' => $resource
82+
'FileName' => $path,
83+
'Body' => $resource,
8184
]);
85+
8286
return $this->getFileInfo($file);
8387
}
8488

@@ -89,11 +93,12 @@ public function read($path)
8993
{
9094
$file = $this->getClient()->getFile([
9195
'BucketName' => $this->bucketName,
92-
'FileName' => $path
96+
'FileName' => $path,
9397
]);
9498
$fileContent = $this->getClient()->download([
95-
'FileId' => $file->getId()
99+
'FileId' => $file->getId(),
96100
]);
101+
97102
return ['contents' => $fileContent];
98103
}
99104

@@ -105,15 +110,17 @@ public function readStream($path)
105110
$stream = Psr7\stream_for();
106111
$download = $this->getClient()->download([
107112
'BucketName' => $this->bucketName,
108-
'FileName' => $path,
109-
'SaveAs' => $stream,
113+
'FileName' => $path,
114+
'SaveAs' => $stream,
110115
]);
111116
$stream->seek(0);
117+
112118
try {
113119
$resource = Psr7\StreamWrapper::getResource($stream);
114120
} catch (InvalidArgumentException $e) {
115121
return false;
116122
}
123+
117124
return $download === true ? ['stream' => $resource] : false;
118125
}
119126

@@ -132,8 +139,8 @@ public function copy($path, $newPath)
132139
{
133140
return $this->getClient()->upload([
134141
'BucketName' => $this->bucketName,
135-
'FileName' => $newPath,
136-
'Body' => @file_get_contents($path)
142+
'FileName' => $newPath,
143+
'Body' => @file_get_contents($path),
137144
]);
138145
}
139146

@@ -160,8 +167,8 @@ public function createDir($path, Config $config)
160167
{
161168
return $this->getClient()->upload([
162169
'BucketName' => $this->bucketName,
163-
'FileName' => $path,
164-
'Body' => ''
170+
'FileName' => $path,
171+
'Body' => '',
165172
]);
166173
}
167174

@@ -219,12 +226,12 @@ public function listContents($directory = '', $recursive = false)
219226
]);
220227
if ($recursive === true && $directory === '') {
221228
$regex = '/^.*$/';
222-
} else if ($recursive === true && $directory !== '') {
223-
$regex = '/^' . preg_quote($directory) . '\/.*$/';
224-
} else if ($recursive === false && $directory === '') {
229+
} elseif ($recursive === true && $directory !== '') {
230+
$regex = '/^'.preg_quote($directory).'\/.*$/';
231+
} elseif ($recursive === false && $directory === '') {
225232
$regex = '/^(?!.*\\/).*$/';
226-
} else if ($recursive === false && $directory !== '') {
227-
$regex = '/^' . preg_quote($directory) . '\/(?!.*\\/).*$/';
233+
} elseif ($recursive === false && $directory !== '') {
234+
$regex = '/^'.preg_quote($directory).'\/(?!.*\\/).*$/';
228235
} else {
229236
throw new \InvalidArgumentException();
230237
}
@@ -234,24 +241,24 @@ public function listContents($directory = '', $recursive = false)
234241
$normalized = array_map(function ($fileObject) {
235242
return $this->getFileInfo($fileObject);
236243
}, $fileObjects);
244+
237245
return array_values($normalized);
238246
}
239247

240248
/**
241-
* Get file info
249+
* Get file info.
242250
*
243251
* @param $file
244252
*
245253
* @return array
246254
*/
247-
248255
protected function getFileInfo($file)
249256
{
250257
$normalized = [
251-
'type' => 'file',
252-
'path' => $file->getName(),
258+
'type' => 'file',
259+
'path' => $file->getName(),
253260
'timestamp' => substr($file->getUploadTimestamp(), 0, -3),
254-
'size' => $file->getSize()
261+
'size' => $file->getSize(),
255262
];
256263

257264
return $normalized;

tests/BackblazeAdapterTests.php

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

3-
use BackblazeB2\Client;
4-
use Mhetreramesh\Flysystem\BackblazeAdapter as Backblaze;
53
use BackblazeB2\File;
6-
use \League\Flysystem\Config;
4+
use League\Flysystem\Config;
5+
use Mhetreramesh\Flysystem\BackblazeAdapter as Backblaze;
76

87
class BackblazeAdapterTests extends PHPUnit_Framework_TestCase
98
{
@@ -17,7 +16,8 @@ class BackblazeAdapterTests extends PHPUnit_Framework_TestCase
1716
*/
1817
private $file_mock;
1918

20-
private function fileSetUp() {
19+
private function fileSetUp()
20+
{
2121
$this->fs_mock = \org\bovigo\vfs\vfsStream::setup();
2222
$this->file_mock = new \org\bovigo\vfs\vfsStreamFile('filename.ext');
2323
$this->fs_mock->addChild($this->file_mock);
@@ -26,6 +26,7 @@ private function fileSetUp() {
2626
public function backblazeProvider()
2727
{
2828
$mock = $this->prophesize('BackblazeB2\Client');
29+
2930
return [
3031
[new Backblaze($mock->reveal(), 'my_bucket'), $mock],
3132
];
@@ -36,7 +37,7 @@ public function backblazeProvider()
3637
*/
3738
public function testHas($adapter, $mock)
3839
{
39-
$mock->fileExists(["BucketName" => "my_bucket", "FileName" => "something"])->willReturn(true);
40+
$mock->fileExists(['BucketName' => 'my_bucket', 'FileName' => 'something'])->willReturn(true);
4041
$result = $adapter->has('something');
4142
$this->assertTrue($result);
4243
}
@@ -46,7 +47,7 @@ public function testHas($adapter, $mock)
4647
*/
4748
public function testWrite($adapter, $mock)
4849
{
49-
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something", "Body" => "contents"])->willReturn(new File('something','','','',''), false);
50+
$mock->upload(['BucketName' => 'my_bucket', 'FileName' => 'something', 'Body' => 'contents'])->willReturn(new File('something', '', '', '', ''), false);
5051
$result = $adapter->write('something', 'contents', new Config());
5152
$this->assertInternalType('array', $result);
5253
$this->assertArrayHasKey('type', $result);
@@ -58,7 +59,7 @@ public function testWrite($adapter, $mock)
5859
*/
5960
public function testWriteStream($adapter, $mock)
6061
{
61-
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something", "Body" => "contents"])->willReturn(new File('something','','','',''), false);
62+
$mock->upload(['BucketName' => 'my_bucket', 'FileName' => 'something', 'Body' => 'contents'])->willReturn(new File('something', '', '', '', ''), false);
6263
$result = $adapter->writeStream('something', 'contents', new Config());
6364
$this->assertInternalType('array', $result);
6465
$this->assertArrayHasKey('type', $result);
@@ -70,7 +71,7 @@ public function testWriteStream($adapter, $mock)
7071
*/
7172
public function testUpdate($adapter, $mock)
7273
{
73-
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something", "Body" => "contents"])->willReturn(new File('something','','','',''), false);
74+
$mock->upload(['BucketName' => 'my_bucket', 'FileName' => 'something', 'Body' => 'contents'])->willReturn(new File('something', '', '', '', ''), false);
7475
$result = $adapter->update('something', 'contents', new Config());
7576
$this->assertInternalType('array', $result);
7677
$this->assertArrayHasKey('type', $result);
@@ -82,7 +83,7 @@ public function testUpdate($adapter, $mock)
8283
*/
8384
public function testUpdateStream($adapter, $mock)
8485
{
85-
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something", "Body" => "contents"])->willReturn(new File('something','','','',''), false);
86+
$mock->upload(['BucketName' => 'my_bucket', 'FileName' => 'something', 'Body' => 'contents'])->willReturn(new File('something', '', '', '', ''), false);
8687
$result = $adapter->updateStream('something', 'contents', new Config());
8788
$this->assertInternalType('array', $result);
8889
$this->assertArrayHasKey('type', $result);
@@ -94,9 +95,9 @@ public function testUpdateStream($adapter, $mock)
9495
*/
9596
public function testRead($adapter, $mock)
9697
{
97-
$file = new File('something','something4','','','','','my_bucket');
98-
$mock->getFile(["BucketName" => "my_bucket", "FileName" => "something"])->willReturn($file, false);
99-
$mock->download(["FileId" => "something"])->willReturn($file, false);
98+
$file = new File('something', 'something4', '', '', '', '', 'my_bucket');
99+
$mock->getFile(['BucketName' => 'my_bucket', 'FileName' => 'something'])->willReturn($file, false);
100+
$mock->download(['FileId' => 'something'])->willReturn($file, false);
100101
$result = $adapter->read('something');
101102
$this->assertEquals(['contents' => $file], $result);
102103
}
@@ -147,7 +148,7 @@ public function testGetMimetype($adapter, $mock)
147148
public function testCopy($adapter, $mock)
148149
{
149150
$this->fileSetUp();
150-
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something_new", "Body" => ""])->willReturn(new File('something_new','','','',''), false);
151+
$mock->upload(['BucketName' => 'my_bucket', 'FileName' => 'something_new', 'Body' => ''])->willReturn(new File('something_new', '', '', '', ''), false);
151152
$result = $adapter->copy($this->file_mock->url(), 'something_new');
152153
$this->assertObjectHasAttribute('id', $result, 'something_new');
153154
}
@@ -157,25 +158,25 @@ public function testCopy($adapter, $mock)
157158
*/
158159
public function testListContents($adapter, $mock)
159160
{
160-
$mock->listFiles(["BucketName" => "my_bucket"])->willReturn([new File('random_id', 'file1.txt'), new File('random_id', 'some_folder/file2.txt'), new File('random_id', 'some_folder/another_folder/file3.txt')]);
161+
$mock->listFiles(['BucketName' => 'my_bucket'])->willReturn([new File('random_id', 'file1.txt'), new File('random_id', 'some_folder/file2.txt'), new File('random_id', 'some_folder/another_folder/file3.txt')]);
161162
$normalized_files = [
162163
[
163-
'type' => 'file',
164-
'path' => 'file1.txt',
164+
'type' => 'file',
165+
'path' => 'file1.txt',
165166
'timestamp' => false,
166-
'size' => NULL,
167+
'size' => null,
167168
],
168169
[
169-
'type' => 'file',
170-
'path' => 'some_folder/file2.txt',
170+
'type' => 'file',
171+
'path' => 'some_folder/file2.txt',
171172
'timestamp' => false,
172-
'size' => NULL,
173+
'size' => null,
173174
],
174175
[
175-
'type' => 'file',
176-
'path' => 'some_folder/another_folder/file3.txt',
176+
'type' => 'file',
177+
'path' => 'some_folder/another_folder/file3.txt',
177178
'timestamp' => false,
178-
'size' => NULL,
179+
'size' => null,
179180
],
180181
];
181182
$result1 = $adapter->listContents('', false);
@@ -192,4 +193,4 @@ public function testListContents($adapter, $mock)
192193
$adapter->listContents(false, 'haha');
193194
$adapter->listContents('', 'haha');
194195
}
195-
}
196+
}

0 commit comments

Comments
 (0)