Skip to content

Commit

Permalink
Correct PHP Stan, improve Scrutinizer score
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Feb 18, 2020
1 parent d3fa9a5 commit 840a38d
Show file tree
Hide file tree
Showing 15 changed files with 512 additions and 421 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

A simple plugin to have sales reports in Sylius

![Reports form](screenshots/reports_form.png)

## Installation

```bash
Expand Down Expand Up @@ -48,6 +50,38 @@ monsieur_biz_sales_reports_plugin:
resource: "@MonsieurBizSyliusSalesReportsPlugin/Resources/config/routing.yaml"
```
## Reports
All reports columns are sortable by clicking on it.
### Global sales report
![Global sales report](screenshots/global.png)
### Average sales report
![Average sales report](screenshots/average.png)
### Product report
![Product report](screenshots/product.png)
### Product variant report
![Product variant report](screenshots/product_variant.png)
### Option report
![Option report](screenshots/option.png)
### Option value report
![Option value report](screenshots/option_value.png)
### Add your custom reports !
An event is available to add your custom reports, see `CustomReportEvent` class in the plugin.
## Contributing
You can open an issue or a Pull Request if you want! 😘
Expand Down
8 changes: 7 additions & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Installation

1. From the plugin root directory, run the following commands:
1. To be able to run yarn build correctly, create symlink for `node_modules` :

```bash
ln -s tests/Application/node_modules node_modules
```

2. From the plugin root directory, run the following commands:

```bash
$ (cd tests/Application && yarn install)
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ parameters:
# Test dependencies
- 'tests/Application/app/**.php'
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 $configuration of method Symfony\Component\DependencyInjection\Extension\Extension::processConfiguration() expects Symfony\Component\Config\Definition\ConfigurationInterface, Symfony\Component\Config\Definition\ConfigurationInterface|null given./'
Binary file added screenshots/average.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/option.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/option_value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/product.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/product_variant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/reports_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 6 additions & 15 deletions src/Controller/Admin/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use MonsieurBiz\SyliusSalesReportsPlugin\Form\Type\DateType;
use Symfony\Component\Templating\EngineInterface;
use Webmozart\Assert\Assert;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand All @@ -27,28 +26,20 @@ final class ReportsController extends AbstractController
*/
protected $reportRepository;

/**
* @var EngineInterface
*/
private $templatingEngine;

/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;

/**
* ReportsController constructor.
* @param EngineInterface $templatingEngine
* @param ReportRepository $reportRepository
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
EngineInterface $templatingEngine,
ReportRepository $reportRepository,
EventDispatcherInterface $eventDispatcher
) {
$this->templatingEngine = $templatingEngine;
$this->reportRepository = $reportRepository;
$this->eventDispatcher = $eventDispatcher;
}
Expand All @@ -66,7 +57,7 @@ public function indexAction(Request $request): Response

// Form not submitted yet
if (null === $request->request->get($form->getName()) && null === $request->request->get($formPeriod->getName())) {
return $this->templatingEngine->renderResponse('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
'form' => $form->createView(),
'form_period' => $formPeriod->createView(),
]);
Expand All @@ -76,7 +67,7 @@ public function indexAction(Request $request): Response
if ($request->request->get($form->getName())) {
$form->submit($request->request->get($form->getName()));
if (!$form->isSubmitted() || !$form->isValid()) {
return $this->templatingEngine->renderResponse('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
'form' => $form->createView(),
'form_period' => $formPeriod->createView(),
]);
Expand All @@ -87,7 +78,7 @@ public function indexAction(Request $request): Response
if ($request->request->get($formPeriod->getName())) {
$formPeriod->submit($request->request->get($formPeriod->getName()));
if (!$formPeriod->isSubmitted() || !$formPeriod->isValid()) {
return $this->templatingEngine->renderResponse('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
'form' => $form->createView(),
'form_period' => $formPeriod->createView(),
]);
Expand Down Expand Up @@ -124,15 +115,15 @@ public function indexAction(Request $request): Response
$productOptionValueSalesResult = $this->reportRepository->getProductOptionValueSalesForChannelForDates($channel, $from, $to);
} catch (InvalidDateException $e) {
$form->addError(new FormError($e->getMessage()));
return $this->templatingEngine->renderResponse('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/index.html.twig', [
'form' => $form->createView(),
]);
}

$event = new CustomReportEvent($channel, $from, $to);
$this->eventDispatcher->dispatch(self::APPEND_REPORTS_EVENT, $event);
$this->eventDispatcher->dispatch($event);

return $this->templatingEngine->renderResponse('@MonsieurBizSyliusSalesReportsPlugin/Admin/view.html.twig', [
return $this->render('@MonsieurBizSyliusSalesReportsPlugin/Admin/view.html.twig', [
'form' => $form->createView(),
'form_period' => $formPeriod->createView(),
'from' => $from,
Expand Down
7 changes: 7 additions & 0 deletions src/Exception/MissingLocaleException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace MonsieurBiz\SyliusSalesReportsPlugin\Exception;

class MissingLocaleException extends \Exception {

}
16 changes: 10 additions & 6 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MonsieurBiz\SyliusSalesReportsPlugin\Menu;

use Knp\Menu\ItemInterface;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;

class AdminMenuListener
Expand All @@ -15,11 +16,14 @@ public function addAdminMenuItem(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();

$menu
->getChild('sales')
->addChild('monsieur_biz_sales_reports', ['route' => 'monsieur_biz_sylius_sales_reports_admin_index'])
->setLabel('monsieur_biz_sales_reports.ui.title')
->setLabelAttribute('icon', 'list alternate')
;
$salesMenu = $menu->getChild('sales');

if ($salesMenu instanceof ItemInterface) {
$salesMenu
->addChild('monsieur_biz_sales_reports', ['route' => 'monsieur_biz_sylius_sales_reports_admin_index'])
->setLabel('monsieur_biz_sales_reports.ui.title')
->setLabelAttribute('icon', 'list alternate')
;
}
}
}
Loading

0 comments on commit 840a38d

Please sign in to comment.