Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Up - 2.2.x into 2.3.x #822

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ parameters:
count: 1
path: src/ClientBundle/Form/ConstraintBuilder.php

-
message: "#^Class SolidInvoice\\\\ClientBundle\\\\Form\\\\DataTransformer\\\\ContactTypeTransformer implements generic interface Symfony\\\\Component\\\\Form\\\\DataTransformerInterface but does not specify its types\\: T, R$#"
count: 1
path: src/ClientBundle/Form/DataTransformer/ContactTypeTransformer.php

-
message: "#^Parameter \\#2 \\$default of method SolidWorx\\\\FormHandler\\\\Options\\:\\:get\\(\\) expects null, SolidInvoice\\\\ClientBundle\\\\Entity\\\\Client given\\.$#"
count: 1
Expand All @@ -120,11 +115,6 @@ parameters:
count: 1
path: src/ClientBundle/Form/Handler/AbstractContactFormHandler.php

-
message: "#^Class SolidInvoice\\\\ClientBundle\\\\Form\\\\ViewTransformer\\\\ContactTypeTransformer implements generic interface Symfony\\\\Component\\\\Form\\\\DataTransformerInterface but does not specify its types\\: T, R$#"
count: 1
path: src/ClientBundle/Form/ViewTransformer/ContactTypeTransformer.php

-
message: "#^Class SolidInvoice\\\\ClientBundle\\\\Repository\\\\ContactRepository extends generic class Doctrine\\\\Bundle\\\\DoctrineBundle\\\\Repository\\\\ServiceEntityRepository but does not specify its types\\: TEntityClass$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/ClientBundle/Form/Type/ContactDetailType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace SolidInvoice\ClientBundle\Form\Type;

use SolidInvoice\ClientBundle\Form\DataTransformer\ContactTypeTransformer;
use SolidInvoice\ClientBundle\Repository\ContactTypeRepository;
use SolidInvoice\CoreBundle\Form\DataTransformer\EntityUuidTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
]
)
->addModelTransformer(new ContactTypeTransformer($this->contactTypeRepository->findAll()))
->addModelTransformer(new EntityUuidTransformer($this->contactTypeRepository->findAll()))
);

$builder->add(
Expand Down
42 changes: 0 additions & 42 deletions src/ClientBundle/Form/ViewTransformer/ContactTypeTransformer.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,46 @@
* with this source code in the file LICENSE.
*/

namespace SolidInvoice\ClientBundle\Form\DataTransformer;
namespace SolidInvoice\CoreBundle\Form\DataTransformer;

use Ramsey\Uuid\UuidInterface;
use SolidInvoice\ClientBundle\Entity\ContactType;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use function method_exists;

class ContactTypeTransformer implements DataTransformerInterface
/**
* @implements DataTransformerInterface<int, object|string>
*/
final class EntityUuidTransformer implements DataTransformerInterface
{
/**
* @param ContactType[] $types
* @param object[] $types
*/
public function __construct(
private readonly array $types
) {
}

/**
* @param ?ContactType $type
* @param ?object $value
*/
public function transform($type): ?UuidInterface
public function transform($value): ?UuidInterface
{
if ($type instanceof ContactType) {
return $type->getId();
if (is_object($value) && method_exists($value, 'getId')) {
return $value->getId();

Check warning on line 40 in src/CoreBundle/Form/DataTransformer/EntityUuidTransformer.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Form/DataTransformer/EntityUuidTransformer.php#L40

Added line #L40 was not covered by tests
}

return null;
}

/**
* @param string $value
* @param object|string $value
*
* @return ContactType
* @return object
*
* @throws TransformationFailedException
*/
public function reverseTransform($value): ?ContactType
public function reverseTransform($value): ?object
{
if ('' === $value) {
return null;
Expand All @@ -59,6 +62,6 @@
}
}

throw new TransformationFailedException('Invalid contact type');
throw new TransformationFailedException('Invalid value');

Check warning on line 65 in src/CoreBundle/Form/DataTransformer/EntityUuidTransformer.php

View check run for this annotation

Codecov / codecov/patch

src/CoreBundle/Form/DataTransformer/EntityUuidTransformer.php#L65

Added line #L65 was not covered by tests
}
}
3 changes: 0 additions & 3 deletions src/CoreBundle/Form/Transformer/UserToContactTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ public function reverseTransform($value)
$contact->setContact($item);
if ($this->entity instanceof Invoice) {
$contact->setInvoice($this->entity);
break;
}
if ($this->entity instanceof RecurringInvoice) {
$contact->setRecurringInvoice($this->entity);
break;
}
if ($this->entity instanceof Quote) {
$contact->setQuote($this->entity);
break;
}

$users[] = $contact;
Expand Down
5 changes: 1 addition & 4 deletions src/CoreBundle/Form/Type/Select2Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function getParent(): string
return ChoiceType::class;
}

