Skip to content

Commit

Permalink
Fix PHP CS
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Nov 3, 2021
1 parent d61191f commit c8c5151
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 159 deletions.
29 changes: 19 additions & 10 deletions src/Controller/Admin/ReportsController.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\Controller\Admin;

use MonsieurBiz\SyliusSalesReportsPlugin\Event\CustomReportEvent;
use MonsieurBiz\SyliusSalesReportsPlugin\Exception\InvalidDateException;
use MonsieurBiz\SyliusSalesReportsPlugin\Form\Type\DateType;
use MonsieurBiz\SyliusSalesReportsPlugin\Form\Type\PeriodType;
use MonsieurBiz\SyliusSalesReportsPlugin\Repository\ReportRepository;
use Sylius\Component\Core\Model\ChannelInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use MonsieurBiz\SyliusSalesReportsPlugin\Form\Type\DateType;
use Webmozart\Assert\Assert;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

final class ReportsController extends AbstractController
{
const APPEND_REPORTS_EVENT = 'monsieurbiz.sylius_sales_report.append_reports';
public const APPEND_REPORTS_EVENT = 'monsieurbiz.sylius_sales_report.append_reports';

/**
* @var ReportRepository
Expand All @@ -33,8 +42,6 @@ final class ReportsController extends AbstractController

/**
* ReportsController constructor.
* @param ReportRepository $reportRepository
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
ReportRepository $reportRepository,
Expand All @@ -45,10 +52,7 @@ public function __construct(
}

/**
* View the report for a single date
*
* @param Request $request
* @return Response
* View the report for a single date.
*/
public function indexAction(Request $request): Response
{
Expand Down Expand Up @@ -98,7 +102,11 @@ public function indexAction(Request $request): Response

// Reverse date if from date greater than end date
if ($from > $to) {
$tmp = $to; $to = $from; $from = $tmp; $data['from'] = $from; $data['to'] = $to;
$tmp = $to;
$to = $from;
$from = $tmp;
$data['from'] = $from;
$data['to'] = $to;
}

Assert::isInstanceOf($channel, ChannelInterface::class);
Expand All @@ -115,6 +123,7 @@ public function indexAction(Request $request): Response
$productOptionValueSalesResult = $this->reportRepository->getProductOptionValueSalesForChannelForDates($channel, $from, $to);
} catch (InvalidDateException $e) {
$form->addError(new FormError($e->getMessage()));

return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
'form' => $form->createView(),
]);
Expand Down
13 changes: 11 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\DependencyInjection;
Expand All @@ -10,12 +19,12 @@
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(MonsieurBizSyliusSalesReportsExtension::EXTENSION_CONFIG_NAME);
if (\method_exists($treeBuilder, 'getRootNode')) {
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
Expand Down
14 changes: 11 additions & 3 deletions src/DependencyInjection/MonsieurBizSyliusSalesReportsExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\DependencyInjection;
Expand All @@ -12,10 +21,9 @@

final class MonsieurBizSyliusSalesReportsExtension extends Extension
{
public const EXTENSION_CONFIG_NAME = 'monsieurbiz_sylius_sales_reports';

CONST EXTENSION_CONFIG_NAME = 'monsieurbiz_sylius_sales_reports';

public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = $this->getConfiguration([], $container);
if ($configuration instanceof ConfigurationInterface) {
Expand Down
33 changes: 14 additions & 19 deletions src/Event/CustomReportEvent.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\Event;
Expand Down Expand Up @@ -42,23 +51,19 @@ public function __construct(
}

/**
* Retrieve custom reports, use a template override to display it
*
* @return array
* Retrieve custom reports, use a template override to display it.
*/
public function getCustomReports(): array
{
return $this->customReports;
}

/**
* Add a new custom report, you can't have reports with the same key
* Add a new custom report, you can't have reports with the same key.
*
* @param string $key
* @param array $data
* @throws AlreadyExistsReport
*/
public function addReport(string $key, array $data)
public function addReport(string $key, array $data): void
{
if (isset($this->customReports[$key])) {
throw new AlreadyExistsReport(sprintf('Report "%s" already exists', $key));
Expand All @@ -67,38 +72,28 @@ public function addReport(string $key, array $data)
}

/**
* Remove a custom report, you cannot remove a key which not exists
* Remove a custom report, you cannot remove a key which not exists.
*
* @param string $key
* @throws NotExistsReport
*/
public function removeReport(string $key)
public function removeReport(string $key): void
{
if (!isset($this->customReports[$key])) {
throw new NotExistsReport(sprintf('Report "%s" does not exist', $key));
}
unset($this->customReports[$key]);
}

/**
* @return ChannelInterface
*/
public function getChannel(): ChannelInterface
{
return $this->channel;
}

/**
* @return \DateTimeInterface
*/
public function getFromDate(): \DateTimeInterface
{
return $this->fromDate;
}

/**
* @return \DateTimeInterface|null
*/
public function getToDate(): ?\DateTimeInterface
{
return $this->toDate;
Expand Down
15 changes: 13 additions & 2 deletions src/Exception/AlreadyExistsReport.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;
/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

class AlreadyExistsReport extends \Exception {
namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;

class AlreadyExistsReport extends \Exception
{
}
15 changes: 13 additions & 2 deletions src/Exception/InvalidDateException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;
/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

class InvalidDateException extends \Exception {
namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;

class InvalidDateException extends \Exception
{
}
15 changes: 13 additions & 2 deletions src/Exception/MissingLocaleException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;
/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

class MissingLocaleException extends \Exception {
namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;

class MissingLocaleException extends \Exception
{
}
15 changes: 13 additions & 2 deletions src/Exception/NotExistsReport.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;
/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

class NotExistsReport extends \Exception {
namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;

class NotExistsReport extends \Exception
{
}
11 changes: 10 additions & 1 deletion src/Form/Type/DateType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\Form\Type;
Expand All @@ -12,7 +21,7 @@

class DateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('date', SymfonyDateType::class, [
Expand Down
11 changes: 10 additions & 1 deletion src/Form/Type/PeriodType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\Form\Type;
Expand All @@ -12,7 +21,7 @@

class PeriodType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('from', SymfonyDateType::class, [
Expand Down
15 changes: 12 additions & 3 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of Monsieur Biz' Sales Reports plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusSalesReportsPlugin\Menu;

use Knp\Menu\ItemInterface;
Expand All @@ -8,9 +19,7 @@
class AdminMenuListener
{
/**
* Add reports link in sales menu
*
* @param MenuBuilderEvent $event
* Add reports link in sales menu.
*/
public function addAdminMenuItem(MenuBuilderEvent $event): void
{
Expand Down
Loading

0 comments on commit c8c5151

Please sign in to comment.