Apply and enforce the Nextcloud coding standard for php
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Родитель
57c353ce21
Коммит
b565c1076a
|
@ -32,6 +32,23 @@ jobs:
|
|||
- name: Lint
|
||||
run: composer run lint
|
||||
|
||||
php-cs-fixer:
|
||||
name: php-cs check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Set up php
|
||||
uses: shivammathur/setup-php@master
|
||||
with:
|
||||
php-version: 7.4
|
||||
tools: composer:v1
|
||||
coverage: none
|
||||
- name: Install dependencies
|
||||
run: composer i
|
||||
- name: Run coding standards check
|
||||
run: composer run cs:check
|
||||
|
||||
app-code-check:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
/nbproject/private/
|
||||
/vendor
|
||||
composer.phar
|
||||
.php_cs.cache
|
||||
|
||||
/tests/clover*.xml
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once './vendor/autoload.php';
|
||||
|
||||
use Nextcloud\CodingStandard\Config;
|
||||
|
||||
$config = new Config();
|
||||
$config
|
||||
->getFinder()
|
||||
->ignoreVCSIgnored(true)
|
||||
->notPath('build')
|
||||
->notPath('l10n')
|
||||
->notPath('lib/Vendor')
|
||||
->notPath('src')
|
||||
->notPath('vendor')
|
||||
->in(__DIR__);
|
||||
return $config;
|
|
@ -10,15 +10,18 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"php": ">=7.2.0",
|
||||
"yubico/u2flib-server": "^1.0.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"christophwurst/nextcloud": "^18.0.0",
|
||||
"phpunit/phpunit": "^7.5.8",
|
||||
"roave/security-advisories": "dev-master"
|
||||
"roave/security-advisories": "dev-master",
|
||||
"nextcloud/coding-standard": "^0.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"cs:check": "php-cs-fixer fix --dry-run --diff",
|
||||
"cs:fix": "php-cs-fixer fix",
|
||||
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
|
||||
"test": "phpunit -c tests/phpunit.xml",
|
||||
"test:acceptance": "phpunit -c tests/phpunit.xml tests/Acceptance",
|
||||
|
@ -30,7 +33,7 @@
|
|||
"optimize-autoloader": true,
|
||||
"classmap-authoritative": true,
|
||||
"platform": {
|
||||
"php": "7.1.0"
|
||||
"php": "7.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -81,5 +81,4 @@ class Provider implements IProvider {
|
|||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -87,5 +87,4 @@ class Setting implements ISetting {
|
|||
public function isDefaultEnabledStream() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,16 +16,13 @@ namespace OCA\TwoFactorU2F\AppInfo;
|
|||
|
||||
use OCA\TwoFactorU2F\Event\DisabledByAdmin;
|
||||
use OCA\TwoFactorU2F\Event\StateChanged;
|
||||
use OCA\TwoFactorU2F\Listener\IListener;
|
||||
use OCA\TwoFactorU2F\Listener\StateChangeActivity;
|
||||
use OCA\TwoFactorU2F\Listener\StateChangeRegistryUpdater;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class Application extends App {
|
||||
|
||||
const APP_ID = 'twofactor_u2f';
|
||||
public const APP_ID = 'twofactor_u2f';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
|
@ -38,5 +35,4 @@ class Application extends App {
|
|||
$eventDispatcher->addServiceListener(StateChanged::class, StateChangeRegistryUpdater::class);
|
||||
$eventDispatcher->addServiceListener(DisabledByAdmin::class, StateChangeActivity::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ namespace OCA\TwoFactorU2F\Controller;
|
|||
require_once(__DIR__ . '/../../vendor/yubico/u2flib-server/src/u2flib_server/U2F.php');
|
||||
|
||||
use OCA\TwoFactorU2F\Service\U2FManager;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
|
||||
use OCP\IRequest;
|
||||
|
@ -76,5 +75,4 @@ class SettingsController extends ALoginSetupController {
|
|||
public function remove(int $id): JSONResponse {
|
||||
return new JSONResponse($this->manager->removeDevice($this->userSession->getUser(), $id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setName(string $name)
|
||||
*/
|
||||
class Registration extends Entity implements JsonSerializable {
|
||||
|
||||
protected $userId;
|
||||
protected $keyHandle;
|
||||
protected $publicKey;
|
||||
|
@ -51,5 +50,4 @@ class Registration extends Entity implements JsonSerializable {
|
|||
'name' => $this->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ use OCP\IDBConnection;
|
|||
use OCP\IUser;
|
||||
|
||||
class RegistrationMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'twofactor_u2f_registrations');
|
||||
}
|
||||
|
@ -53,5 +52,4 @@ class RegistrationMapper extends QBMapper {
|
|||
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID())));
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,9 +28,7 @@ namespace OCA\TwoFactorU2F\Event;
|
|||
use OCP\IUser;
|
||||
|
||||
class DisabledByAdmin extends StateChanged {
|
||||
|
||||
public function __construct(IUser $user) {
|
||||
parent::__construct($user, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,5 +45,4 @@ class StateChanged extends Event {
|
|||
public function isEnabled(): bool {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class StateChangeRegistryUpdater implements IEventListener {
|
|||
if ($event->isEnabled() && count($devices) === 1) {
|
||||
// The first device was enabled -> enable provider for this user
|
||||
$this->providerRegistry->enableProviderFor($this->provider, $event->getUser());
|
||||
} else if (!$event->isEnabled() && empty($devices)) {
|
||||
} elseif (!$event->isEnabled() && empty($devices)) {
|
||||
// The last device was removed -> disable provider for this user
|
||||
$this->providerRegistry->disableProviderFor($this->provider, $event->getUser());
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
|
@ -35,5 +37,4 @@ class U2FLoginProvider implements ILoginSetupProvider {
|
|||
public function getBody(): Template {
|
||||
return new Template(Application::APP_ID, 'loginsetup');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,7 +108,8 @@ class U2FProvider implements IActivatableAtLogin, IProvidesIcons, IProvidesPerso
|
|||
}
|
||||
|
||||
public function getDarkIcon(): String {
|
||||
return image_path('twofactor_u2f', 'app-dark.svg');;
|
||||
return image_path('twofactor_u2f', 'app-dark.svg');
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,5 +129,4 @@ class U2FProvider implements IActivatableAtLogin, IProvidesIcons, IProvidesPerso
|
|||
public function getLoginSetup(IUser $user): ILoginSetupProvider {
|
||||
return $this->container->query(U2FLoginProvider::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ use OCP\ILogger;
|
|||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
use OCP\IUser;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use u2flib_server\Error;
|
||||
use u2flib_server\U2F;
|
||||
|
||||
|
@ -163,7 +162,7 @@ class U2FManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
$regs = array_filter($registrations, function($registration) use ($reg) {
|
||||
$regs = array_filter($registrations, function ($registration) use ($reg) {
|
||||
return $registration->keyHandle === $reg->keyHandle;
|
||||
});
|
||||
$origReg = reset($regs);
|
||||
|
@ -172,5 +171,4 @@ class U2FManager {
|
|||
$this->mapper->update($registration);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\TwoFactorU2F\Settings;
|
||||
|
||||
use function json_encode;
|
||||
use OCP\Authentication\TwoFactorAuth\IPersonalProviderSettings;
|
||||
use OCP\Template;
|
||||
|
||||
class Personal implements IPersonalProviderSettings {
|
||||
|
||||
public function getBody(): Template {
|
||||
return new Template('twofactor_u2f', 'personal');
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ use OCP\L10N\IFactory;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProviderTest extends TestCase {
|
||||
|
||||
private $l10n;
|
||||
private $urlGenerator;
|
||||
private $logger;
|
||||
|
@ -103,5 +102,4 @@ class ProviderTest extends TestCase {
|
|||
|
||||
$this->provider->parse($lang, $event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ use OCP\IL10N;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SettingTest extends TestCase {
|
||||
|
||||
private $l10n;
|
||||
|
||||
/** @var Setting */
|
||||
|
@ -54,5 +53,4 @@ class SettingTest extends TestCase {
|
|||
$this->assertEquals(true, $this->setting->isDefaultEnabledMail());
|
||||
$this->assertEquals(true, $this->setting->isDefaultEnabledStream());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -102,5 +102,4 @@ class SettingsControllerTest extends TestCase {
|
|||
|
||||
$this->assertEquals(new JSONResponse([]), $resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ use OCP\IUser;
|
|||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StateChangedTest extends TestCase {
|
||||
|
||||
public function testEnabledState() {
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
|
@ -37,5 +36,4 @@ class StateChangedTest extends TestCase {
|
|||
$this->assertFalse($event->isEnabled());
|
||||
$this->assertSame($user, $event->getUser());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -186,5 +186,4 @@ class U2FProviderTest extends TestCase {
|
|||
|
||||
$this->assertSame($loginProvider, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -136,5 +136,4 @@ class U2FManagerTest extends TestCase {
|
|||
|
||||
$this->manager->startRegistration($user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче