Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
added scalar type hints; minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed Mar 26, 2019
1 parent 7fe3d9f commit 57fc9cf
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 567 deletions.
52 changes: 28 additions & 24 deletions Constant.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Zikula package.
*
Expand All @@ -24,152 +25,155 @@ class Constant
*
* @var string
*/
const MODNAME = 'ZikulaLegalModule';
public const MODNAME = 'ZikulaLegalModule';

const FORM_BLOCK_PREFIX = 'zikulalegalmodule_policy';
/**
* The form data prefix
*/
public const FORM_BLOCK_PREFIX = 'zikulalegalmodule_policy';

/**
* This key is used to 'disguise' the purpose of passing the UID in the session.
*/
const FORCE_POLICY_ACCEPTANCE_SESSION_UID_KEY = 'kjh4kjgsdkjyf76r44hf9';
public const FORCE_POLICY_ACCEPTANCE_SESSION_UID_KEY = 'kjh4kjgsdkjyf76r44hf9';

/**
* The module variable name indicating that the legal notice is active.
*
* @var string
*/
const MODVAR_LEGALNOTICE_ACTIVE = 'legalNoticeActive';
public const MODVAR_LEGALNOTICE_ACTIVE = 'legalNoticeActive';

/**
* The module variable name indicating that the terms of use is active.
*
* @var string
*/
const MODVAR_TERMS_ACTIVE = 'termsOfUseActive';
public const MODVAR_TERMS_ACTIVE = 'termsOfUseActive';

/**
* The module variable name indicating that the privacy policy is active.
*
* @var string
*/
const MODVAR_PRIVACY_ACTIVE = 'privacyPolicyActive';
public const MODVAR_PRIVACY_ACTIVE = 'privacyPolicyActive';

/**
* The module variable name indicating that the accessibility statement is active.
*
* @var string
*/
const MODVAR_ACCESSIBILITY_ACTIVE = 'accessibilityStatementActive';
public const MODVAR_ACCESSIBILITY_ACTIVE = 'accessibilityStatementActive';

/**
* The module variable name indicating that the trade conditions page is active.
*
* @var string
*/
const MODVAR_TRADECONDITIONS_ACTIVE = 'tradeConditionsActive';
public const MODVAR_TRADECONDITIONS_ACTIVE = 'tradeConditionsActive';

/**
* The module variable name indicating that the cancellation right policy page is active.
*
* @var string
*/
const MODVAR_CANCELLATIONRIGHTPOLICY_ACTIVE = 'cancellationRightPolicyActive';
public const MODVAR_CANCELLATIONRIGHTPOLICY_ACTIVE = 'cancellationRightPolicyActive';

/**
* The module variable name storing an optional url for the legal notice.
*
* @var string
*/
const MODVAR_LEGALNOTICE_URL = 'legalNoticeUrl';
public const MODVAR_LEGALNOTICE_URL = 'legalNoticeUrl';

/**
* The module variable name storing an optional url for the terms of use.
*
* @var string
*/
const MODVAR_TERMS_URL = 'termsOfUseUrl';
public const MODVAR_TERMS_URL = 'termsOfUseUrl';

/**
* The module variable name storing an optional url for the privacy policy.
*
* @var string
*/
const MODVAR_PRIVACY_URL = 'privacyPolicyUrl';
public const MODVAR_PRIVACY_URL = 'privacyPolicyUrl';

/**
* The module variable name storing an optional url for the accessibility guidelines.
*
* @var string
*/
const MODVAR_ACCESSIBILITY_URL = 'accessibilityStatementUrl';
public const MODVAR_ACCESSIBILITY_URL = 'accessibilityStatementUrl';

/**
* The module variable name storing an optional url for the trade conditions.
*
* @var string
*/
const MODVAR_TRADECONDITIONS_URL = 'tradeConditionsUrl';
public const MODVAR_TRADECONDITIONS_URL = 'tradeConditionsUrl';

