Skip to content

Commit

Permalink
Merge pull request #112 from eclipxe13/development
Browse files Browse the repository at this point in the history
Calculator for Pagos 2.0 and code style
  • Loading branch information
eclipxe13 committed Jul 15, 2023
2 parents 861ee81 + e0dfaa8 commit c8dacc2
Show file tree
Hide file tree
Showing 60 changed files with 305 additions and 175 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
env:
fail-fast: true
- name: Code style (phpcs)
run: phpcs -q --report=checkstyle src/ tests/ | cs2pr
run: phpcs -q --report=checkstyle | cs2pr

php-cs-fixer:
name: Code style (php-cs-fixer)
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
composer remove squizlabs/php_codesniffer friendsofphp/php-cs-fixer phpstan/phpstan --dev --no-interaction --no-progress --no-update
composer upgrade --no-interaction --no-progress --prefer-dist
- name: PHPStan
run: phpstan analyse --no-progress --verbose src/ tests/
run: phpstan analyse --no-progress --verbose

tests-linux:
name: Test PHP ${{ matrix.php-versions }} on Linux
Expand Down
41 changes: 23 additions & 18 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
<?php

/**
* @noinspection PhpUndefinedClassInspection
* @noinspection PhpUndefinedNamespaceInspection
* @see https://cs.symfony.com/doc/ruleSets/
* @see https://cs.symfony.com/doc/rules/
*/

