Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native type declarations #567

Open
wants to merge 3 commits into
base: 11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Command/AssetCopyrightCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@

class AssetCopyrightCommand extends AbstractCommand
{
public function configure()
public function configure(): void
{
$this->setName('app:asset-copyright');
}

/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$assets = new Asset\Listing();
//$assets->setCondition('id = 219');
Expand Down
38 changes: 13 additions & 25 deletions src/Command/DataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use Pimcore\Console\AbstractCommand;
use Pimcore\Model\DataObject\AccessoryPart;
use Pimcore\Model\DataObject\Data\Geopoint;
use Pimcore\Model\DataObject\Data\GeoCoordinates;
use Pimcore\Model\DataObject\Data\QuantityValue;
use Pimcore\Model\DataObject\Objectbrick\Data\SaleInformation;
use Pimcore\Model\DataObject\QuantityValue\Unit;
Expand All @@ -26,41 +26,38 @@

class DataCommand extends AbstractCommand
{
protected $priceRange = [
protected array $priceRange = [
'from' => 57,
'to' => 900
];

protected $availabilityTypes = [
protected array $availabilityTypes = [
'couple-weeks',
'couple-days',
'instant'
];

protected $conditionTypes = [
protected array $conditionTypes = [
'broken',
'reworked',
'used',
'new' //not for cars
];

protected $locations = [
protected array $locations = [
[47.8156617813774, 13.049333095550539],
[48.197161014477935, 16.335082054138187],
[48.143553854307555, 11.556630134582521],
[52.526039219655445, 13.367292881011963],
[48.78339883980666, 9.180042743682863]
];

public function configure()
public function configure(): void
{
$this->setName('app:data-command');
}

/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$listing = new AccessoryPart\Listing();
foreach ($listing as $object) {
Expand Down Expand Up @@ -90,7 +87,7 @@ public function execute(InputInterface $input, OutputInterface $output)
//
// $geoPoint = $this->locations[rand(0,4)];
//
// $object->setLocation(new Geopoint($geoPoint[1], $geoPoint[0]));
// $object->setLocation(new GeoCoordinates($geoPoint[0], $geoPoint[1]));
//
// $object->setObjectType('actual-car');
//
Expand All @@ -103,7 +100,7 @@ public function execute(InputInterface $input, OutputInterface $output)
return 0;
}

protected function updateAccessoryKey(AccessoryPart $object)
protected function updateAccessoryKey(AccessoryPart $object): void
{
$key = '';

Expand All @@ -117,7 +114,7 @@ protected function updateAccessoryKey(AccessoryPart $object)
$object->setKey($key);
}

protected function updateAccessorySalesInformation(AccessoryPart $object)
protected function updateAccessorySalesInformation(AccessoryPart $object): void
{
$saleInformation = $object->getSaleInformation()->getSaleInformation();

Expand All @@ -132,7 +129,7 @@ protected function updateAccessorySalesInformation(AccessoryPart $object)
$saleInformation->setMilage(new QuantityValue(rand(30000, 300000), Unit::getByAbbreviation('km')));
}

protected function updateAccessoryERPInformation(AccessoryPart $part)
protected function updateAccessoryERPInformation(AccessoryPart $part): void
{
if (empty($part->getErpNumber())) {
$part->setErpNumber(crc32($part->getId()));
Expand All @@ -149,12 +146,7 @@ protected function updateAccessoryERPInformation(AccessoryPart $part)
$part->setOwner($owners[rand(0, count($owners) - 1)]);
}

/**
* @param int $min
* @param int $max
* @return float
*/
protected function generatePrice($min, $max)
protected function generatePrice(int $min, int $max): float
{
$price = rand($min, $max);

Expand All @@ -164,11 +156,7 @@ protected function generatePrice($min, $max)
return $price;
}

/**
* @param string $condition
* @return float
*/
protected function generateCarPrice($condition)
protected function generateCarPrice(string $condition): float
{
$priceRangeArray = [
'broken' => [1500, 7500],
Expand Down
89 changes: 26 additions & 63 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,15 @@
class AccountController extends BaseController
{
use PasswordMaxLengthTrait;

/**
* @Route("/account/login", name="account-login")
*
* @param AuthenticationUtils $authenticationUtils
* @param Request $request
* @param UserInterface|null $user
*
* @return Response|RedirectResponse
*/
public function loginAction(
AuthenticationUtils $authenticationUtils,
Request $request,
UserInterface $user = null
) {

): RedirectResponse|Response {
//redirect user to index page if logged in
if ($user && $this->isGranted('ROLE_USER')) {
return $this->redirectToRoute('account-index');
Expand Down Expand Up @@ -96,24 +90,10 @@ public function loginAction(
}

/**
*
* This could be further separated into services, but was kept as single method for demonstration purposes as the
* registration process is different on every project.
*
* @Route("/account/register", name="account-register")
*
* @param Request $request
* @param CustomerProviderInterface $customerProvider
* @param LoginManagerInterface $loginManager
* @param RegistrationFormHandler $registrationFormHandler
* @param AuthenticationLoginListener $authenticationLoginListener
* @param Translator $translator
* @param Service $consentService
* @param UrlGeneratorInterface $urlGenerator
* @param NewsletterDoubleOptInService $newsletterDoubleOptInService
* @param UserInterface|null $user
*
* @return Response|RedirectResponse
*/
public function registerAction(
Request $request,
Expand All @@ -126,8 +106,7 @@ public function registerAction(
UrlGeneratorInterface $urlGenerator,
NewsletterDoubleOptInService $newsletterDoubleOptInService,
UserInterface $user = null
) {

): RedirectResponse|Response {
//redirect user to index page if logged in
if ($user && $this->isGranted('ROLE_USER')) {
return $this->redirectToRoute('account-index');
Expand Down Expand Up @@ -206,13 +185,9 @@ public function registerAction(
* Index page for account - it is restricted to ROLE_USER via security annotation
*
* @Route("/account/index", name="account-index")
*
* @param UserInterface|null $user
*
* @return Response
*/
#[IsGranted('ROLE_USER')]
public function indexAction(UserInterface $user = null)
public function indexAction(UserInterface $user = null): Response
{
$orderManager = Factory::getInstance()->getOrderManager();
$orderList = $orderManager->createOrderList();
Expand All @@ -228,19 +203,16 @@ public function indexAction(UserInterface $user = null)
/**
* @Route("/account/update-marketing", name="account-update-marketing-permission")
*
* @param Request $request
* @param Service $consentService
* @param Translator $translator
* @param NewsletterDoubleOptInService $newsletterDoubleOptInService
* @param UserInterface|null $user
*
* @return RedirectResponse
*
* @throws \Exception
*/
#[IsGranted('ROLE_USER')]
public function updateMarketingPermissionAction(Request $request, Service $consentService, Translator $translator, NewsletterDoubleOptInService $newsletterDoubleOptInService, UserInterface $user = null)
{
public function updateMarketingPermissionAction(
Request $request,
Service $consentService,
Translator $translator,
NewsletterDoubleOptInService $newsletterDoubleOptInService,
UserInterface $user = null
): RedirectResponse {
if ($user instanceof Customer) {
$currentNewsletterPermission = $user->getNewsletter()->getConsent();
if (!$currentNewsletterPermission && $request->get('newsletter')) {
Expand Down Expand Up @@ -268,15 +240,12 @@ public function updateMarketingPermissionAction(Request $request, Service $conse

/**
* @Route("/account/confirm-newsletter", name="account-confirm-newsletter")
*
* @param Request $request
* @param NewsletterDoubleOptInService $newsletterDoubleOptInService
* @param Translator $translator
*
* @return RedirectResponse
*/
public function confirmNewsletterAction(Request $request, NewsletterDoubleOptInService $newsletterDoubleOptInService, Translator $translator)
{
public function confirmNewsletterAction(
Request $request,
NewsletterDoubleOptInService $newsletterDoubleOptInService,
Translator $translator
): RedirectResponse {
$token = $request->get('token');
$customer = $newsletterDoubleOptInService->handleDoubleOptInConfirmation($token);
if ($customer) {
Expand All @@ -291,16 +260,13 @@ public function confirmNewsletterAction(Request $request, NewsletterDoubleOptInS
/**
* @Route("/account/send-password-recovery", name="account-password-send-recovery")
*
* @param Request $request
* @param PasswordRecoveryService $service
* @param Translator $translator
*
* @return Response
*
* @throws \Exception
*/
public function sendPasswordRecoveryMailAction(Request $request, PasswordRecoveryService $service, Translator $translator)
{
public function sendPasswordRecoveryMailAction(
Request $request,
PasswordRecoveryService $service,
Translator $translator
): Response {
if ($request->isMethod(Request::METHOD_POST)) {
try {
$service->sendRecoveryMail(
Expand All @@ -324,15 +290,12 @@ public function sendPasswordRecoveryMailAction(Request $request, PasswordRecover

/**
* @Route("/account/reset-password", name="account-reset-password")
*
* @param Request $request
* @param PasswordRecoveryService $service
* @param Translator $translator
*
* @return Response|RedirectResponse
*/
public function resetPasswordAction(Request $request, PasswordRecoveryService $service, Translator $translator)
{
public function resetPasswordAction(
Request $request,
PasswordRecoveryService $service,
Translator $translator
): RedirectResponse|Response {
$token = $request->get('token');
$customer = $service->getCustomerByToken($token);
$error = null;
Expand Down
11 changes: 0 additions & 11 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@

class BaseController extends FrontendController
{
/**
* @param Request $request
* @param DataObject $object
*
* @return bool
*/
protected function verifyPreviewRequest(Request $request, DataObject $object): bool
{
if (Tool::isElementRequestByAdmin($request, $object)) {
Expand All @@ -37,11 +31,6 @@ protected function verifyPreviewRequest(Request $request, DataObject $object): b
return false;
}

/**
* @param Request $request
*
* @return array
*/
protected function getAllParameters(Request $request): array
{
return array_merge($request->request->all(), $request->query->all());
Expand Down