Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kapersoft committed Sep 11, 2017
2 parents 64eb242 + f1f0780 commit 8b1ad11
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
52 changes: 26 additions & 26 deletions src/SharefileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function has($path)
*/
public function read($path)
{
if (!$item = $this->getItemByPath($path)) {
if (! $item = $this->getItemByPath($path)) {
return false;
}

if (!$this->checkAccessControl($item, self::CAN_DOWNLOAD)) {
if (! $this->checkAccessControl($item, self::CAN_DOWNLOAD)) {
return false;
}

Expand All @@ -98,7 +98,7 @@ public function read($path)
*/
public function listContents($directory = '', $recursive = false)
{
if (!$item = $this->getItemByPath($directory)) {
if (! $item = $this->getItemByPath($directory)) {
return false;
}

Expand All @@ -110,7 +110,7 @@ public function listContents($directory = '', $recursive = false)
*/
public function getMetadata($path)
{
if (!$item = $this->getItemByPath($path)) {
if (! $item = $this->getItemByPath($path)) {
return false;
}
$metadata = $this->mapItemInfo($item, Util::dirname($path));
Expand Down Expand Up @@ -167,15 +167,15 @@ public function update($path, $contents, Config $config = null)
*/
public function rename($path, $newpath)
{
if (!$targetFolderItem = $this->getItemByPath(Util::dirname($newpath))) {
if (! $targetFolderItem = $this->getItemByPath(Util::dirname($newpath))) {
return false;
}

if (!$this->checkAccessControl($targetFolderItem, self::CAN_UPLOAD)) {
if (! $this->checkAccessControl($targetFolderItem, self::CAN_UPLOAD)) {
return false;
}

if (!$item = $this->getItemByPath($path)) {
if (! $item = $this->getItemByPath($path)) {
return false;
}

Expand All @@ -197,15 +197,15 @@ public function rename($path, $newpath)
*/
public function copy($path, $newpath)
{
if (!$targetFolderItem = $this->getItemByPath(Util::dirname($newpath))) {
if (! $targetFolderItem = $this->getItemByPath(Util::dirname($newpath))) {
return false;
}

if (!$this->checkAccessControl($targetFolderItem, self::CAN_UPLOAD)) {
if (! $this->checkAccessControl($targetFolderItem, self::CAN_UPLOAD)) {
return false;
}

if (!$item = $this->getItemByPath($path)) {
if (! $item = $this->getItemByPath($path)) {
return false;
}

Expand Down Expand Up @@ -233,11 +233,11 @@ public function delete($path)
*/
public function deleteDir($dirname)
{
if (!$item = $this->getItemByPath($dirname)) {
if (! $item = $this->getItemByPath($dirname)) {
return false;
}

if (!$this->checkAccessControl($item, self::CAN_DELETE_CURRENT_ITEM)) {
if (! $this->checkAccessControl($item, self::CAN_DELETE_CURRENT_ITEM)) {
return false;
}

Expand All @@ -254,11 +254,11 @@ public function createDir($dirname, Config $config = null)
$parentFolder = Util::dirname($dirname);
$folder = basename($dirname);

if (!$parentFolderItem = $this->getItemByPath($parentFolder)) {
if (! $parentFolderItem = $this->getItemByPath($parentFolder)) {
return false;
}

if (!$this->checkAccessControl($parentFolderItem, self::CAN_ADD_FOLDER)) {
if (! $this->checkAccessControl($parentFolderItem, self::CAN_ADD_FOLDER)) {
return false;
}

Expand All @@ -280,12 +280,12 @@ public function put($path, $contents)
*/
public function readAndDelete($path)
{
if (!$item = $this->getItemByPath($path)) {
if (! $item = $this->getItemByPath($path)) {
return false;
}

if (!$this->checkAccessControl($item, self::CAN_DOWNLOAD) ||
!$this->checkAccessControl($item, self::CAN_DELETE_CURRENT_ITEM)) {
if (! $this->checkAccessControl($item, self::CAN_DOWNLOAD) ||
! $this->checkAccessControl($item, self::CAN_DELETE_CURRENT_ITEM)) {
return false;
}

Expand Down Expand Up @@ -317,11 +317,11 @@ public function getClient(): Client
*/
protected function uploadFile(string $path, string $contents, bool $overwrite = false)
{
if (!$parentFolderItem = $this->getItemByPath(Util::dirname($path))) {
if (! $parentFolderItem = $this->getItemByPath(Util::dirname($path))) {
return false;
}

if (!$this->checkAccessControl($parentFolderItem, self::CAN_UPLOAD)) {
if (! $this->checkAccessControl($parentFolderItem, self::CAN_UPLOAD)) {
return false;
}

Expand Down Expand Up @@ -350,7 +350,7 @@ protected function uploadFile(string $path, string $contents, bool $overwrite =
*/
protected function prepareUploadFile(string $filename, string $contents):string
{
$filename = tempnam(sys_get_temp_dir(), '') . '/' . $filename;
$filename = tempnam(sys_get_temp_dir(), '').'/'.$filename;
unlink(Util::dirname($filename));
mkdir(Util::dirname($filename));
file_put_contents($filename, $contents);
Expand Down Expand Up @@ -382,12 +382,12 @@ protected function mapItemInfo(array $item, string $path = '', string $contents
{
$timestamp = $item['ClientModifiedDate'] ?? $item['ClientCreatedDate'] ??
$item['CreationDate'] ?? $item['ProgenyEditDate'] ?? '';
$timestamp = !empty($timestamp) ? strtotime($timestamp) : false;
$timestamp = ! empty($timestamp) ? strtotime($timestamp) : false;

if ($path == '.') {
$path = '';
}
$path = trim($path . '/' . $item['FileName'], '/');
$path = trim($path.'/'.$item['FileName'], '/');

if ($this->isShareFileApiModelsFile($item)) {
$mimetype = Util::guessMimeType($item['FileName'], $contents);
Expand All @@ -408,7 +408,7 @@ protected function mapItemInfo(array $item, string $path = '', string $contents
'basename' => pathinfo($item['FileName'], PATHINFO_FILENAME),
'type' => $type,
'size' => $item['FileSizeBytes'],
'contents' => !empty($contents) ? $contents : false,
'contents' => ! empty($contents) ? $contents : false,
'stream' => false,
],
$this->returnShareFileItem ? ['sharefile_item' => $item] : []
Expand Down Expand Up @@ -450,7 +450,7 @@ protected function buildItemList(array $item, string $path, bool $recursive = fa

$children = $this->client->getItemById($item['Id'], true);

if ($children['FileCount'] < 2 || !isset($children['Children'])) {
if ($children['FileCount'] < 2 || ! isset($children['Children'])) {
return [];
}

Expand All @@ -460,7 +460,7 @@ protected function buildItemList(array $item, string $path, bool $recursive = fa

if ($recursive) {
foreach ($children as $child) {
$path = $path . '/' . $child['FileName'];
$path = $path.'/'.$child['FileName'];

$itemList = array_merge(
$itemList,
Expand Down Expand Up @@ -527,7 +527,7 @@ protected function getItemByPath(string $path)
if ($path == '.') {
$path = '';
}
$path = '/' . trim($this->applyPathPrefix($path), '/');
$path = '/'.trim($this->applyPathPrefix($path), '/');

try {
$item = $this->client->getItemByPath($path);
Expand Down
2 changes: 1 addition & 1 deletion tests/SharefileAdapterFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Kapersoft\Sharefile\Client;

/**
* Online Flysystem ShareFile Adapter tests
* Online Flysystem ShareFile Adapter tests.
*
* @author Jan Willem Kaper <kapersoft@gmail.com>
* @license MIT (see License.txt)
Expand Down
32 changes: 16 additions & 16 deletions tests/SharefileAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Kapersoft\FlysystemSharefile\SharefileAdapter;

/**
* Offline Flysystem ShareFile Adapter tests
* Offline Flysystem ShareFile Adapter tests.
*
* @author Jan Willem Kaper <kapersoft@gmail.com>
* @license MIT (see License.txt)
Expand Down Expand Up @@ -169,11 +169,11 @@ public function it_can_list_contents(string $filename) // @codingStandardsIgnore
])
);

$sharefileItemFolder = $this->mockSharefileItem($directory . '/folder', [
$sharefileItemFolder = $this->mockSharefileItem($directory.'/folder', [
'odata.type' => 'ShareFile.Api.Models.Folder',
'Id' => '2',
]);
$sharefileItemFile = $this->mockSharefileItem($directory . '/folder/file.txt', [
$sharefileItemFile = $this->mockSharefileItem($directory.'/folder/file.txt', [
'odata.type' => 'ShareFile.Api.Models.File',
'Id' => '3',
]);
Expand All @@ -196,11 +196,11 @@ public function it_can_list_contents(string $filename) // @codingStandardsIgnore
$result = $this->adapter->listContents($directory, true);

$expectedResult = [
$this->calculateExpectedMetadata($directory . '/folder', [
$this->calculateExpectedMetadata($directory.'/folder', [
'mimetype' => 'inode/directory',
'type' => 'dir',
]),
$this->calculateExpectedMetadata($directory . '/folder/file.txt'),
$this->calculateExpectedMetadata($directory.'/folder/file.txt'),
];

$this->assertsame($expectedResult, $result);
Expand Down Expand Up @@ -302,7 +302,7 @@ public function it_can_writestream_updatestream(string $filename) // @codingStan
public function it_can_move_a_file(string $filename) // @codingStandardsIgnoreLine
{
$filenamePrefix = $this->applyPathPrefix($filename);
$newPath = '/targetfolder/new name of ' . basename($filename);
$newPath = '/targetfolder/new name of '.basename($filename);
$newPathPrefix = $this->applyPathPrefix($newPath);
$newPathParent = Util::dirname($newPathPrefix);

Expand Down Expand Up @@ -348,7 +348,7 @@ public function it_can_move_a_file(string $filename) // @codingStandardsIgnoreLi
public function it_will_return_false_when_a_move_has_failed(string $filename) // @codingStandardsIgnoreLine
{
$filenamePrefix = $this->applyPathPrefix($filename);
$newPath = '/targetfolder/new name of ' . basename($filename);
$newPath = '/targetfolder/new name of '.basename($filename);
$newPathPrefix = $this->applyPathPrefix($newPath);
$newPathParent = Util::dirname($newPathPrefix);

Expand Down Expand Up @@ -393,7 +393,7 @@ public function it_can_copy_a_file_to_a_new_folder(string $filename) // @codingS
{
$filename = basename($filename);
$filenamePrefix = $this->applyPathPrefix($filename);
$newPath = 'targetfolder/' . $filename;
$newPath = 'targetfolder/'.$filename;
$newPathPrefix = $this->applyPathPrefix($newPath);
$newPathParent = Util::dirname($newPathPrefix);

Expand Down Expand Up @@ -433,7 +433,7 @@ public function it_can_copy_a_file_to_same_folder(string $filename) // @codingSt
{
$filename = basename($filename);
$filenamePrefix = $this->applyPathPrefix($filename);
$newPath = 'copy of ' . $filename;
$newPath = 'copy of '.$filename;
$newPathPrefix = $this->applyPathPrefix($newPath);
$newPathParent = Util::dirname($newPathPrefix);

Expand Down Expand Up @@ -736,11 +736,11 @@ protected function filenames()
'test 1/test.txt',
'test/test 1.txt',
'test 1/test 2.txt',
$this->faker()->word . '/' . $this->randomFileName(),
$this->faker()->word . '/' . $this->randomFileName(),
$this->faker()->word . '/' . $this->randomFileName(),
$this->faker()->word . '/' . $this->randomFileName(),
$this->faker()->word . '/' . $this->randomFileName(),
$this->faker()->word.'/'.$this->randomFileName(),
$this->faker()->word.'/'.$this->randomFileName(),
$this->faker()->word.'/'.$this->randomFileName(),
$this->faker()->word.'/'.$this->randomFileName(),
$this->faker()->word.'/'.$this->randomFileName(),
];
}

Expand Down Expand Up @@ -808,7 +808,7 @@ protected function faker():Generator
*/
protected function randomFileName()
{
return $this->faker()->name . '.' . $this->faker()->fileExtension;
return $this->faker()->name.'.'.$this->faker()->fileExtension;
}

/**
Expand All @@ -820,6 +820,6 @@ protected function randomFileName()
*/
protected function applyPathPrefix(string $path):string
{
return '/' . trim($this->prefix, '/') . '/' . trim($path, '/');
return '/'.trim($this->prefix, '/').'/'.trim($path, '/');
}
}
28 changes: 14 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ abstract class TestCase extends PHPUnit_Framework_Testcase
*/
public function setUp()
{
if (!$this->checkEnvironmentVariables()) {
$this->markTestSkipped('No ShareFile credentials are found. ' .
'Fill in your ShareFile credentials under section <PHP> in the file ' .
if (! $this->checkEnvironmentVariables()) {
$this->markTestSkipped('No ShareFile credentials are found. '.
'Fill in your ShareFile credentials under section <PHP> in the file '.
'phpunit.xml.dist in the project root folder.');
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public function tearDown()
*/
protected function checkEnvironmentVariables():bool
{
return !$this->varEmpty(
return ! $this->varEmpty(
getenv('SHAREFILE_ROOT'),
getenv('SHAREFILE_HOSTNAME'),
getenv('SHAREFILE_CLIENT_ID'),
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function initializeResource()
{
$this->webdavRoot = getenv('WEBDAV_ROOT');

$guessedUrl = 'https://' . str_replace(
$guessedUrl = 'https://'.str_replace(
'sharefile.com',
'sharefile-webdav.com',
strtolower(getenv('SHAREFILE_HOSTNAME'))
Expand Down Expand Up @@ -232,15 +232,15 @@ protected function clearResources()
{
$location = $this->getResourceLocation('/');

$this->webdavClient->request('DELETE', $location . '/');
$this->webdavClient->request('DELETE', $location.'/');
}

/**
* Create random filename.
*/
protected function randomFileName():string
{
return $this->faker()->name . '.' . $this->faker()->fileExtension;
return $this->faker()->name.'.'.$this->faker()->fileExtension;
}

/**
Expand Down Expand Up @@ -319,11 +319,11 @@ public function withSubFolderProvider()
['test 1/test.txt'],
['test/test 1.txt'],
['test 1/test 2.txt'],
[$this->faker()->word . '/' . $this->randomFileName()],
[$this->faker()->word . '/' . $this->randomFileName()],
[$this->faker()->word . '/' . $this->randomFileName()],
[$this->faker()->word . '/' . $this->randomFileName()],
[$this->faker()->word . '/' . $this->randomFileName()],
[$this->faker()->word.'/'.$this->randomFileName()],
[$this->faker()->word.'/'.$this->randomFileName()],
[$this->faker()->word.'/'.$this->randomFileName()],
[$this->faker()->word.'/'.$this->randomFileName()],
[$this->faker()->word.'/'.$this->randomFileName()],
];
}

Expand All @@ -337,8 +337,8 @@ public function copyFilesProvider()
$provider = [];
foreach ($this->filesProvider() as $filename) {
$filename = $filename[0];
$provider[] = [$filename, '/target/' . $filename];
$provider[] = [$filename, 'copy of ' . basename($filename)];
$provider[] = [$filename, '/target/'.$filename];
$provider[] = [$filename, 'copy of '.basename($filename)];
}

return $provider;
Expand Down

0 comments on commit 8b1ad11

Please sign in to comment.