declare(strict_types=1);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/build/.php_cs.cache')
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache')
->setRules([
'@PSR2' => true,
'@PHP70Migration' => true,
// '@PHP70Migration:risky' => true,
'@PSR12' => true,
// '@PSR12:risky' => true,
// '@PHP71Migration:risky' => true,
'@PHP73Migration' => true,
// symfony
'class_attributes_separation' => true,
'whitespace_after_comma_in_array' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'function_typehint_space' => true,
'no_alias_functions' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'new_with_braces' => true,
'no_blank_lines_after_class_opening' => true,
'type_declaration_spaces' => true,
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays']],
'no_blank_lines_after_phpdoc' => true,
'object_operator_without_whitespace' => true,
'binary_operator_spaces' => true,
'phpdoc_scalar' => true,
'self_accessor' => true,
'no_trailing_comma_in_singleline' => true,
'single_quote' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'yoda_style' => ['equal' => true, 'identical' => true, 'less_and_greater' => null],
'standardize_not_equals' => true,
// contrib
'concat_space' => ['spacing' => 'one'],
'not_operator_with_successor_space' => true,
'blank_lines_before_namespace' => true,
'linebreak_after_opening_tag' => true,
'blank_line_after_opening_tag' => true,
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
'fully_qualified_strict_types' => true,
// symfony:risky
'no_alias_functions' => true,
'self_accessor' => true,
// contrib
'not_operator_with_successor_space' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], // @PSR12 sort_algorithm: none
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(['vendor', 'build'])
->append([__FILE__])
->exclude(['vendor', 'build']),
)
;
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
],
"dev:check-style": [
"@php vendor/bin/php-cs-fixer fix --dry-run --verbose",
"@php vendor/bin/phpcs --colors -sp src/ tests/"
"@php vendor/bin/phpcs --colors -sp"
],
"dev:fix-style": [
"@php vendor/bin/php-cs-fixer fix --verbose",
"@php vendor/bin/phpcbf --colors -sp src/ tests/"
"@php vendor/bin/phpcbf --colors -sp"
],
"dev:docs": [
"node_modules/markdownlint-cli/markdownlint.js *.md docs/",
Expand All @@ -83,7 +83,7 @@
"dev:test": [
"@dev:check-style",
"@php vendor/bin/phpunit --testdox --verbose --stop-on-failure",
"@php vendor/bin/phpstan analyse --no-progress src/ tests/"
"@php vendor/bin/phpstan analyse --no-progress"
],
"dev:coverage": [
"@php -dzend_extension=xdebug.so -dxdebug.mode=coverage vendor/bin/phpunit --coverage-html build/coverage/html/"
Expand Down
2 changes: 1 addition & 1 deletion development/bin/elements-maker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require __DIR__ . '/../../vendor/autoload.php';

exit(call_user_func(new class(...$argv) extends BaseCliApplication {
exit(call_user_func(new class (...$argv) extends BaseCliApplication {
public function printHelp(): void
{
$command = basename($this->getCommand());
Expand Down
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
- Merge methods from `\CfdiUtils\Nodes\NodeHasValueInterface` into `\CfdiUtils\Nodes\NodeInterface`.
- Remove deprecated constant `CfdiUtils\Retenciones\Retenciones::RET_NAMESPACE`.

## Version 2.24.1 2023-07-12

Fix calculator for complement *Pagos 2.0*.
For attributes `BaseP` and `ImporteP` the value was truncated. Now, the value has to be rounded.
Some vendors communicate this change, such as Finkok.

Improve calculator with new getter and setter for `paymentTaxesPrecision` and `currencies`.

Update code style as other PhpCfdi projects.

Set up PHPStan paths on configuration file.

## Maintenance 2023-06-19

The certificate for RFC `EKU9003173C9` expired and is replaced for a new one.
Expand Down
6 changes: 3 additions & 3 deletions docs/contribuir/guia-desarrollador.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ composer install
Para probar que no se están violando las reglas de estilo

```shell
vendor/bin/phpcs -sp --colors src/ tests/
vendor/bin/phpcs -sp --colors
vendor/bin/php-cs-fixer fix --using-cache=no --dry-run --verbose
```

Expand All @@ -57,7 +57,7 @@ vendor/bin/phpunit
También ejecutamos PHPStan sobre archivos de orígenes y pruebas

```shell
vendor/bin/phpstan analyse --level max src/ tests/
vendor/bin/phpstan analyse
```


Expand All @@ -67,7 +67,7 @@ Para corregir todos los problemas de estilo que encuentre

```shell
vendor/bin/php-cs-fixer fix --verbose
vendor/bin/phpcbf --colors -sp src/ tests/
vendor/bin/phpcbf --colors -sp
```


Expand Down
6 changes: 3 additions & 3 deletions docs/contribuir/guia-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ Para que puedas ejecutar los comandos que forman las pruebas del proyecto (lo "c

```shell
:: verificar que se están compliendo las reglas de estilo
vendor\bin\phpcs -sp src tests
vendor\bin\phpcs -sp
vendor\bin\php-cs-fixer fix --dry-run --verbose

:: hacer las correcciones de estilo de forma automática
vendor\bin\phpcbf -sp src tests
vendor\bin\phpcbf -sp
vendor\bin\php-cs-fixer fix --verbose


:: ejecutar las pruebas
vendor\bin\phpunit

:: ejecutar el analizador el analizador estático
vendor\bin\phpstan.bat --no-progress analyse --level max src tests
vendor\bin\phpstan.bat --no-progress analyse
```

Lamentablemente, no se puede ejecutar `composer dev:build` o alguno de los comandos personalizados
Expand Down
10 changes: 8 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version="1.0"?>
<ruleset name="EngineWorks">
<description>The EngineWorks (PSR-2 based) coding standard.</description>
<description>The EngineWorks (PSR-12 based) coding standard.</description>

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

<arg name="tab-width" value="4"/>
<arg name="encoding" value="utf-8"/>
<arg name="report-width" value="auto"/>
<arg name="extensions" value="php"/>
<rule ref="PSR2" />
<arg name="cache" value="build/phpcs.cache"/>

<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
parameters:
level: 5
inferPrivatePropertyTypeFromConstructor: true

paths:
- src/
- tests/
6 changes: 3 additions & 3 deletions src/CfdiUtils/CadenaOrigen/CfdiDefaultLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

class CfdiDefaultLocations
{
const XSLT_32 = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_2/cadenaoriginal_3_2.xslt';
public const XSLT_32 = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_2/cadenaoriginal_3_2.xslt';

const XSLT_33 = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt';
public const XSLT_33 = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt';

const XSLT_40 = 'http://www.sat.gob.mx/sitio_internet/cfd/4/cadenaoriginal_4_0/cadenaoriginal_4_0.xslt';
public const XSLT_40 = 'http://www.sat.gob.mx/sitio_internet/cfd/4/cadenaoriginal_4_0/cadenaoriginal_4_0.xslt';

public static function location(string $version): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/CfdiUtils/CfdiCreatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ private function cfdiCreatorConstructor(
XsltBuilderInterface $xsltBuilder = null
): void {
$this->comprobante->addAttributes($comprobanteAttributes);
$this->setXmlResolver($xmlResolver ? : new XmlResolver());
$this->setXmlResolver($xmlResolver ?: new XmlResolver());
if (null !== $certificado) {
$this->putCertificado($certificado);
}
$this->setXsltBuilder($xsltBuilder ? : new DOMBuilder());
$this->setXsltBuilder($xsltBuilder ?: new DOMBuilder());
}

public static function newUsingNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class RemoveDuplicatedCfdi3Namespace implements BeforeLoadCleanerInterface
{
public function clean(string $content): string
{
if (false !== strpos($content, ' xmlns="http://www.sat.gob.mx/cfd/3"')
&& false !== strpos($content, ' xmlns:cfdi="http://www.sat.gob.mx/cfd/3"')) {
if (
false !== strpos($content, ' xmlns="http://www.sat.gob.mx/cfd/3"')
&& false !== strpos($content, ' xmlns:cfdi="http://www.sat.gob.mx/cfd/3"')
) {
$content = str_replace(' xmlns="http://www.sat.gob.mx/cfd/3"', '', $content);
}
return $content;
Expand Down
6 changes: 3 additions & 3 deletions src/CfdiUtils/ConsultaCfdiSat/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config
* Default value of SAT web service
* @var string
*/
const DEFAULT_SERVICE_URL = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc';
public const DEFAULT_SERVICE_URL = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc';

/**
* This library does not use WSDL anymore
Expand All @@ -17,7 +17,7 @@ class Config
* @see self::DEFAULT_SERVICE_URL
* @var string
*/
const DEFAULT_WSDL_URL = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc?singleWsdl';
public const DEFAULT_WSDL_URL = self::DEFAULT_SERVICE_URL . '?singleWsdl';

/** @var int */
private $timeout;
Expand All @@ -39,7 +39,7 @@ public function __construct(
) {
$this->timeout = $timeout;
$this->verifyPeer = $verifyPeer;
$this->serviceUrl = $serviceUrl ? : static::DEFAULT_SERVICE_URL;
$this->serviceUrl = $serviceUrl ?: static::DEFAULT_SERVICE_URL;
$this->wsdlLocation = $wsdlLocation;
if ('' !== $this->wsdlLocation) {
trigger_error(__CLASS__ . ' deprecated WSDL location', E_USER_DEPRECATED);
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/ConsultaCfdiSat/WebService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WebService

public function __construct(Config $config = null)
{
$this->config = $config ? : new Config();
$this->config = $config ?: new Config();
}

public function getConfig(): Config
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/OpenSSL/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Caller
{
const DEFAULT_OPENSSL_EXECUTABLE = 'openssl';
public const DEFAULT_OPENSSL_EXECUTABLE = 'openssl';

/** @var string */
private $executable;
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/Retenciones/Retenciones.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Retenciones
* @deprecated :3.0.0
* @internal Preserve this constant to not break compatibility
*/
const RET_NAMESPACE = 'http://www.sat.gob.mx/esquemas/retencionpago/1';
public const RET_NAMESPACE = 'http://www.sat.gob.mx/esquemas/retencionpago/1';

/** @var array<string, string> Dictionary of versions and namespaces */
private const RET_SPECS = [
Expand Down
4 changes: 2 additions & 2 deletions src/CfdiUtils/Retenciones/RetencionesCreatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ private function retencionesCreatorConstructor(
XsltBuilderInterface $xsltBuilder = null
): void {
$this->retenciones->addAttributes($retencionesAttributes);
$this->setXmlResolver($xmlResolver ? : new XmlResolver());
$this->setXmlResolver($xmlResolver ?: new XmlResolver());
if (null !== $certificado) {
$this->putCertificado($certificado);
}
$this->setXsltBuilder($xsltBuilder ? : new DOMBuilder());
$this->setXsltBuilder($xsltBuilder ?: new DOMBuilder());
}

public function addSello(string $key, string $passPhrase = '')
Expand Down
9 changes: 6 additions & 3 deletions src/CfdiUtils/SumasConceptos/SumasConceptosWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ private function putComprobanteSumas(): void
$this->comprobante['SubTotal'] = $this->format($this->sumas->getSubTotal());
$this->comprobante['Total'] = $this->format($this->sumas->getTotal());
$this->comprobante['Descuento'] = $this->format($this->sumas->getDescuento());
if (! $this->sumas->foundAnyConceptWithDiscount()
&& ! $this->valueGreaterThanZero($this->sumas->getDescuento())) {
if (
! $this->sumas->foundAnyConceptWithDiscount()
&& ! $this->valueGreaterThanZero($this->sumas->getDescuento())
) {
unset($this->comprobante['Descuento']);
}
}
Expand All @@ -74,7 +76,8 @@ private function putImpuestosNode(): void
// obtain node reference
$impuestos = $this->comprobante->getImpuestos();
// if there is nothing to write then remove the children and exit
if (! $this->sumas->hasTraslados()
if (
! $this->sumas->hasTraslados()
&& ! $this->sumas->hasRetenciones()
&& ! ($this->writeExentos && $this->sumas->hasExentos())
) {
Expand Down

0 comments on commit c8dacc2

Please sign in to comment.