Objects are always passed by reference

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-07-10 15:58:21 +02:00
parent 1759d2176e
commit 298f7c4704
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
4 changed files with 8 additions and 20 deletions

View File

@ -84,7 +84,7 @@ class RegistrationMapper extends Mapper {
/**
* @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);
$registration->setToken($token);
}
@ -92,8 +92,8 @@ class RegistrationMapper extends Mapper {
/**
* @param Registration $registration
*/
public function generateClientSecret(Registration &$registration) {
$token = $this->random->generate(32, "abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789");
public function generateClientSecret(Registration $registration) {
$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.
$registration->setClientSecret($token);
}

View File

@ -36,7 +36,6 @@ use OCA\Registration\Db\RegistrationMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\RedirectResponse;
use \OCP\Defaults;
use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
@ -68,8 +67,6 @@ class RegistrationService {
private $config;
/** @var IGroupManager */
private $groupManager;
/** @var \OCP\Defaults */
private $defaults;
/** @var ISecureRandom */
private $random;
/** @var IUserSession */
@ -86,7 +83,7 @@ class RegistrationService {
private $crypto;
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) {
$this->appName = $appName;
$this->mailService = $mailService;
@ -96,7 +93,6 @@ class RegistrationService {
$this->userManager = $userManager;
$this->config = $config;
$this->groupManager = $groupManager;
$this->defaults = $defaults;
$this->random = $random;
$this->usersession = $us;
$this->request = $request;
@ -109,7 +105,7 @@ class RegistrationService {
/**
* @param Registration $registration
*/
public function confirmEmail(Registration &$registration) {
public function confirmEmail(Registration $registration) {
$registration->setEmailConfirmed(true);
$this->registrationMapper->update($registration);
}
@ -117,7 +113,7 @@ class RegistrationService {
/**
* @param Registration $registration
*/
public function generateNewToken(Registration &$registration) {
public function generateNewToken(Registration $registration) {
$this->registrationMapper->generateNewToken($registration);
$this->registrationMapper->update($registration);
}
@ -255,9 +251,9 @@ class RegistrationService {
* @param string $username
* @param string $password
* @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) {
$generatedPassword = $this->generateRandomDeviceToken();
$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\Service\MailService;
use OCA\Registration\Service\RegistrationService;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
@ -73,7 +72,6 @@ class RegisterControllerTest extends TestCase {
$this->userManager = \OC::$server->getUserManager();
$this->config = $this->createMock(IConfig::class);
$this->groupManager = \OC::$server->getGroupManager();
$this->defaults = $this->createMock(Defaults::class);
$this->random = \OC::$server->getSecureRandom();
$this->usersession = $this->createMock(IUserSession::class);
$this->request = $this->createMock(IRequest::class);
@ -96,7 +94,6 @@ class RegisterControllerTest extends TestCase {
$this->userManager,
$this->config,
$this->groupManager,
$this->defaults,
$this->random,
$this->usersession,
$this->request,

View File

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