-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrea Pollastri
committed
Nov 13, 2023
1 parent
a0416d3
commit 8c16121
Showing
27 changed files
with
393 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
$header = <<<'EOF' | ||
This file is part of PHP CS Fixer. | ||
(c) Fabien Potencier <[email protected]> | ||
Dariusz Rumiński <[email protected]> | ||
This source file is subject to the MIT license that is bundled | ||
with this source code in the file LICENSE. | ||
EOF; | ||
|
||
$finder = (new PhpCsFixer\Finder()) | ||
->ignoreDotFiles(false) | ||
->ignoreVCSIgnored(true) | ||
->exclude(['dev-tools/phpstan', 'tests/Fixtures']) | ||
->in(__DIR__); | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PHP74Migration' => true, | ||
'@PHP74Migration:risky' => true, | ||
'@PHPUnit100Migration:risky' => true, | ||
'@PhpCsFixer' => true, | ||
'@PhpCsFixer:risky' => true, | ||
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead | ||
'header_comment' => ['header' => $header], | ||
'modernize_strpos' => true, // needs PHP 8+ or polyfill | ||
'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat | ||
]) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Abstracts; | ||
|
||
use Axiostudio\FatturaElettronica\Contracts\Model as ModelInterface; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Contracts; | ||
|
||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica; | ||
|
||
use Axiostudio\FatturaElettronica\Handlers\Model as ModelHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\Xml as XmlHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\XmlDatiBeniServizi as DatiBeniServiziHandler; | ||
use Axiostudio\FatturaElettronica\Handlers\Model as ModelHandler; | ||
use Axiostudio\FatturaElettronica\Models\FatturaElettronica as Fattura; | ||
|
||
class FatturaElettronica | ||
{ | ||
use DatiBeniServiziHandler; | ||
use ModelHandler; | ||
use XmlHandler; | ||
use DatiBeniServiziHandler; | ||
|
||
public function compose( | ||
array $FatturaElettronicaHeader, | ||
array $FatturaElettronicaBody, | ||
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
return $this->create( | ||
$FatturaElettronicaHeader, | ||
$FatturaElettronicaBody, | ||
$DettaglioLinee, | ||
$DatiRiepilogo | ||
); | ||
} | ||
|
||
protected function fileName($header): string | ||
{ | ||
$idPaese = (is_array($header[0][0]) && isset($header[0][0][1])) ? $header[0][0][1] : Settings::IdPaeseDefault(); | ||
$idCodice = (is_array($header[0][0])) ? $header[0][0][0] : $header[0][0]; | ||
$idPaese = (\is_array($header[0][0]) && isset($header[0][0][1])) ? $header[0][0][1] : Settings::IdPaeseDefault(); | ||
$idCodice = (\is_array($header[0][0])) ? $header[0][0][0] : $header[0][0]; | ||
$progressivoInvio = $header[0][1]; | ||
|
||
return $idPaese . $idCodice . '_' . $progressivoInvio . '.xml'; | ||
return $idPaese.$idCodice.'_'.$progressivoInvio.'.xml'; | ||
} | ||
|
||
protected function fileContent($header, $body): string | ||
|
@@ -35,27 +61,12 @@ protected function create( | |
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
|
||
$xmlContent = $this->fileContent($FatturaElettronicaHeader, $FatturaElettronicaBody); | ||
$xmlContent = $this->addDatiBeniServiziToXml($xmlContent, $DettaglioLinee, $DatiRiepilogo); | ||
|
||
return [ | ||
'fileContent' => $xmlContent, | ||
'fileName' => $this->fileName($FatturaElettronicaHeader) | ||
'fileName' => $this->fileName($FatturaElettronicaHeader), | ||
]; | ||
} | ||
|
||
public function compose( | ||
array $FatturaElettronicaHeader, | ||
array $FatturaElettronicaBody, | ||
array $DettaglioLinee, | ||
array $DatiRiepilogo | ||
): array { | ||
return $this->create( | ||
$FatturaElettronicaHeader, | ||
$FatturaElettronicaBody, | ||
$DettaglioLinee, | ||
$DatiRiepilogo | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Symfony\Component\Validator\Validation; | ||
use Axiostudio\FatturaElettronica\Contracts\Model as ModelInterface; | ||
use Symfony\Component\Validator\Validation; | ||
|
||
trait Model | ||
{ | ||
public function createModel(ModelInterface $model, bool $toArray = false): array|ModelInterface | ||
{ | ||
$validator = Validation::createValidatorBuilder() | ||
->addMethodMapping('loadValidatorMetadata') | ||
->getValidator(); | ||
->getValidator() | ||
; | ||
|
||
$errors = $validator->validate($model); | ||
|
||
if (count($errors) > 0) { | ||
if (\count($errors) > 0) { | ||
$errorsString = (string) $errors; | ||
|
||
throw new \Exception($errorsString); | ||
} | ||
|
||
|
@@ -31,4 +45,4 @@ protected function modelToArray(ModelInterface $model): array | |
{ | ||
return json_decode(json_encode($model), true); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Spatie\ArrayToXml\ArrayToXml; | ||
use Axiostudio\FatturaElettronica\Settings; | ||
use Spatie\ArrayToXml\ArrayToXml; | ||
|
||
trait Xml | ||
{ | ||
|
@@ -14,28 +26,26 @@ public function createXml(array $array): string | |
return $this->updateXml($xml); | ||
} | ||
|
||
protected function updateXml(string $xml): string | ||
public function createXmlBlock(array $array): string | ||
{ | ||
$xml = str_replace('<?xml version="1.0"?>', Settings::XmlStart(), $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
$xml = str_replace('</root>', Settings::XmlEnd(), $xml); | ||
$xml = ArrayToXml::convert($array); | ||
|
||
return $xml; | ||
return $this->updateXmlBlock($xml); | ||
} | ||
|
||
public function createXmlBlock(array $array): string | ||
protected function updateXml(string $xml): string | ||
{ | ||
$xml = ArrayToXml::convert($array); | ||
$xml = str_replace('<?xml version="1.0"?>', Settings::XmlStart(), $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
|
||
return $this->updateXmlBlock($xml); | ||
return str_replace('</root>', Settings::XmlEnd(), $xml); | ||
} | ||
|
||
protected function updateXmlBlock(string $xml): string | ||
{ | ||
$xml = str_replace('<?xml version="1.0"?>', '', $xml); | ||
$xml = str_replace('<root>', '', $xml); | ||
$xml = str_replace('</root>', '', $xml); | ||
|
||
return $xml; | ||
return str_replace('</root>', '', $xml); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Handlers; | ||
|
||
use Axiostudio\FatturaElettronica\Handlers\Xml; | ||
use Axiostudio\FatturaElettronica\Handlers\Model; | ||
use Axiostudio\FatturaElettronica\Models\DatiRiepilogo; | ||
use Axiostudio\FatturaElettronica\Models\DettaglioLinee; | ||
|
||
trait XmlDatiBeniServizi | ||
{ | ||
use Xml; | ||
use Model; | ||
use Xml; | ||
|
||
public function addDatiBeniServiziToXml(string $Xml, array $DettaglioLinee = [], array $DatiRiepilogo = []): string | ||
{ | ||
|
@@ -19,18 +29,16 @@ public function addDatiBeniServiziToXml(string $Xml, array $DettaglioLinee = [], | |
foreach ($DettaglioLinee as $numero => $linea) { | ||
$data = $this->createModel(new DettaglioLinee(...$linea), true); | ||
$data['NumeroLinea'] = $numero + 1; | ||
$DettaglioLineeBlock .= '<DettaglioLinee>' . $this->createXmlBlock($data) . '</DettaglioLinee>'; | ||
$DettaglioLineeBlock .= '<DettaglioLinee>'.$this->createXmlBlock($data).'</DettaglioLinee>'; | ||
} | ||
|
||
$DatiRiepilogoBlock = ''; | ||
|
||
foreach ($DatiRiepilogo as $dato) { | ||
$data = $this->createModel(new DatiRiepilogo(...$dato), true); | ||
$DatiRiepilogoBlock .= '<DatiRiepilogo>' . $this->createXmlBlock($data) . '</DatiRiepilogo>'; | ||
$DatiRiepilogoBlock .= '<DatiRiepilogo>'.$this->createXmlBlock($data).'</DatiRiepilogo>'; | ||
} | ||
|
||
$xml = str_replace('<XmlDatiBeniServizi></XmlDatiBeniServizi>', $DettaglioLineeBlock . $DatiRiepilogoBlock, $Xml); | ||
|
||
return $xml; | ||
return str_replace('<XmlDatiBeniServizi></XmlDatiBeniServizi>', $DettaglioLineeBlock.$DatiRiepilogoBlock, $Xml); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Axiostudio\FatturaElettronica\Models; | ||
|
||
use Axiostudio\FatturaElettronica\Abstracts\Model; | ||
|
@@ -26,8 +38,5 @@ public function __construct(...$args) | |
} | ||
} | ||
|
||
public static function loadValidatorMetadata(ClassMetadata $metadata): void | ||
{ | ||
// | ||
} | ||
public static function loadValidatorMetadata(ClassMetadata $metadata): void {} | ||
} |
Oops, something went wrong.