/**
* The module variable name storing an optional url for the cancellation right policy.
*
* @var string
*/
const MODVAR_CANCELLATIONRIGHTPOLICY_URL = 'cancellationRightPolicyUrl';
public const MODVAR_CANCELLATIONRIGHTPOLICY_URL = 'cancellationRightPolicyUrl';

/**
* The module variable containing the minimum age.
*
* @var string
*/
const MODVAR_MINIMUM_AGE = 'minimumAge';
public const MODVAR_MINIMUM_AGE = 'minimumAge';

/**
* The module variable indicating that the EU cookie law complaince option is enabled.
*
* @var int
* @var string
*/
const MODVAR_EUCOOKIE = 'eucookie';
public const MODVAR_EUCOOKIE = 'eucookie';

/**
* Users account record attribute key for terms of use acceptance.
*
* @var string
*/
const ATTRIBUTE_TERMSOFUSE_ACCEPTED = '_Legal_termsOfUseAccepted';
public const ATTRIBUTE_TERMSOFUSE_ACCEPTED = '_Legal_termsOfUseAccepted';

/**
* Users account record attribute key for terms of use acceptance.
*
* @var string
*/
const ATTRIBUTE_PRIVACYPOLICY_ACCEPTED = '_Legal_privacyPolicyAccepted';
public const ATTRIBUTE_PRIVACYPOLICY_ACCEPTED = '_Legal_privacyPolicyAccepted';

/**
* Users account record attribute key for age policy confirmation.
*
* @var string
*/
const ATTRIBUTE_AGEPOLICY_CONFIRMED = '_Legal_agePolicyConfirmed';
public const ATTRIBUTE_AGEPOLICY_CONFIRMED = '_Legal_agePolicyConfirmed';

/**
* Users account record attribute key for trade conditions acceptance.
*
* @var string
*/
const ATTRIBUTE_TRADECONDITIONS_ACCEPTED = '_Legal_tradeConditionsConfirmed';
public const ATTRIBUTE_TRADECONDITIONS_ACCEPTED = '_Legal_tradeConditionsConfirmed';

/**
* Users account record attribute key for cancellation right policy acceptance.
*
* @var string
*/
const ATTRIBUTE_CANCELLATIONRIGHTPOLICY_ACCEPTED = '_Legal_cancellationRightPolicyConfirmed';
public const ATTRIBUTE_CANCELLATIONRIGHTPOLICY_ACCEPTED = '_Legal_cancellationRightPolicyConfirmed';

/**
* Users account record attribute key for eu cookie acceptance.
*
* @var string
*/
const ATTRIBUTE_EUCOOKIE_ACCEPTED = '_Legal_euCookieConfirmed';
public const ATTRIBUTE_EUCOOKIE_ACCEPTED = '_Legal_euCookieConfirmed';
}
70 changes: 22 additions & 48 deletions Container/LinkContainer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Zikula package.
*
Expand Down Expand Up @@ -41,31 +42,19 @@ class LinkContainer implements LinkContainerInterface
*/
private $variableApi;

