chore: unify __construct functions

Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
This commit is contained in:
Christian Hartmann 2024-08-08 23:10:01 +02:00
Родитель 17ffeb3fb5
Коммит c22c515dbb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 01CF79F7199D2C63
25 изменённых файлов: 102 добавлений и 261 удалений

Просмотреть файл

@ -35,9 +35,8 @@ use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
class ActivityManager {
/** @var IUser */
private $currentUser;
private IUser $currentUser;
public function __construct(
protected string $appName,
private IManager $manager,

Просмотреть файл

@ -28,20 +28,11 @@ use OCP\IL10N;
use OCP\IURLGenerator;
class Filter implements IFilter {
protected $appName;
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(string $appName,
IL10N $l10n,
IURLGenerator $urlGenerator) {
$this->appName = $appName;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
public function __construct(
protected string $appName,
private IL10N $l10n,
private IURLGenerator $urlGenerator
) {
}
/**

Просмотреть файл

@ -27,15 +27,10 @@ use OCP\Activity\ActivitySettings;
use OCP\IL10N;
abstract class FormsActivitySettings extends ActivitySettings {
protected $appName;
/** @var IL10N */
protected $l10n;
public function __construct(string $appName,
IL10N $l10n) {
$this->appName = $appName;
$this->l10n = $l10n;
public function __construct(
protected string $appName,
protected IL10N $l10n
) {
}
/**

Просмотреть файл

@ -40,7 +40,8 @@ class CleanupUploadedFilesJob extends TimedJob {
private FormMapper $formMapper,
private UploadedFileMapper $uploadedFileMapper,
private LoggerInterface $logger,
ITimeFactory $time) {
ITimeFactory $time
) {
parent::__construct($time);
$this->setInterval(60 * 60);

Просмотреть файл

@ -31,19 +31,12 @@ use Psr\Log\LoggerInterface;
class UserDeletedJob extends QueuedJob {
/** @var FormMapper */
private $formMapper;
/** @var LoggerInterface */
private $logger;
public function __construct(FormMapper $formMapper,
public function __construct(
private FormMapper $formMapper,
ITimeFactory $time,
LoggerInterface $logger) {
private LoggerInterface $logger
) {
parent::__construct($time);
$this->formMapper = $formMapper;
$this->logger = $logger;
}
/**

Просмотреть файл

@ -27,11 +27,9 @@ use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;
class Capabilities implements ICapability {
/** @var IAppManager */
private $appManager;
public function __construct(IAppManager $appManager) {
$this->appManager = $appManager;
public function __construct(
private IAppManager $appManager
) {
}
/**

Просмотреть файл

@ -67,9 +67,8 @@ use OCP\IUserSession;
use Psr\Log\LoggerInterface;
class ApiController extends OCSController {
/** @var IUser */
private $currentUser;
private ?IUser $currentUser;
public function __construct(
string $appName,
IRequest $request,

Просмотреть файл

@ -36,27 +36,14 @@ use OCP\IRequest;
use Psr\Log\LoggerInterface;
class ConfigController extends ApiController {
protected $appName;
/** @var ConfigService */
private $configService;
/** @var IConfig */
private $config;
/** @var LoggerInterface */
private $logger;
public function __construct(string $appName,
ConfigService $configService,
IConfig $config,
LoggerInterface $logger,
IRequest $request) {
public function __construct(
protected $appName,
private ConfigService $configService,
private IConfig $config,
private LoggerInterface $logger,
IRequest $request
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->configService = $configService;
$this->config = $config;
$this->logger = $logger;
}
/**

Просмотреть файл

@ -55,7 +55,8 @@ use Psr\Log\LoggerInterface;
class PageController extends Controller {
private const TEMPLATE_MAIN = 'main';
public function __construct(string $appName,
public function __construct(
string $appName,
IRequest $request,
private FormMapper $formMapper,
private ShareMapper $shareMapper,

Просмотреть файл

@ -47,7 +47,6 @@ class AnswerMapper extends QBMapper {
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Answer[]
*/
public function findBySubmission(int $submissionId): array {
$qb = $this->db->getQueryBuilder();

Просмотреть файл

@ -29,8 +29,8 @@ namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getQuestionId()
* @method void setQuestionId(integer $value)
* @method int getQuestionId()
* @method void setQuestionId(int $value)
* @method string getText()
* @method void setText(string $value)
*/

Просмотреть файл

@ -34,9 +34,9 @@ namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getFormId()
* @method int getFormId()
* @method void setFormId(integer $value)
* @method integer getOrder()
* @method int getOrder()
* @method void setOrder(integer $value)
* @method string getType()
* @method void setType(string $value)

Просмотреть файл

@ -35,12 +35,11 @@ use OCP\IDBConnection;
* @extends QBMapper<Question>
*/
class QuestionMapper extends QBMapper {
private $optionMapper;
public function __construct(IDBConnection $db, OptionMapper $optionMapper) {
public function __construct(
IDBConnection $db,
private OptionMapper $optionMapper
) {
parent::__construct($db, 'forms_v2_questions', Question::class);
$this->optionMapper = $optionMapper;
}
/**

Просмотреть файл

@ -30,9 +30,9 @@ use OCA\Forms\Constants;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getFormId()
* @method int getFormId()
* @method void setFormId(integer $value)
* @method integer getShareType()
* @method int getShareType()
* @method void setShareType(integer $value)
* @method string getShareWith()
* @method void setShareWith(string $value)

Просмотреть файл

@ -31,11 +31,11 @@ namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getFormId()
* @method int getFormId()
* @method void setFormId(integer $value)
* @method string getUserId()
* @method void setUserId(string $value)
* @method integer getTimestamp()
* @method int getTimestamp()
* @method void setTimestamp(integer $value)
*/
class Submission extends Entity {

Просмотреть файл

@ -35,17 +35,16 @@ use OCP\IDBConnection;
* @extends QBMapper<Submission>
*/
class SubmissionMapper extends QBMapper {
private $answerMapper;
/**
* SubmissionMapper constructor.
* @param IDBConnection $db
* @param AnswerMapper $answerMapper
*/
public function __construct(IDBConnection $db, AnswerMapper $answerMapper) {
public function __construct(
IDBConnection $db,
private AnswerMapper $answerMapper
) {
parent::__construct($db, 'forms_v2_submissions', Submission::class);
$this->answerMapper = $answerMapper;
}
/**

Просмотреть файл

@ -29,14 +29,14 @@ namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getFormId()
* @method void setFormId(integer $value)
* @method int getFormId()
* @method void setFormId(int $value)
* @method string getOriginalFileName()
* @method void setOriginalFileName(string $value)
* @method integer getFileId()
* @method void setFileId(integer $value)
* @method integer getCreated()
* @method void setCreated(integer $value)
* @method int getFileId()
* @method void setFileId(int $value)
* @method int getCreated()
* @method void setCreated(int $value)
*/
class UploadedFile extends Entity {
protected $formId;

Просмотреть файл

@ -53,54 +53,20 @@ use Throwable;
class FormsMigrator implements IMigrator {
use TMigratorBasicVersionHandling;
/** @var AnswerMapper */
private $answerMapper;
/** @var FormMapper */
private $formMapper;
/** @var OptionMapper */
private $optionMapper;
/** @var QuestionMapper */
private $questionMapper;
/** @var SubmissionMapper */
private $submissionMapper;
/** @var FormsService */
private $formsService;
/** @var SubmissionService */
private $submissionService;
/** @var IL10N */
private $l10n;
/** @var IUserManager */
private $userManager;
private const PATH_ROOT = Application::APP_ID . '/';
private const PATH_MYAPP_FILE = FormsMigrator::PATH_ROOT . 'forms.json';
public function __construct(AnswerMapper $answerMapper,
FormMapper $formMapper,
OptionMapper $optionMapper,
QuestionMapper $questionMapper,
SubmissionMapper $submissionMapper,
FormsService $formsService,
SubmissionService $submissionService,
IL10N $l10n,
IUserManager $userManager) {
$this->answerMapper = $answerMapper;
$this->formMapper = $formMapper;
$this->optionMapper = $optionMapper;
$this->questionMapper = $questionMapper;
$this->submissionMapper = $submissionMapper;
$this->formsService = $formsService;
$this->submissionService = $submissionService;
$this->l10n = $l10n;
$this->userManager = $userManager;
public function __construct(
private AnswerMapper $answerMapper,
private FormMapper $formMapper,
private OptionMapper $optionMapper,
private QuestionMapper $questionMapper,
private SubmissionMapper $submissionMapper,
private FormsService $formsService,
private SubmissionService $submissionService,
private IL10N $l10n,
private IUserManager $userManager
) {
}
/**

Просмотреть файл

@ -35,17 +35,10 @@ use Psr\Log\LoggerInterface;
* @implements IEventListener<UserDeletedEvent>
*/
class UserDeletedListener implements IEventListener {
/** @var IJobList */
private $jobList;
/** @var LoggerInterface */
private $logger;
public function __construct(IJobList $jobList,
LoggerInterface $logger) {
$this->jobList = $jobList;
$this->logger = $logger;
public function __construct(
private IJobList $jobList,
private LoggerInterface $logger
) {
}
public function handle(Event $event): void {

Просмотреть файл

@ -36,30 +36,15 @@ use OCP\IUserSession;
use Psr\Log\LoggerInterface;
class ConfigService {
protected $appName;
/** @var IConfig */
private $config;
/** @var IGroupManager */
private $groupManager;
/** @var LoggerInterface */
private $logger;
/** @var IUser */
private $currentUser;
public function __construct(string $appName,
IConfig $config,
IGroupManager $groupManager,
LoggerInterface $logger,
IUserSession $userSession) {
$this->appName = $appName;
$this->config = $config;
$this->groupManager = $groupManager;
$this->logger = $logger;
private IUser $currentUser;
public function __construct(
protected string $appName,
private IConfig $config,
private IGroupManager $groupManager,
private LoggerInterface $logger,
IUserSession $userSession
) {
$this->currentUser = $userSession->getUser();
}

Просмотреть файл

@ -54,7 +54,7 @@ use Psr\Log\LoggerInterface;
*/
class FormsService {
private ?IUser $currentUser;
public function __construct(
IUserSession $userSession,
private ActivityManager $activityManager,

Просмотреть файл

@ -32,10 +32,8 @@ use OCA\Forms\Db\Answer;
use OCA\Forms\Db\AnswerMapper;
use OCA\Forms\Db\Form;
use OCA\Forms\Db\FormMapper;
use OCA\Forms\Db\Question;
use OCA\Forms\Db\QuestionMapper;
use OCA\Forms\Db\Submission;
use OCA\Forms\Db\SubmissionMapper;
use OCA\Forms\Db\UploadedFileMapper;
use OCP\AppFramework\Db\DoesNotExistException;
@ -60,66 +58,24 @@ use PhpOffice\PhpSpreadsheet\Writer\Csv;
use Psr\Log\LoggerInterface;
class SubmissionService {
/** @var FormMapper */
private $formMapper;
/** @var QuestionMapper */
private $questionMapper;
/** @var SubmissionMapper */
private $submissionMapper;
/** @var AnswerMapper */
private $answerMapper;
/** @var IRootFolder */
private $storage;
/** @var IConfig */
private $config;
/** @var IL10N */
private $l10n;
/** @var LoggerInterface */
private $logger;
/** @var IUserManager */
private $userManager;
/** @var IUser */
private $currentUser;
/** @var IMailer */
private $mailer;
public function __construct(FormMapper $formMapper,
QuestionMapper $questionMapper,
SubmissionMapper $submissionMapper,
AnswerMapper $answerMapper,
IRootFolder $storage,
IConfig $config,
IL10N $l10n,
LoggerInterface $logger,
IUserManager $userManager,
private ?IUser $currentUser;
public function __construct(
private QuestionMapper $questionMapper,
private SubmissionMapper $submissionMapper,
private AnswerMapper $answerMapper,
private UploadedFileMapper $uploadedFileMapper,
private IRootFolder $storage,
private IConfig $config,
private IL10N $l10n,
private LoggerInterface $logger,
private IUserManager $userManager,
IUserSession $userSession,
IMailer $mailer,
private IMailer $mailer,
private ITempManager $tempManager,
private FormsService $formsService,
private IUrlGenerator $urlGenerator,
private UploadedFileMapper $uploadedFileMapper,
) {
$this->formMapper = $formMapper;
$this->questionMapper = $questionMapper;
$this->submissionMapper = $submissionMapper;
$this->answerMapper = $answerMapper;
$this->storage = $storage;
$this->config = $config;
$this->l10n = $l10n;
$this->logger = $logger;
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->currentUser = $userSession->getUser();
}
@ -253,7 +209,7 @@ class SubmissionService {
$questions = $this->questionMapper->findByForm($form->getId());
$defaultTimeZone = date_default_timezone_get();
if ($this->currentUser == null) {
if (!$this->currentUser) {
$userTimezone = $this->config->getUserValue($form->getOwnerId(), 'core', 'timezone', $defaultTimeZone);
} else {
$userTimezone = $this->config->getUserValue($this->currentUser->getUID(), 'core', 'timezone', $defaultTimeZone);

Просмотреть файл

@ -33,25 +33,12 @@ use OCP\Settings\ISettings;
use OCP\Util;
class Settings implements ISettings {
private $appName;
/** @var ConfigService */
private $configService;
/** @var IGroupManager */
private $groupManager;
/** @var IInitialState */
private $initialState;
public function __construct(string $appName,
ConfigService $configService,
IGroupManager $groupManager,
IInitialState $initialState) {
$this->appName = $appName;
$this->configService = $configService;
$this->groupManager = $groupManager;
$this->initialState = $initialState;
public function __construct(
private string $appName,
private ConfigService $configService,
private IGroupManager $groupManager,
private IInitialState $initialState
) {
}
/**

Просмотреть файл

@ -30,16 +30,10 @@ use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class SettingsSection implements IIconSection {
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator
) {
}
/**

Просмотреть файл

@ -135,7 +135,6 @@ class SubmissionServiceTest extends TestCase {
$this->uploadedFileMapper = $this->createMock(UploadedFileMapper::class);
$this->submissionService = new SubmissionService(
$this->formMapper,
$this->questionMapper,
$this->submissionMapper,
$this->answerMapper,