Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code quality analysis with PHPStan #62

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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"
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"email": "eldad@appwrite.io"
}
],
"scripts": {
"check": "./vendor/bin/phpstan analyse --level 5 src tests"
},
"autoload": {
"psr-4": {"Utopia\\Storage\\":"src/Storage"}
},
Expand All @@ -25,7 +28,8 @@
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "4.0.1"
"vimeo/psalm": "4.0.1",
"phpstan/phpstan": "1.9.x-dev"
},
"minimum-stability": "dev"
}
71 changes: 68 additions & 3 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 @@ -161,8 +161,8 @@ public function abort(string $path, string $extra = ''): bool
* Read file by given path.
*
* @param string $path
* @param int offset
* @param int length
* @param int $offset
* @param int $length
*
* @return string
*/
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 @@ -161,8 +161,8 @@ 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
*
* @throws \Exception
Expand All @@ -172,7 +172,7 @@ public function getPath(string $filename, string $prefix = null): string
public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int
{
if($chunk == 1 && $chunks == 1) {
return $this->write($path, \file_get_contents($source), \mime_content_type($source));
return intval($this->write($path, \file_get_contents($source), \mime_content_type($source)));
}
$uploadId = $metadata['uploadId'] ?? null;
if(empty($uploadId)) {
Expand Down Expand Up @@ -295,8 +295,8 @@ 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
*
* @throws \Exception
*
Expand Down Expand Up @@ -391,7 +391,9 @@ 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
*
* @throws \Exception
*
Expand Down Expand Up @@ -577,7 +579,7 @@ private function getInfo(string $path): array
* Generate the headers for AWS Signature V4
* @param string $method
* @param string $uri
* @param array parameters
* @param array $parameters
*
* @return string
*/
Expand Down Expand Up @@ -701,7 +703,7 @@ private function call(string $method, string $uri, string $data = '', array $par
$response->body .= $data;
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 @@ -742,7 +744,10 @@ 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
8 changes: 4 additions & 4 deletions tests/Storage/Compression/Algorithms/GZIPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function tearDown(): void
{
}

public function testName()
public function testName(): void
{
$this->assertEquals($this->object->getName(), 'gzip');
}

public function testCompressDecompressWithText()
public function testCompressDecompressWithText(): void
{
$demo = 'This is a demo string';
$demoSize = mb_strlen($demo, '8bit');
Expand All @@ -40,7 +40,7 @@ public function testCompressDecompressWithText()
$this->assertEquals($this->object->decompress($data), $demo);
}

public function testCompressDecompressWithJPGImage()
public function testCompressDecompressWithJPGImage(): void
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg');
$demoSize = mb_strlen($demo, '8bit');
Expand All @@ -59,7 +59,7 @@ public function testCompressDecompressWithJPGImage()
$this->assertEquals($dataSize, 599639);
}

public function testCompressDecompressWithPNGImage()
public function testCompressDecompressWithPNGImage(): void
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png');
$demoSize = mb_strlen($demo, '8bit');
Expand Down
8 changes: 4 additions & 4 deletions tests/Storage/Compression/Algorithms/ZstdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function tearDown(): void
{
}

public function testName()
public function testName(): void
{
$this->assertEquals($this->object->getName(), 'zstd');
}

public function testCompressDecompressWithText()
public function testCompressDecompressWithText(): void
{
$demo = 'This is a demo string';
$demoSize = \mb_strlen($demo, '8bit');
Expand All @@ -37,7 +37,7 @@ public function testCompressDecompressWithText()
$this->assertEquals($demo, $this->object->decompress($data));
}

public function testCompressDecompressWithJPGImage()
public function testCompressDecompressWithJPGImage(): void
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg');
$demoSize = \mb_strlen($demo, '8bit');
Expand All @@ -56,7 +56,7 @@ public function testCompressDecompressWithJPGImage()
$this->assertEquals(599639, $dataSize);
}

public function testCompressDecompressWithPNGImage()
public function testCompressDecompressWithPNGImage(): void
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png');
$demoSize = \mb_strlen($demo, '8bit');
Expand Down
Loading