/**
* LinkContainer constructor.
*
* @param TranslatorInterface $translator Translator service instance
* @param RouterInterface $router RouterInterface service instance
* @param PermissionApiInterface $permissionApi PermissionApi service instance
* @param VariableApiInterface $variableApi VariableApi service instance
*/
public function __construct(TranslatorInterface $translator, RouterInterface $router, PermissionApiInterface $permissionApi, VariableApiInterface $variableApi)
{
public function __construct(
TranslatorInterface $translator,
RouterInterface $router,
PermissionApiInterface $permissionApi,
VariableApiInterface $variableApi
) {
$this->translator = $translator;
$this->router = $router;
$this->permissionApi = $permissionApi;
$this->variableApi = $variableApi;
}

/**
* get Links of any type for this extension
* required by the interface.
*
* @param string $type
*
* @return array
*/
public function getLinks($type = LinkContainerInterface::TYPE_ADMIN)
public function getLinks(string $type = LinkContainerInterface::TYPE_ADMIN): array
{
$method = 'get'.ucfirst(mb_strtolower($type));
if (method_exists($this, $method)) {
Expand All @@ -76,11 +65,9 @@ public function getLinks($type = LinkContainerInterface::TYPE_ADMIN)
}

/**
* get the Admin links for this extension.
*
* @return array
* Get the admin links for this extension.
*/
private function getAdmin()
private function getAdmin(): array
{
$links = [];

Expand All @@ -96,45 +83,43 @@ private function getAdmin()
}

/**
* get the User links for this extension.
*
* @return array
* Get the user links for this extension.
*/
private function getUser()
private function getUser(): array
{
$links = [];

if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_LEGALNOTICE_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_LEGALNOTICE_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Legal notice', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_LEGALNOTICE_URL, 'legalnotice'),
];
}
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_TERMS_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_TERMS_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Terms of use', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_TERMS_URL, 'termsofuse'),
];
}
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_PRIVACY_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_PRIVACY_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Privacy policy', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_PRIVACY_URL, 'privacypolicy'),
];
}
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_TRADECONDITIONS_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_TRADECONDITIONS_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Trade conditions', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_TRADECONDITIONS_URL, 'tradeconditions'),
];
}
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_CANCELLATIONRIGHTPOLICY_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_CANCELLATIONRIGHTPOLICY_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Cancellation right policy', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_CANCELLATIONRIGHTPOLICY_URL, 'cancellationrightpolicy'),
];
}
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_ACCESSIBILITY_ACTIVE, false)) {
if ($this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_ACCESSIBILITY_ACTIVE)) {
$links[] = [
'text' => $this->translator->__('Accessibility statement', 'zikulalegalmodule'),
'url' => $this->determineUrl(LegalConstant::MODVAR_ACCESSIBILITY_URL, 'accessibilitystatement'),
Expand All @@ -145,11 +130,9 @@ private function getUser()
}

/**
* get the Account links for this extension.
*
* @return array
* Get the account links for this extension.
*/
private function getAccount()
private function getAccount(): array
{
$links = [];
$links[] = [
Expand All @@ -163,12 +146,8 @@ private function getAccount()

/**
* Determine the URL for a certain user link.
*
* @param string $urlVar Name of module var storing a possible custom url
* @param string $defaultRoute Suffix for route for default url
* @return string
*/
private function determineUrl($urlVar, $defaultRoute)
private function determineUrl(string $urlVar, string $defaultRoute): string
{
$customUrl = $this->variableApi->get(LegalConstant::MODNAME, $urlVar, '');
if ('' !== $customUrl) {
Expand All @@ -178,12 +157,7 @@ private function determineUrl($urlVar, $defaultRoute)
return $this->router->generate('zikulalegalmodule_user_'.$defaultRoute);
}

/**
* set the BundleName as required by the interface.
*
* @return string
*/
public function getBundleName()
public function getBundleName(): string
{
return LegalConstant::MODNAME;
}
Expand Down
12 changes: 6 additions & 6 deletions Controller/ConfigController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Zikula package.
*
Expand All @@ -12,10 +13,11 @@

namespace Zikula\LegalModule\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Zikula\Core\Controller\AbstractController;
use Zikula\GroupsModule\Entity\RepositoryInterface\GroupRepositoryInterface;
Expand All @@ -36,11 +38,8 @@ class ConfigController extends AbstractController
* @Theme("admin")
* @Template("ZikulaLegalModule:Config:config.html.twig")
*
* @param Request $request
* @param GroupRepositoryInterface $groupRepository
* @param ResetAgreementHelper $resetAgreementHelper
*
* @throws AccessDeniedException Thrown if the user doesn't have admin access to the module
* @throws Exception
*
* @return array|RedirectResponse
*/
Expand Down Expand Up @@ -108,7 +107,8 @@ public function configAction(
$this->addFlash('status', $this->__('Operation cancelled.'));
}

return $this->redirectToRoute('zikulalegalmodule_config_config'); // redirecting prevents values from being repeated in the form
// redirecting prevents values from being repeated in the form
return $this->redirectToRoute('zikulalegalmodule_config_config');
}

return [
Expand Down
Loading

0 comments on commit 57fc9cf

Please sign in to comment.