From de02f114668a4c43ae80c90336aaf991c937910d Mon Sep 17 00:00:00 2001 From: Rogerio Lino Date: Fri, 8 Nov 2024 10:02:59 -0300 Subject: [PATCH] ci: init --- .github/ISSUE_TEMPLATE.md | 13 ++++++++ .github/workflows/ci.yaml | 24 ++++++++++++++ .phpunit.result.cache | 1 + composer.json | 2 ++ phpcs.xml.dist | 23 ++++++++++++++ phpstan.neon | 5 +++ phpunit.xml.dist | 31 +++++++++++++++++++ src/Controller/DefaultController.php | 30 +++++++++--------- .../NovosgaSchedulingExtension.php | 2 +- src/Form/AgendamentoType.php | 14 ++------- 10 files changed, 118 insertions(+), 27 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/workflows/ci.yaml create mode 100644 .phpunit.result.cache create mode 100644 phpcs.xml.dist create mode 100644 phpstan.neon create mode 100644 phpunit.xml.dist diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..388ce13 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,13 @@ +| Q | A +| ---------------- | ----- +| Bug report? | yes/no +| Feature request? | yes/no +| Novo SGA version | x.y.z +| PHP version | x.y.z +| Database version | MySQL 5.7/PostgreSQL 15 +| Platform/OS | Linux/Windows + + diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..10f5bd2 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,24 @@ +name: CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@2.28.0 + with: + php-version: 8.2 + + - name: Install dependencies + run: composer install + + - name: PHP Code Standards + run: vendor/bin/phpcs + + - name: PHP Code Analysis + run: vendor/bin/phpstan + + - name: PHP Unit Tests + run: vendor/bin/phpunit diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..2de2a6d --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":[]} \ No newline at end of file diff --git a/composer.json b/composer.json index 786596b..91e3d59 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,8 @@ "php": ">=8.2", "doctrine/orm": "^3.2", "novosga/core": "2.2.x-dev", + "pagerfanta/doctrine-orm-adapter": "*", + "pagerfanta/pagerfanta": "^4.6", "symfony/framework-bundle": "7.1.*", "symfony/form": "7.1.*" }, diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..b545cee --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + src/ + tests/ + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..d268c2f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 6 + paths: + - src/ + - tests/ diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8a916fc --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + tests + + + + + + src + + + + + + diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 528ffb3..4948b24 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -47,7 +47,7 @@ public function index( /** @var UsuarioInterface */ $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); - + $qb = $repository ->createQueryBuilder('e') ->select('e', 'c') @@ -57,26 +57,26 @@ public function index( ->setParameter('unidade', $unidade) ->setParameter('situacao', $situacao) ->orderBy('e.data', 'DESC'); - + if (!empty($search)) { - $where = [ + $where = [ 'c.email LIKE :s', 'c.documento LIKE :s' ]; $qb->setParameter('s', "%{$search}%"); - + $tokens = explode(' ', $search); - + for ($i = 0; $i < count($tokens); $i++) { $value = $tokens[$i]; $v1 = "n{$i}"; $where[] = "(UPPER(c.nome) LIKE UPPER(:{$v1}))"; $qb->setParameter($v1, "{$value}%"); } - + $qb->andWhere(join(' OR ', $where)); } - + $query = $qb->getQuery(); $currentPage = max(1, (int) $request->get('p')); @@ -86,7 +86,7 @@ public function index( $pagerfanta = new Pagerfanta($adapter); $pagerfanta->setCurrentPage($currentPage); - + $path = $this->generateUrl('novosga_scheduling_index'); $html = $view->render( $pagerfanta, @@ -113,7 +113,7 @@ function ($page) use ($request, $path) { ); $agendamentos = $pagerfanta->getCurrentPageResults(); - + return $this->render('@NovosgaScheduling/default/index.html.twig', [ 'agendamentos' => $agendamentos, 'paginacao' => $html, @@ -145,12 +145,12 @@ public function edit( /** @var UsuarioInterface */ $usuario = $this->getUser(); $unidade = $usuario->getLotacao()->getUnidade(); - + $entity = $service->getById($id); if (!$entity) { throw $this->createNotFoundException(); } - + if ($entity->getUnidade() && $entity->getUnidade()->getId() !== $unidade->getId()) { return $this->redirectToRoute('novosga_scheduling_index'); } @@ -171,11 +171,11 @@ private function form( 'disabled' => $isDisabled, ]) ->handleRequest($request); - + if ($form->isSubmitted() && $form->isValid()) { try { $service->save($entity); - + $this->addFlash( 'success', $translator->trans( @@ -184,7 +184,7 @@ private function form( NovosgaSchedulingBundle::getDomain(), ) ); - + return $this->redirectToRoute('novosga_scheduling_edit', [ 'id' => $entity->getId(), ]); @@ -192,7 +192,7 @@ private function form( $this->addFlash('error', $e->getMessage()); } } - + return $this->render('@NovosgaScheduling/default/form.html.twig', [ 'entity' => $entity, 'form' => $form, diff --git a/src/DependencyInjection/NovosgaSchedulingExtension.php b/src/DependencyInjection/NovosgaSchedulingExtension.php index 9f80a15..655bd9e 100644 --- a/src/DependencyInjection/NovosgaSchedulingExtension.php +++ b/src/DependencyInjection/NovosgaSchedulingExtension.php @@ -28,7 +28,7 @@ class NovosgaSchedulingExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); } } diff --git a/src/Form/AgendamentoType.php b/src/Form/AgendamentoType.php index 3707d95..9f1e850 100644 --- a/src/Form/AgendamentoType.php +++ b/src/Form/AgendamentoType.php @@ -33,11 +33,7 @@ public function __construct( ) { } - /** - * @param FormBuilderInterface $builder - * @param array $options - */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('cliente', ClienteType::class, [ @@ -72,12 +68,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'label' => 'form.scheduling.time', ]); } - - /** - * - * @param OptionsResolver $resolver - */ - public function configureOptions(OptionsResolver $resolver) + + public function configureOptions(OptionsResolver $resolver): void { $resolver ->setDefaults([