Merge pull request #222 from nextcloud/techdebt/noid/object-reference

Objects are always passed by reference
This commit is contained in:
Joas Schilling 2020-07-10 16:45:52 +02:00 committed by GitHub
commit 8dae582438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 20 deletions

View File

@ -84,7 +84,7 @@ class RegistrationMapper extends Mapper {
/** /**
* @param Registration $registration * @param Registration $registration
*/ */
public function generateNewToken(Registration &$registration) { public function generateNewToken(Registration $registration) {
$token = $this->random->generate(10, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); $token = $this->random->generate(10, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
$registration->setToken($token); $registration->setToken($token);
} }
@ -92,8 +92,8 @@ class RegistrationMapper extends Mapper {
/** /**
* @param Registration $registration * @param Registration $registration
*/ */
public function generateClientSecret(Registration &$registration) { public function generateClientSecret(Registration $registration) {
$token = $this->random->generate(32, "abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789"); $token = $this->random->generate(32, 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789');
//FIXME eqivalent to ISecureRandom::CHAR_HUMAN_READABLE introduced in https://github.com/nextcloud/server/commit/f2a2b34e4639e88f8d948a388a51f010212b42a3 but not supported in ownCloud yet. We'll just use the string for now then switch to constants when supported. //FIXME eqivalent to ISecureRandom::CHAR_HUMAN_READABLE introduced in https://github.com/nextcloud/server/commit/f2a2b34e4639e88f8d948a388a51f010212b42a3 but not supported in ownCloud yet. We'll just use the string for now then switch to constants when supported.
$registration->setClientSecret($token); $registration->setClientSecret($token);
} }

View File

@ -36,7 +36,6 @@ use OCA\Registration\Db\RegistrationMapper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use \OCP\AppFramework\Http\TemplateResponse; use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\RedirectResponse; use \OCP\AppFramework\Http\RedirectResponse;
use \OCP\Defaults;
use OCP\ILogger; use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
@ -68,8 +67,6 @@ class RegistrationService {
private $config; private $config;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var \OCP\Defaults */
private $defaults;
/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;
/** @var IUserSession */ /** @var IUserSession */
@ -86,7 +83,7 @@ class RegistrationService {
private $crypto; private $crypto;
public function __construct($appName, MailService $mailService, IL10N $l10n, IURLGenerator $urlGenerator, public function __construct($appName, MailService $mailService, IL10N $l10n, IURLGenerator $urlGenerator,
RegistrationMapper $registrationMapper, IUserManager $userManager, IConfig $config, IGroupManager $groupManager, Defaults $defaults, RegistrationMapper $registrationMapper, IUserManager $userManager, IConfig $config, IGroupManager $groupManager,
ISecureRandom $random, IUserSession $us, IRequest $request, ILogger $logger, ISession $session, IProvider $tokenProvider, ICrypto $crypto) { ISecureRandom $random, IUserSession $us, IRequest $request, ILogger $logger, ISession $session, IProvider $tokenProvider, ICrypto $crypto) {
$this->appName = $appName; $this->appName = $appName;
$this->mailService = $mailService; $this->mailService = $mailService;
@ -96,7 +93,6 @@ class RegistrationService {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->config = $config; $this->config = $config;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->defaults = $defaults;
$this->random = $random; $this->random = $random;
$this->usersession = $us; $this->usersession = $us;
$this->request = $request; $this->request = $request;
@ -109,7 +105,7 @@ class RegistrationService {
/** /**
* @param Registration $registration * @param Registration $registration
*/ */
public function confirmEmail(Registration &$registration) { public function confirmEmail(Registration $registration) {
$registration->setEmailConfirmed(true); $registration->setEmailConfirmed(true);
$this->registrationMapper->update($registration); $this->registrationMapper->update($registration);
} }
@ -117,7 +113,7 @@ class RegistrationService {
/** /**
* @param Registration $registration * @param Registration $registration
*/ */
public function generateNewToken(Registration &$registration) { public function generateNewToken(Registration $registration) {
$this->registrationMapper->generateNewToken($registration); $this->registrationMapper->generateNewToken($registration);
$this->registrationMapper->update($registration); $this->registrationMapper->update($registration);
} }
@ -255,9 +251,9 @@ class RegistrationService {
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return \OCP\IUser * @return \OCP\IUser
* @throws RegistrationException|\InvalidTokenException * @throws RegistrationException|InvalidTokenException
*/ */
public function createAccount(Registration &$registration, $username = null, $password = null) { public function createAccount(Registration $registration, $username = null, $password = null) {
if ($password === null && $registration->getPassword() === null) { if ($password === null && $registration->getPassword() === null) {
$generatedPassword = $this->generateRandomDeviceToken(); $generatedPassword = $this->generateRandomDeviceToken();
$registration->setPassword($this->crypto->encrypt($generatedPassword)); $registration->setPassword($this->crypto->encrypt($generatedPassword));

View File

@ -6,7 +6,6 @@ use OCA\Registration\Controller\RegisterController;
use OCA\Registration\Db\RegistrationMapper; use OCA\Registration\Db\RegistrationMapper;
use OCA\Registration\Service\MailService; use OCA\Registration\Service\MailService;
use OCA\Registration\Service\RegistrationService; use OCA\Registration\Service\RegistrationService;
use OCP\Defaults;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
@ -73,7 +72,6 @@ class RegisterControllerTest extends TestCase {
$this->userManager = \OC::$server->getUserManager(); $this->userManager = \OC::$server->getUserManager();
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->groupManager = \OC::$server->getGroupManager(); $this->groupManager = \OC::$server->getGroupManager();
$this->defaults = $this->createMock(Defaults::class);
$this->random = \OC::$server->getSecureRandom(); $this->random = \OC::$server->getSecureRandom();
$this->usersession = $this->createMock(IUserSession::class); $this->usersession = $this->createMock(IUserSession::class);
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
@ -96,7 +94,6 @@ class RegisterControllerTest extends TestCase {
$this->userManager, $this->userManager,
$this->config, $this->config,
$this->groupManager, $this->groupManager,
$this->defaults,
$this->random, $this->random,
$this->usersession, $this->usersession,
$this->request, $this->request,

View File

@ -7,7 +7,6 @@ use OCA\Registration\Db\RegistrationMapper;
use OCA\Registration\Service\MailService; use OCA\Registration\Service\MailService;
use OCA\Registration\Service\RegistrationException; use OCA\Registration\Service\RegistrationException;
use OCA\Registration\Service\RegistrationService; use OCA\Registration\Service\RegistrationService;
use OCP\Defaults;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
@ -47,8 +46,6 @@ class RegistrationServiceTest extends TestCase {
private $config; private $config;
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
/** @var \OCP\Defaults */
private $defaults;
/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;
/** @var IUserSession */ /** @var IUserSession */
@ -73,7 +70,6 @@ class RegistrationServiceTest extends TestCase {
$this->userManager = \OC::$server->getUserManager(); $this->userManager = \OC::$server->getUserManager();
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->groupManager = \OC::$server->getGroupManager(); $this->groupManager = \OC::$server->getGroupManager();
$this->defaults = $this->createMock(Defaults::class);
$this->random = \OC::$server->getSecureRandom(); $this->random = \OC::$server->getSecureRandom();
$this->usersession = $this->createMock(IUserSession::class); $this->usersession = $this->createMock(IUserSession::class);
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
@ -96,7 +92,6 @@ class RegistrationServiceTest extends TestCase {
$this->userManager, $this->userManager,
$this->config, $this->config,
$this->groupManager, $this->groupManager,
$this->defaults,
$this->random, $this->random,
$this->usersession, $this->usersession,
$this->request, $this->request,