-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from eclipxe13/version-1.3.0
Agregar la opción para excluir limpiadores específicos (v1.3.0)
- Loading branch information
Showing
13 changed files
with
261 additions
and
23 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\CfdiCleaner; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use Traversable; | ||
|
||
/** | ||
* Class to specify the cleaner class names to be excluded | ||
* @see Cleaner::exclude() | ||
* @implements IteratorAggregate<int, class-string> | ||
*/ | ||
final class ExcludeList implements IteratorAggregate | ||
{ | ||
/** @var list<class-string> */ | ||
private $classNames; | ||
|
||
/** @param class-string ...$classNames */ | ||
public function __construct(string ...$classNames) | ||
{ | ||
$this->classNames = array_values($classNames); | ||
} | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return [] === $this->classNames; | ||
} | ||
|
||
public function match(object $object): bool | ||
{ | ||
foreach ($this->classNames as $className) { | ||
if ($object instanceof $className) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @template TObject of object | ||
* @param TObject ...$objects | ||
* @return array<TObject> | ||
*/ | ||
public function filterObjects(object ...$objects): array | ||
{ | ||
return array_filter( | ||
$objects, | ||
function (object $object): bool { | ||
return ! $this->match($object); | ||
} | ||
); | ||
} | ||
|
||
/** @return Traversable<int, class-string> */ | ||
public function getIterator(): Traversable | ||
{ | ||
return new ArrayIterator($this->classNames); | ||
} | ||
} |
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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\CfdiCleaner\Tests\Features; | ||
|
||
use PhpCfdi\CfdiCleaner\Cleaner; | ||
use PhpCfdi\CfdiCleaner\ExcludeList; | ||
use PhpCfdi\CfdiCleaner\Tests\TestCase; | ||
use PhpCfdi\CfdiCleaner\XmlDocumentCleaners\MoveNamespaceDeclarationToRoot; | ||
use PhpCfdi\CfdiCleaner\XmlDocumentCleaners\RemoveAddenda; | ||
use PhpCfdi\CfdiCleaner\XmlDocumentCleaners\RemoveNonSatNamespacesNodes; | ||
use PhpCfdi\CfdiCleaner\XmlDocumentCleaners\RemoveNonSatSchemaLocations; | ||
|
||
final class CleanerExcludeTest extends TestCase | ||
{ | ||
public function testCleanerExcludeAddenda(): void | ||
{ | ||
$xml = /** @lang text */ <<<XML | ||
<?xml version="1.0"?> | ||
<cfdi:Comprobante xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:cfdi="http://www.sat.gob.mx/cfd/4" | ||
xsi:schemaLocation="http://www.sat.gob.mx/cfd/4 http://www.sat.gob.mx/sitio_internet/cfd/4/cfdv40.xsd" | ||
Version="4.0"> | ||
<cfdi:Addenda> | ||
<foo:Main xmlns:foo="urn:foo" id="1" /> | ||
</cfdi:Addenda> | ||
</cfdi:Comprobante> | ||
XML; | ||
|
||
$excludeList = new ExcludeList( | ||
RemoveAddenda::class, | ||
RemoveNonSatNamespacesNodes::class, | ||
RemoveNonSatSchemaLocations::class, | ||
MoveNamespaceDeclarationToRoot::class | ||
); | ||
|
||
$cleaner = new Cleaner(); | ||
$cleaner->exclude($excludeList); | ||
|
||
$xmlClean = $cleaner->cleanStringToString($xml); | ||
|
||
$this->assertXmlStringEqualsXmlString($xml, $xmlClean); | ||
} | ||
} |
Oops, something went wrong.