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

Feature/1088-code-style-setup #97

Merged
merged 15 commits into from
Jan 6, 2025
Merged
Prev Previous commit
Next Next commit
feat(cs): enable PSR12 and PhpCsFixer rules
- add: extend NC rules
- chore: lint new rules
- fix: OC PSR4 detection
- add: global imports
- add: trailing comma in arrays and etc
mahiarirani committed Dec 28, 2024
commit 22f891365ebc87fff8f793a7dc81471e9bc69277
20 changes: 19 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -4,10 +4,28 @@

require_once './vendor/autoload.php';

use Nextcloud\CodingStandard\Config;
use Nextcloud\CodingStandard\Config as Base;
use PhpCsFixer\Runner\Parallel\ParallelConfig;

class Config extends Base {
public function getRules(array $rules = []): array
{
return [
...parent::getRules(), // Nextcloud Standard Rules
'@PSR12' => true,
'@PhpCsFixer' => true,
'global_namespace_import' => [
'import_classes' => true,
],
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'match', 'parameters']],
];
}
}

$config = new Config();
$config
->setParallelConfig(new ParallelConfig(8))
->setRiskyAllowed(true)
->getFinder()
->ignoreVCSIgnored(true)
->notPath('dev-environment')
3 changes: 0 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@

/**
* @copyright Copyright (c) 2022, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -21,7 +19,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
return ['routes' => [
[
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"autoload-dev": {
"psr-4": {
"OC\\": "dev-environment/nextcloud_source/lib/",
"OCP\\": "dev-environment/nextcloud_source/lib/public/",
"OCA\\Files_External\\": "dev-environment/nextcloud_source/apps/files_external/lib/",
"OCA\\Files_External_Ethswarm\\": "lib/"
5 changes: 2 additions & 3 deletions lib/AppInfo/AppConstants.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -20,8 +19,8 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_External_Ethswarm\AppInfo;

class AppConstants {
18 changes: 4 additions & 14 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,7 @@

/**
* @copyright Copyright (c) 2022, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -19,7 +17,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

declare(strict_types=1);
@@ -40,22 +37,16 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;

/**
* @package OCA\Files_external_beeswarm\AppInfo
*/
class Application extends App implements IBootstrap, IBackendProvider, IAuthMechanismProvider {

public function __construct(array $urlParams = []) {
parent::__construct(AppConstants::APP_NAME, $urlParams);
}

/**
* @{inheritdoc}
*/
public function getBackends() {
$container = $this->getContainer();

return [
$container->query(BeeSwarm::class)
$container->query(BeeSwarm::class),
];
}

@@ -82,11 +73,9 @@ public function boot(IBootContext $context): void {
});

$this->getAuthMechanisms();

}

public function registerEventsScripts(IEventDispatcher $dispatcher) {
}
public function registerEventsScripts(IEventDispatcher $dispatcher) {}