/**
* @return string
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'select2';
}
Expand Down
22 changes: 9 additions & 13 deletions src/CoreBundle/Resources/views/Form/fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
{% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
{%- endblock widget_attributes %}

{% block form_widget_simple -%}{{ parent() }}{% if help is defined and help is not empty %}<span class="help-{{ help_type }}"><small>{{ help|trans|nl2br }}</small></span>{% endif %}{%- endblock form_widget_simple %}

{% block form_row -%}
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
{{ form_label(form) }}
{{ form_widget(form) }}
{#{% if help is defined and help is not empty %}
<span class="help-{{ help_type }}"><small>{{ help|trans|nl2br }}</small></span>
{% endif %}#}
</div>
{%- endblock form_row %}
{% block form_help -%}
{%- if help is not empty -%}
<div class="alert alert-info mt-2">
{{ parent()|replace({'text-muted': ''})|raw }}
</div>
{%- endif -%}
{%- endblock form_help %}

{% block checkbox_widget -%}
{{ parent() }}
Expand Down Expand Up @@ -75,7 +71,7 @@
{% include "@SolidInvoiceClient/Form/contacts.html.twig" %}
{% endblock contact_widget %}

{% block tax_field_widget -%}
{#{% block tax_field_widget -%}
{% if expanded %}
{{- block('choice_widget_expanded') -}}
{% else %}
Expand All @@ -98,7 +94,7 @@
{{ block('tax_choice_widget_options') }}
</select>
{% endif %}
{%- endblock %}
{%- endblock %}#}

{% block tax_number_widget -%}
<div class="input-group">
Expand Down
4 changes: 2 additions & 2 deletions src/InvoiceBundle/Form/Type/ItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'tax',
TaxEntityType::class,
[
'class' => Tax::class,
'placeholder' => 'No Tax',
'attr' => [
'class' => 'select2 input-mini invoice-item-tax',
Expand All @@ -92,7 +91,8 @@ public function getBlockPrefix(): string

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('data_class', Item::class)
$resolver
->setDefault('data_class', Item::class)
->setRequired('currency')
->setAllowedTypes('currency', [Currency::class]);
}
Expand Down
42 changes: 33 additions & 9 deletions src/TaxBundle/Form/Type/TaxEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,47 @@

namespace SolidInvoice\TaxBundle\Form\Type;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use SolidInvoice\CoreBundle\Form\DataTransformer\EntityUuidTransformer;
use SolidInvoice\TaxBundle\Entity\Tax;
use SolidInvoice\TaxBundle\Repository\TaxRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use function array_combine;

class TaxEntityType extends AbstractType
final class TaxEntityType extends AbstractType
{
public function getParent(): string
private TaxRepository $repository;

public function __construct(TaxRepository $repository)
{
return EntityType::class;
$this->repository = $repository;
}

/**
* Returns the name of this type.
*
* @return string The name of this type
* @param array<string, mixed> $options
*/
public function getBlockPrefix()
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addModelTransformer(new EntityUuidTransformer($this->repository->findAll()));
}

public function configureOptions(OptionsResolver $resolver): void
{
$values = $this->repository->findAll();

$resolver->setDefault(
'choices',
array_combine(
$values,

Check failure on line 49 in src/TaxBundle/Form/Type/TaxEntityType.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $keys of function array_combine expects array<int|string>, array<int, object> given.
array_map(static fn (Tax $tax) => $tax->getId()->toString(), $values),
)
);
}

public function getParent(): string
{
return 'tax_field';
return ChoiceType::class;
}
}
1 change: 1 addition & 0 deletions src/TaxBundle/Form/Type/TaxType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
[
'choices' => array_map('ucwords', Tax::getTypes()),
'help' => 'tax.rates.explanation',
'help_html' => true,
'placeholder' => 'tax.rates.type.select',
]
);
Expand Down
13 changes: 1 addition & 12 deletions src/TaxBundle/Repository/TaxRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@ public function getTaxList(): array

public function taxRatesConfigured(): bool
{
return $this->getTotal() > 0;
}

/**
* Gets an array of all the available tax rates.
*/
public function getTotal(): int
{
$queryBuilder = $this->createQueryBuilder('t')
->select('COUNT(t.id)');

return (int) $queryBuilder->getQuery()->getSingleScalarResult();
return $this->count([]) > 0;
}

public function getGridQuery(): QueryBuilder
Expand Down
9 changes: 9 additions & 0 deletions src/TaxBundle/Resources/config/services/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:

_defaults:
public: false
autowire: true
autoconfigure: true

SolidInvoice\TaxBundle\Repository\TaxRepository: ~
SolidInvoice\TaxBundle\Form\Type\TaxEntityType: ~
4 changes: 3 additions & 1 deletion src/TaxBundle/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ tax:
title: 'Tax Rates'
add: 'Add Tax Rate'
save: Save
explanation: "Inclusive: Tax is included in the item price\nExclusive: Tax is calculated on the item price"
explanation: |
<b>Inclusive</b>: The Tax is already included in the item price<br />
<b>Exclusive</b>: Tax is calculated on top of the item price
type:
select: Select
inclusive: Inclusive
Expand Down
Loading