Skip to content

Commit

Permalink
Github CI test (#18)
Browse files Browse the repository at this point in the history
### New features
* new github action: php cs
### Improvements
* massive code-style fix
  • Loading branch information
sigere authored Jan 10, 2022
1 parent c0d4db8 commit 39659a8
Show file tree
Hide file tree
Showing 23 changed files with 615 additions and 465 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/phpcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Analysis
on: pull_request

jobs:
build:
name: Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v1

- name: PHP CodeSniffer
run: |
composer global require "squizlabs/php_codesniffer=*" \
--no-interaction --prefer-dist --ignore-platform-reqs --quiet
~/.composer/vendor/bin/phpcs --config-set colors 1
~/.composer/vendor/bin/phpcs \
--extensions=php \
--standard=./dev/phpcs/ruleset.xml \
./src -s
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"squizlabs/php_codesniffer": "*",
"symfony/debug-bundle": "5.2.*"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true
}
},
"autoload": {
"psr-4": {
Expand Down
60 changes: 58 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions dev/phpcs/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="OrderManagerDefaultPHPCS">
<description>Order Manage rDefault PHP Code Sniffer ruleset.</description>
<rule ref="PSR2" />
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1" />
<property name="ignoreNewlines" value="true" />
</properties>
</rule>
</ruleset>

10 changes: 10 additions & 0 deletions dev/phpcs/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

docker-compose exec -u www-data php \
./vendor/bin/phpcs --config-set colors 1

docker-compose exec -u www-data php \
./vendor/bin/phpcs \
--extensions=php \
--standard=./dev/phpcs/ruleset.xml \
./src -s
57 changes: 35 additions & 22 deletions src/Controller/ArchivesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
use App\Entity\Order;
use App\Entity\Staff;
use App\Form\ArchivesFiltersForm;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ArchivesController extends AbstractController
{
private $entityManager;
private $request;
private ?Request $request;

public function __construct(EntityManagerInterface $entityManager, RequestStack $request)
{
$this->entityManager = $entityManager;
public function __construct(
private EntityManagerInterface $entityManager,
RequestStack $request
) {
$this->request = $request->getCurrentRequest();
}

Expand All @@ -44,9 +44,12 @@ private function loadOrdersTable(): array
$repository = $this->entityManager->getRepository(Order::class);
$user = $this->getUser();
$preferences = $user->getPreferences();
$staff = $this->entityManager->getRepository(Staff::class)->findOneBy(['id' => $preferences['archives']['select-staff']]);

//doctrine nie zapisuje obiektów w user->preferences['archives']['select-client'],
//więc mapuje na id przy zapisie i na obiekt przy odczycie
$staff = $this->entityManager->getRepository(Staff::class)->findOneBy(
['id' => $preferences['archives']['select-staff']]
);

$orders = $repository->createQueryBuilder('o');

Expand All @@ -66,33 +69,32 @@ private function loadOrdersTable(): array
if ($preferences['archives']['select-client']) {
$orders = $orders
->andWhere('o.client = :client')
->setParameter('client', $repository->findOneBy(['id' => $preferences['archives']['select-client']]));
->setParameter('client', $repository->findOneBy(
['id' => $preferences['archives']['select-client']]
));
}
//doctrine nie zapisuje obiektów w user->preferences['archives']['select-client'],
//więc mapuje na id przy zapisie i na obiekt przy odczycie

$dateType = $preferences['archives']['date-type'];
if ($preferences['archives']['date-from']) {
$dateFrom = new Datetime($preferences['archives']['date-from']['date']);
$dateFrom = new \Datetime($preferences['archives']['date-from']['date']);
$orders
->andWhere('o.'.$dateType.' >= :dateFrom')
->andWhere('o.' . $dateType . ' >= :dateFrom')
->setParameter('dateFrom', $dateFrom);
}
if ($preferences['archives']['date-to']) {
$dateTo = new Datetime($preferences['archives']['date-to']['date']);
$dateTo = new \Datetime($preferences['archives']['date-to']['date']);
$dateTo->setTime(23, 59);
$orders
->andWhere('o.'.$dateType.' <= :dateTo')
->andWhere('o.' . $dateType . ' <= :dateTo')
->setParameter('dateTo', $dateTo);
}

$orders = $orders
->setMaxResults(100)
->orderBy('o.deadline', 'ASC')
->getQuery()
->getResult();
->getQuery();

return $orders;
return $orders->getResult();
}

/**
Expand Down Expand Up @@ -132,14 +134,19 @@ public function filters(): Response
if ($form->isSubmitted() && $form->isValid()) {
$preferences = $user->getPreferences();
$preferences['archives'] = $form->getData();
$preferences['archives']['select-staff'] = $preferences['archives']['select-staff'] ? $preferences['archives']['select-staff']->getId() : null;
$preferences['archives']['select-client'] = $preferences['archives']['select-client'] ? $preferences['archives']['select-client']->getId() : null;
$preferences['archives']['select-staff'] = $preferences['archives']['select-staff'] ?
$preferences['archives']['select-staff']->getId() : null;
$preferences['archives']['select-client'] = $preferences['archives']['select-client'] ?
$preferences['archives']['select-client']->getId() : null;
$user->setPreferences($preferences);
$this->entityManager->persist($user);
$this->entityManager->flush();
}

return new Response('<div class="alert alert-success">Zaktualizowano preferencje</div>', 200);
return new Response(
'<div class="alert alert-success">Zaktualizowano preferencje</div>',
200
);
}

/**
Expand All @@ -148,12 +155,18 @@ public function filters(): Response
public function restore(Order $order): Response
{
if (!$order->getDeletedAt()) {
return new Response("<div class='alert alert-danger'>Zlecenie nie jest usunięte</div>", 406);
return new Response(
"<div class='alert alert-danger'>Zlecenie nie jest usunięte</div>",
406
);
}
$order->setDeletedAt(null);
$this->entityManager->persist($order);
$this->entityManager->flush();

return new Response("<div class='alert alert-success'>Zlecenie zostało przywrócone.</div>", 200);
return new Response(
"<div class='alert alert-success'>Zlecenie zostało przywrócone.</div>",
200
);
}
}
26 changes: 15 additions & 11 deletions src/Controller/ClientsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
use App\Form\AddClientForm;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ClientsController extends AbstractController
{
private $entityManager;
private $request;
private ?Request $request;

public function __construct(EntityManagerInterface $entityManager, RequestStack $request)
{
$this->entityManager = $entityManager;
public function __construct(
private EntityManagerInterface $entityManager,
RequestStack $request
) {
$this->request = $request->getCurrentRequest();
}

Expand All @@ -35,14 +36,13 @@ public function index(): Response
private function loadClientsTable(): array
{
$repository = $this->entityManager->getRepository(Client::class);
$clients = $repository->createQueryBuilder('c');
$clients = $clients
$clients = $repository
->createQueryBuilder('c')
->andWhere('c.deletedAt is null')
->orderBy('c.alias', 'ASC')
->getQuery()
->getResult();
->getQuery();

return $clients;
return $clients->getResult();
}

/**
Expand Down Expand Up @@ -104,7 +104,11 @@ public function addClient(): Response
*/
public function details(Client $client): Response
{
$logs = $this->entityManager->getRepository(Log::class)->findBy(['client' => $client], ['createdAt' => 'DESC'], 100);
$logs = $this->entityManager->getRepository(Log::class)->findBy(
['client' => $client],
['createdAt' => 'DESC'],
100
);

return $this->render('clients/details.twig', [
'client' => $client,
Expand Down
Loading

0 comments on commit 39659a8

Please sign in to comment.