<commit_before><?php
namespace CfdiUtils\TimbreFiscalDigital;

use CfdiUtils\Nodes\NodeInterface;
use CfdiUtils\Utils\Xml;
use DOMDocument;
use DOMElement;

class TfdVersion
{
    public static function fromDOMElement(DOMElement $element): string
    {
        return self::evaluate($element->getAttribute('version'), $element->getAttribute('Version'));
    }

    public static function fromDOMDocument(DOMDocument $document): string
    {
        return static::fromDOMElement($document->documentElement);
    }

    public static function fromNode(NodeInterface $node): string
    {
        return self::evaluate($node['version'], $node['Version']);
    }

    public static function fromXmlString(string $contents): string
    {
        $document = Xml::newDocumentContent($contents);
        return static::fromDOMDocument($document);
    }

    private static function evaluate(string $v10, string $v11): string
    {
        if ('1.1' === $v11) {
            return '1.1';
        }
        if ('1.0' === $v10) {
            return '1.0';
        }
        return '';
    }
}<commit_msg>Use same logic in TfdVersion as CfdiVersion<commit_after><?php
namespace CfdiUtils\TimbreFiscalDigital;

use CfdiUtils\VersionDiscovery\StaticMethodsCompatTrait;
use CfdiUtils\VersionDiscovery\VersionDiscoverer;

/**
 * This class provides static methods to retrieve the version attribute from a
 * Timbre Fiscal Digital (TFD)
 *
 * It will not check anything but the value of the correct attribute
 * It will not care if the cfdi is following an schema or element's name
 *
 * Possible values are always 1.0, 1.1 or empty string
 */
class TfdVersion extends VersionDiscoverer
{
    use StaticMethodsCompatTrait;

    protected static function createDiscoverer(): VersionDiscoverer
    {
        return new self();
    }

    public function rules(): array
    {
        return [
            '1.1' => 'Version',
            '1.0' => 'version',
        ];
    }
}
{'fraction_non_alphanumeric': 0.10531697341513292, 'fraction_numerical': 0.012269938650306749, 'mean_word_length': 3.128691983122363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1555258', 'n_tokens_mistral': 569, 'n_tokens_neox': 538, 'n_words': 155}