public function register(IRegistrationContext $context): void {
// Register AddContentSecurityPolicyEvent for CSPListener class listenser here
@@ -95,6 +84,7 @@ public function register(IRegistrationContext $context): void {

public function getAuthMechanisms() {
$container = $this->getContainer();

return [
// AuthMechanism::BASIC HTTP mechanisms
$container->get(License::class),
11 changes: 3 additions & 8 deletions lib/Auth/License.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,7 @@

/**
* @copyright Copyright (c) 2022, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -19,7 +17,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_External_Ethswarm\Auth;
@@ -29,15 +26,12 @@
use OCP\IL10N;

/**
* Basic Http Authentication
* Basic Http Authentication.
*/
class License extends AuthMechanism {
/** @const string */
public const SCHEME_ACCESS_KEY = 'access_key';

/**
* @param IL10N $l
*/
public function __construct(IL10N $l) {
$this
->setIdentifier('access:key')
@@ -47,6 +41,7 @@ public function __construct(IL10N $l) {
(new DefinitionParameter(self::SCHEME_ACCESS_KEY, $l->t('Access Key')))
->setTooltip($l->t('License Access Key'))
->setType(DefinitionParameter::VALUE_PASSWORD),
]);
])
;
}
}
30 changes: 6 additions & 24 deletions lib/Backend/BeeSwarm.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,7 @@

/**
* @copyright Copyright (c) 2022, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -19,7 +17,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_External_Ethswarm\Backend;
@@ -35,31 +32,18 @@
use Psr\Log\LoggerInterface;

class BeeSwarm extends Backend {
/** @var IL10N */
private IL10N $l;
/** @const string */
public const OPTION_HOST_URL = 'host_url';

/** @var string */
protected string $appName;
private IL10N $l;

/** @var IConfig */
private IConfig $config;

/** @var LoggerInterface */
private LoggerInterface $logger;

/** @var GlobalStoragesService */
private GlobalStoragesService $globalStoragesService;

/** @const string */
public const OPTION_HOST_URL = 'host_url';

/**
* @param string $appName
* @param IL10N $l
* @param IConfig $config
* @param LoggerInterface $logger
* @param GlobalStoragesService $globalStoragesService
*/
public function __construct(string $appName, IL10N $l, IConfig $config, LoggerInterface $logger, GlobalStoragesService $globalStoragesService) {
$this->l = $l;
$this->appName = $appName;
@@ -74,12 +58,10 @@ public function __construct(string $appName, IL10N $l, IConfig $config, LoggerIn
->addParameters([
(new DefinitionParameter(self::OPTION_HOST_URL, $l->t('Server URL')))
->setTooltip($l->t('License Server URL')),
])->addAuthScheme(License::SCHEME_ACCESS_KEY);
])->addAuthScheme(License::SCHEME_ACCESS_KEY)
;
}

/**
* {@inheritdoc}
*/
public function validateStorageDefinition(StorageConfig $storage): bool {
$result = true;

@@ -92,7 +74,7 @@ public function validateStorageDefinition(StorageConfig $storage): bool {
// server url
$host = $storage->getBackendOption(self::OPTION_HOST_URL);
if (!preg_match('/^https?:\/\//i', $host)) {
$host = 'https://' . $host;
$host = 'https://'.$host;
}
if (!filter_var($host, FILTER_VALIDATE_URL)) {
$this->logger->warning('invalid url');
24 changes: 12 additions & 12 deletions lib/Controller/BeeController.php
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@

/**
* @copyright Copyright (c) 2023, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -21,7 +19,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_External_Ethswarm\Controller;
@@ -34,20 +31,15 @@
use OCP\IRequest;

class BeeController extends Controller {
/** @var string */
protected $appName;

/** @var Admin */
private $admin;

/** @var string */
protected $appName;

/** @var IConfig */
private $config;

/**
* @param IConfig $config
* @param IRequest $request
*/
public function __construct(
string $appName,
IConfig $config,
@@ -61,8 +53,10 @@ public function __construct(

/**
* @NoCSRFRequired
*
* @NoAdminRequired
* Create a new postage batch stamp
*
* @return \DataResponse
*/
public function createPostageBatch(): DataResponse {
@@ -73,17 +67,21 @@ public function createPostageBatch(): DataResponse {

if (isset($response_data['batchID'])) {
return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK);
} elseif (isset($response_data['message'])) {
}
if (isset($response_data['message'])) {
return new DataResponse(['msg' => $response_data['message']], $response_data['code']);
}
}

return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT);
}

/**
* @NoCSRFRequired
*
* @NoAdminRequired
* Top up an existing batch stamp based on the batchID
*
* @return \DataResponse
*/
public function topUpBatch(): DataResponse {
@@ -93,10 +91,12 @@ public function topUpBatch(): DataResponse {
$response_data = $this->admin->topUpPostageStamp($postageBatch['activeBatchId'], $postageBatch['topUpValue'], $postageBatch['mount_urloptions']);
if (isset($response_data['batchID'])) {
return new DataResponse(['batchID' => $response_data['batchID']], Http::STATUS_OK);
} elseif (isset($response_data['message'])) {
}
if (isset($response_data['message'])) {
return new DataResponse(['msg' => $response_data['message']], $response_data['code']);
}
}

return new DataResponse(['msg' => 'Error in request'], Http::STATUS_CONFLICT);
}
}
Loading
Loading