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 psalm check action #28

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
56 changes: 56 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization

name: Psalm static analysis

on:
pull_request:
paths:
- .github/workflows/psalm.yml
- appinfo/**
- composer.*
- lib/**
- templates/**
- tests/**
push:
branches:
- main
- stable*
- test
paths:
- .github/workflows/psalm.yml
- appinfo/**
- composer.*
- lib/**
- templates/**
- tests/**

concurrency:
group: psalm-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
static-analysis:
runs-on: ubuntu-latest

name: Psalm check
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up php
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
with:
php-version: 8.2
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer i

- name: Run coding standards check
run: composer run psalm
12 changes: 6 additions & 6 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ include text processing providers to:
<version>1.0.3</version>
<licence>agpl</licence>
<author>Julien Veyssier</author>
<namespace>TPAssistant</namespace>
<namespace>TpAssistant</namespace>
<documentation>
<developer>https://github.com/nextcloud/assistant</developer>
</documentation>
Expand All @@ -48,17 +48,17 @@ include text processing providers to:
<screenshot>https://github.com/nextcloud/assistant/raw/main/img/screenshot2.jpg</screenshot>
<screenshot>https://github.com/nextcloud/assistant/raw/main/img/screenshot3.jpg</screenshot>
<background-jobs>
<job>OCA\TPAssistant\Cron\CleanupImageGenerations</job>
<job>OCA\TpAssistant\Cron\CleanupImageGenerations</job>
</background-jobs>
<commands>
<command>OCA\TPAssistant\Command\CleanupImageGenerations</command>
<command>OCA\TpAssistant\Command\CleanupImageGenerations</command>
</commands>
<dependencies>
<nextcloud min-version="28" max-version="29"/>
</dependencies>
<settings>
<admin>OCA\TPAssistant\Settings\Admin</admin>
<personal>OCA\TPAssistant\Settings\Personal</personal>
<personal-section>OCA\TPAssistant\Settings\PersonalSection</personal-section>
<admin>OCA\TpAssistant\Settings\Admin</admin>
<personal>OCA\TpAssistant\Settings\Personal</personal>
<personal-section>OCA\TpAssistant\Settings\PersonalSection</personal-section>
</settings>
</info>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar",
"psalm": "psalm.phar --no-cache",
"test:unit": "phpunit --config tests/phpunit.xml"
},
"require-dev": {
Expand Down
22 changes: 11 additions & 11 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace OCA\TPAssistant\AppInfo;

use OCA\TPAssistant\Listener\BeforeTemplateRenderedListener;
use OCA\TPAssistant\Listener\FreePrompt\FreePromptReferenceListener;
use OCA\TPAssistant\Listener\TaskFailedListener;
use OCA\TPAssistant\Listener\TaskSuccessfulListener;
use OCA\TPAssistant\Listener\Text2Image\Text2ImageReferenceListener;
use OCA\TPAssistant\Listener\Text2Image\Text2ImageResultListener;
use OCA\TPAssistant\Notification\Notifier;
use OCA\TPAssistant\Reference\FreePromptReferenceProvider;
use OCA\TPAssistant\Reference\Text2ImageReferenceProvider;
namespace OCA\TpAssistant\AppInfo;

use OCA\TpAssistant\Listener\BeforeTemplateRenderedListener;
use OCA\TpAssistant\Listener\FreePrompt\FreePromptReferenceListener;
use OCA\TpAssistant\Listener\TaskFailedListener;
use OCA\TpAssistant\Listener\TaskSuccessfulListener;
use OCA\TpAssistant\Listener\Text2Image\Text2ImageReferenceListener;
use OCA\TpAssistant\Listener\Text2Image\Text2ImageResultListener;
use OCA\TpAssistant\Notification\Notifier;
use OCA\TpAssistant\Reference\FreePromptReferenceProvider;
use OCA\TpAssistant\Reference\Text2ImageReferenceProvider;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;

Expand Down
10 changes: 5 additions & 5 deletions lib/Command/CleanupImageGenerations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Command;
namespace OCA\TpAssistant\Command;

use Exception;
use OCA\TPAssistant\AppInfo\Application;
use OCA\TPAssistant\Service\Text2Image\CleanUpService;
use OC\Core\Command\Base;
use OCA\TpAssistant\AppInfo\Application;
use OCA\TpAssistant\Service\Text2Image\CleanUpService;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanupImageGenerations extends Command {
class CleanupImageGenerations extends Base {
public function __construct(
private CleanUpService $cleanUpService,
private IConfig $config
Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/AssistantController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace OCA\TPAssistant\Controller;
namespace OCA\TpAssistant\Controller;

use OCA\TPAssistant\AppInfo\Application;
use OCA\TPAssistant\Service\AssistantService;
use OCA\TpAssistant\AppInfo\Application;
use OCA\TpAssistant\Service\AssistantService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace OCA\TPAssistant\Controller;
namespace OCA\TpAssistant\Controller;

use OCA\TPAssistant\AppInfo\Application;
use OCA\TpAssistant\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/FreePromptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Controller;
namespace OCA\TpAssistant\Controller;

use Exception;
use OCA\TPAssistant\Service\FreePrompt\FreePromptService;
use OCA\TpAssistant\Service\FreePrompt\FreePromptService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand Down
18 changes: 9 additions & 9 deletions lib/Controller/Text2ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Controller;
namespace OCA\TpAssistant\Controller;

use Exception;
use OCA\TPAssistant\AppInfo\Application;
use OCA\TPAssistant\Service\Text2Image\Text2ImageHelperService;
use OCA\TpAssistant\AppInfo\Application;
use OCA\TpAssistant\Service\Text2Image\Text2ImageHelperService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
Expand Down Expand Up @@ -83,8 +83,8 @@ public function getImage(string $imageGenId, int $fileNameId): DataDisplayRespon
try {
$result = $this->text2ImageHelperService->getImage($imageGenId, $fileNameId);
} catch (Exception $e) {
$response = new DataResponse(['error' => $e->getMessage()], $e->getCode());
if ($e->getCode() === Http::STATUS_BAD_REQUEST | Http::STATUS_UNAUTHORIZED) {
$response = new DataResponse(['error' => $e->getMessage()], (int) $e->getCode());
if ($e->getCode() === Http::STATUS_BAD_REQUEST || $e->getCode() === Http::STATUS_UNAUTHORIZED) {
// Throttle brute force attempts
$response->throttle(['action' => 'imageGenId']);
}
Expand Down Expand Up @@ -114,8 +114,8 @@ public function getGenerationInfo(string $imageGenId): DataResponse {
try {
$result = $this->text2ImageHelperService->getGenerationInfo($imageGenId, true);
} catch (Exception $e) {
$response = new DataResponse(['error' => $e->getMessage()], $e->getCode());
if ($e->getCode() === Http::STATUS_BAD_REQUEST | Http::STATUS_UNAUTHORIZED) {
$response = new DataResponse(['error' => $e->getMessage()], (int) $e->getCode());
if ($e->getCode() === Http::STATUS_BAD_REQUEST || $e->getCode() === Http::STATUS_UNAUTHORIZED) {
// Throttle brute force attempts
$response->throttle(['action' => 'imageGenId']);
}
Expand All @@ -140,8 +140,8 @@ public function setVisibilityOfImageFiles(string $imageGenId, array $fileVisStat
try {
$this->text2ImageHelperService->setVisibilityOfImageFiles($imageGenId, $fileVisStatusArray);
} catch (Exception $e) {
$response = new DataResponse(['error' => $e->getMessage()], $e->getCode());
if($e->getCode() === Http::STATUS_BAD_REQUEST | Http::STATUS_UNAUTHORIZED) {
$response = new DataResponse(['error' => $e->getMessage()], (int) $e->getCode());
if($e->getCode() === Http::STATUS_BAD_REQUEST || $e->getCode() === Http::STATUS_UNAUTHORIZED) {
// Throttle brute force attempts
$response->throttle(['action' => 'imageGenId']);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Cron/CleanupImageGenerations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Cron;
namespace OCA\TpAssistant\Cron;

use Exception;
use OCA\TPAssistant\Db\Text2Image\ImageGenerationMapper;
use OCA\TPAssistant\Service\Text2Image\CleanUpService;
use OCA\TpAssistant\Db\Text2Image\ImageGenerationMapper;
use OCA\TpAssistant\Service\Text2Image\CleanUpService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use Psr\Log\LoggerInterface;
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/FreePrompt/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Db\FreePrompt;
namespace OCA\TpAssistant\Db\FreePrompt;

use OCP\AppFramework\Db\Entity;

Expand Down
8 changes: 4 additions & 4 deletions lib/Db/FreePrompt/PromptMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

declare(strict_types=1);

namespace OCA\TPAssistant\Db\FreePrompt;
namespace OCA\TpAssistant\Db\FreePrompt;

use DateTime;
use OCA\TPAssistant\AppInfo\Application;
use OCA\TpAssistant\AppInfo\Application;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
Expand All @@ -17,7 +17,7 @@
use OCP\IDBConnection;

/**
* @implements QBMapper<Prompt>
* @extends QBMapper<Prompt>
*/
class PromptMapper extends QBMapper {
public function __construct(IDBConnection $db) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public function createPrompt(string $userId, string $value, ?int $timestamp = nu
if ($timestamp === null) {
$timestamp = (new DateTime())->getTimestamp();
}

try {
$prompt = $this->getPromptOfUserByValue($userId, $value);
$prompt->setTimestamp($timestamp);
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Text2Image/ImageFileName.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Db\Text2Image;
namespace OCA\TpAssistant\Db\Text2Image;

use OCP\AppFramework\Db\Entity;

Expand Down
20 changes: 7 additions & 13 deletions lib/Db/Text2Image/ImageFileNameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Db\Text2Image;
namespace OCA\TpAssistant\Db\Text2Image;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @implements QBMapper<ImageFileName>
* @extends QBMapper<ImageFileName>
*/
class ImageFileNameMapper extends QBMapper {
public function __construct(IDBConnection $db) {
Expand Down Expand Up @@ -81,11 +82,9 @@ public function setFileNameHidden(int $fileNameId, bool $hidden = true): int {
/**
* @param int $generationId
* @param int $fileNameId
* @return ImageFileName|null
*
* @return ImageFileName|Entity|null
*/

public function getImageFileNameOfGenerationId(int $generationId, int $fileNameId): ImageFileName | null {
public function getImageFileNameOfGenerationId(int $generationId, int $fileNameId): ImageFileName|Entity|null {
$qb = $this->db->getQueryBuilder();

$qb->select('file_name')
Expand All @@ -106,21 +105,16 @@ public function getImageFileNameOfGenerationId(int $generationId, int $fileNameI
/**
* @param int $generationId
* @param string $fileName
* @param string $prompt
* @return ImageFileName
* @return ImageFileName|Entity
* @throws Exception
*/
public function createImageFileName(int $generationId, string $fileName): ImageFileName {
public function createImageFileName(int $generationId, string $fileName): ImageFileName|Entity {
$imageFile = new ImageFileName();
$imageFile->setGenerationId($generationId);
$imageFile->setFileName($fileName);
return $this->insert($imageFile);
}

/**
*
*/

/**
* @param int $generationId
* @return void
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Text2Image/ImageGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-FileCopyrightText: Sami Finnilä <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\TPAssistant\Db\Text2Image;
namespace OCA\TpAssistant\Db\Text2Image;

use OCP\AppFramework\Db\Entity;

Expand Down
Loading
Loading