Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "CodeQL"

on: [pull_request]
jobs:
lint:
name: CodeQL
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- run: git checkout HEAD^2

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"type": "library",
"keywords": ["php","framework","upf","utopia","storage"],
"license": "MIT",
"authors": [],
"autoload": {
"psr-4": {"Utopia\\Storage\\":"src/Storage"}
},
Expand All @@ -13,7 +12,8 @@
},
"scripts": {
"lint": "./vendor/bin/pint --test",
"format": "./vendor/bin/pint"
"format": "./vendor/bin/pint",
"check": "./vendor/bin/phpstan analyse --level 5 src tests"
},
"require": {
"ext-fileinfo": "*",
Expand All @@ -28,6 +28,7 @@
"require-dev": {
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "4.0.1",
"phpstan/phpstan": "1.9.x-dev",
"laravel/pint": "1.2.*"
},
"minimum-stability": "dev"
Expand Down
81 changes: 71 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Storage/Device/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public function abort(string $path, string $extra = ''): bool
* Read file by given path.
*
* @param string $path
* @param int offset
* @param int|null $length
* @param int $offset
* @param int $length
* @return string
*
* @throws Exception
Expand Down
23 changes: 14 additions & 9 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ public function getPath(string $filename, string $prefix = null): string
*
* @param string $source
* @param string $path
* @param int chunk
* @param int chunks
* @param int $chunk
* @param int $chunks
* @param array $metadata
* @return int
*
* @throws \Exception
*/
Expand Down Expand Up @@ -347,11 +346,12 @@ public function abort(string $path, string $extra = ''): bool
* Read file or part of file by given path, offset and length.
*
* @param string $path
* @param int offset
* @param int length
* @param int $offset
* @param int $length
* @return string
*
* @throws \Exception
* @throws \Exception
*/
public function read(string $path, int $offset = 0, int $length = null): string
{
Expand Down Expand Up @@ -441,10 +441,13 @@ public function delete(string $path, bool $recursive = false): bool
/**
* Get list of objects in the given path.
*
* @param string $path
* @param string $prefix
* @param int $maxKeys
* @param string $continuationToken
* @return array
*
* @throws \Exception
* @throws \Exception
*/
private function listObjects($prefix = '', $maxKeys = 1000, $continuationToken = '')
{
Expand Down Expand Up @@ -642,7 +645,7 @@ private function getInfo(string $path): array
*
* @param string $method
* @param string $uri
* @param array parameters
* @param array $parameters
* @return string
*/
private function getSignatureV4(string $method, string $uri, array $parameters = []): string
Expand Down Expand Up @@ -769,7 +772,7 @@ private function call(string $method, string $uri, string $data = '', array $par

return \strlen($data);
});
curl_setopt($curl, CURLOPT_HEADERFUNCTION, function ($curl, string $header) use (&$response) {
\curl_setopt($curl, CURLOPT_HEADERFUNCTION, function ($curl, string $header) use (&$response) {
$len = strlen($header);
$header = explode(':', $header, 2);

Expand Down Expand Up @@ -810,7 +813,9 @@ private function call(string $method, string $uri, string $data = '', array $par
\curl_close($curl);

// Parse body into XML
if ((isset($response->headers['content-type']) && $response->headers['content-type'] == 'application/xml') || (str_starts_with($response->body, '<?xml') && ($response->headers['content-type'] ?? '') !== 'image/svg+xml')) {
if (array_key_exists('content-type', $response->headers)
&& ($response->headers['content-type'] == 'application/xml'
|| (str_starts_with($response->body, '<?xml') && $response->headers['content-type'] == 'image/svg+xml'))) {
$response->body = \simplexml_load_string($response->body);
$response->body = json_decode(json_encode($response->body), true);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Storage/Compression/Algorithms/GZIPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function tearDown(): void
{
}

public function testName()
public function testName(): void
{
$this->assertEquals($this->object->getName(), 'gzip');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Storage/Compression/Algorithms/ZstdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function tearDown(): void
{
}

public function testName()
public function testName(): void
{
$this->assertEquals($this->object->getName(), 'zstd');
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Storage/Device/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public function testDescription()
$this->assertEquals($this->object->getDescription(), 'Adapter for Local storage that is in the physical or virtual machine or mounted to it.');
}

public function testRoot()
public function testRoot(): void
{
$this->assertEquals($this->object->getRoot(), $this->object->getAbsolutePath(__DIR__.'/../../resources/disk-a'));
}

public function testPath()
public function testPath(): void
{
$this->assertEquals($this->object->getPath('image.png'), $this->object->getAbsolutePath(__DIR__.'/../../resources/disk-a').'/image.png');
}

public function testWrite()
public function testWrite(): void
{
$this->assertEquals($this->object->write($this->object->getPath('text.txt'), 'Hello World'), true);
$this->assertEquals(file_exists($this->object->getPath('text.txt')), true);
Expand All @@ -66,15 +66,15 @@ public function testWrite()
$this->object->delete($this->object->getPath('text.txt'));
}

public function testRead()
public function testRead(): void
{
$this->assertEquals($this->object->write($this->object->getPath('text-for-read.txt'), 'Hello World'), true);
$this->assertEquals($this->object->read($this->object->getPath('text-for-read.txt')), 'Hello World');

$this->object->delete($this->object->getPath('text-for-read.txt'));
}

public function testFileExists()
public function testFileExists(): void
{
$this->assertEquals($this->object->write($this->object->getPath('text-for-test-exists.txt'), 'Hello World'), true);
$this->assertEquals($this->object->exists($this->object->getPath('text-for-test-exists.txt')), true);
Expand All @@ -83,7 +83,7 @@ public function testFileExists()
$this->object->delete($this->object->getPath('text-for-test-exists.txt'));
}

public function testMove()
public function testMove(): void
{
$this->assertEquals($this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World'), true);
$this->assertEquals($this->object->read($this->object->getPath('text-for-move.txt')), 'Hello World');
Expand All @@ -97,7 +97,7 @@ public function testMove()
$this->object->delete($this->object->getPath('text-for-move-new.txt'));
}

public function testDelete()
public function testDelete(): void
{
$this->assertEquals($this->object->write($this->object->getPath('text-for-delete.txt'), 'Hello World'), true);
$this->assertEquals($this->object->read($this->object->getPath('text-for-delete.txt')), 'Hello World');
Expand Down Expand Up @@ -148,7 +148,7 @@ public function testPartUpload()
$totalSize = $this->object->getFileSize($source);
$chunkSize = 2097152;

$chunks = ceil($totalSize / $chunkSize);
$chunks = intval(ceil($totalSize / $chunkSize));

$chunk = 1;
$start = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ public function testAbort()
$dest = $this->object->getPath('abcduploaded.mp4');
$totalSize = $this->object->getFileSize($source);
$chunkSize = 2097152;
$chunks = ceil($totalSize / $chunkSize);
$chunks = intval(ceil($totalSize / $chunkSize));

$chunk = 1;
$start = 0;
Expand All @@ -202,7 +202,7 @@ public function testAbort()
$dest1 = $this->object->getPath('abcduploaded2.mp4');
$totalSize = $this->object->getFileSize($source);
$chunkSize = 2097152;
$chunks = ceil($totalSize / $chunkSize);
$chunks = intval(ceil($totalSize / $chunkSize));

$chunk = 1;
$start = 0;
Expand Down
Loading