Skip to content

Commit

Permalink
ci: init
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriolino committed Nov 8, 2024
1 parent 39a5b49 commit de02f11
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 27 deletions.
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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

<!--
- Please fill in this template according to your issue.
- Replace this comment by the description of your issue.
-->
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/[email protected]
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
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":[],"times":[]}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
},
Expand Down
23 changes: 23 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<config name="installed_paths" value="../../slevomat/coding-standard"/>

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR12"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true" />
</properties>
</rule>

<file>src/</file>
<file>tests/</file>

</ruleset>
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 6
paths:
- src/
- tests/
31 changes: 31 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
convertDeprecationsToExceptions="false"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<extensions>
</extensions>
</phpunit>
30 changes: 15 additions & 15 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function index(
/** @var UsuarioInterface */
$usuario = $this->getUser();
$unidade = $usuario->getLotacao()->getUnidade();

$qb = $repository
->createQueryBuilder('e')
->select('e', 'c')
Expand All @@ -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'));
Expand All @@ -86,7 +86,7 @@ public function index(
$pagerfanta = new Pagerfanta($adapter);

$pagerfanta->setCurrentPage($currentPage);

$path = $this->generateUrl('novosga_scheduling_index');
$html = $view->render(
$pagerfanta,
Expand All @@ -113,7 +113,7 @@ function ($page) use ($request, $path) {
);

$agendamentos = $pagerfanta->getCurrentPageResults();

return $this->render('@NovosgaScheduling/default/index.html.twig', [
'agendamentos' => $agendamentos,
'paginacao' => $html,
Expand Down Expand Up @@ -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');
}
Expand All @@ -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(
Expand All @@ -184,15 +184,15 @@ private function form(
NovosgaSchedulingBundle::getDomain(),
)
);

return $this->redirectToRoute('novosga_scheduling_edit', [
'id' => $entity->getId(),
]);
} catch (Exception $e) {
$this->addFlash('error', $e->getMessage());
}
}

return $this->render('@NovosgaScheduling/default/form.html.twig', [
'entity' => $entity,
'form' => $form,
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/NovosgaSchedulingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
14 changes: 3 additions & 11 deletions src/Form/AgendamentoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit de02f11

Please sign in to comment.