<commit_before><?php

namespace GeoIO\WKB\Parser;

use GeoIO\Dimension;
use GeoIO\Factory;
use GeoIO\WKB\Parser\Exception\ParserException;

class Parser
{
    const MASK_SRID = 0x20000000;
    const MASK_Z = 0x80000000;
    const MASK_M = 0x40000000;

    const TYPE_POINT = 1;
    const TYPE_LINESTRING = 2;
    const TYPE_POLYGON = 3;
    const TYPE_MULTIPOINT = 4;
    const TYPE_MULTILINESTRING = 5;
    const TYPE_MULTIPOLYGON = 6;
    const TYPE_GEOMETRYCOLLECTION = 7;

    private $scanner;

    private $factory;

    private $dimension;
    private $srid;
    private $litteEndian;

    public function __construct(Factory $factory)
    {
        $this->factory = $factory;
    }

    public function parse($str)
    {
        try {
            $this->scanner = new Scanner($str);

            return $this->doParse();
        } catch (\Exception $e) {
            throw new ParserException(sprintf('Parsing failed: %s', $e->getMessage()), 0, $e);
        }
    }

    protected function doParse($expectedType = null)
    {
        $this->endian();

        $type = $this->scanner->integer($this->litteEndian);

        $srid = null;
        $hasZ = false;
        $hasM = false;

        if ($type & self::MASK_SRID) {
            $srid = $this->scanner->integer($this->litteEndian);
            $type = ($type & ~self::MASK_SRID);
        }

        if ($type & self::MASK_Z) {
            $hasZ = true;
            $type = ($type & ~self::MASK_Z);
        }

        if ($type & self::MASK_M) {
            $hasM = true;
            $type = ($type & ~self::MASK_M);
        }

        $wkb12 = false;

        if (($type / 1000) & 1) {
            $hasZ = true;
            $wkb12 = true;
        }

        if (($type / 1000) & 2) {
            $hasM = true;
            $wkb12 = true;
        }<commit_msg>Cast to int to avoid deprecation warning on PHP 8.1<commit_after><?php

namespace GeoIO\WKB\Parser;

use GeoIO\Dimension;
use GeoIO\Factory;
use GeoIO\WKB\Parser\Exception\ParserException;

class Parser
{
    const MASK_SRID = 0x20000000;
    const MASK_Z = 0x80000000;
    const MASK_M = 0x40000000;

    const TYPE_POINT = 1;
    const TYPE_LINESTRING = 2;
    const TYPE_POLYGON = 3;
    const TYPE_MULTIPOINT = 4;
    const TYPE_MULTILINESTRING = 5;
    const TYPE_MULTIPOLYGON = 6;
    const TYPE_GEOMETRYCOLLECTION = 7;

    private $scanner;

    private $factory;

    private $dimension;
    private $srid;
    private $litteEndian;

    public function __construct(Factory $factory)
    {
        $this->factory = $factory;
    }

    public function parse($str)
    {
        try {
            $this->scanner = new Scanner($str);

            return $this->doParse();
        } catch (\Exception $e) {
            throw new ParserException(sprintf('Parsing failed: %s', $e->getMessage()), 0, $e);
        }
    }

    protected function doParse($expectedType = null)
    {
        $this->endian();

        $type = $this->scanner->integer($this->litteEndian);

        $srid = null;
        $hasZ = false;
        $hasM = false;

        if ($type & self::MASK_SRID) {
            $srid = $this->scanner->integer($this->litteEndian);
            $type = ($type & ~self::MASK_SRID);
        }

        if ($type & self::MASK_Z) {
            $hasZ = true;
            $type = ($type & ~self::MASK_Z);
        }

        if ($type & self::MASK_M) {
            $hasM = true;
            $type = ($type & ~self::MASK_M);
        }

        $wkb12 = false;

        if (((int) ($type / 1000)) & 1) {
            $hasZ = true;
            $wkb12 = true;
        }

        if (((int) ($type / 1000)) & 2) {
            $hasM = true;
            $wkb12 = true;
        }
{'fraction_non_alphanumeric': 0.13392857142857142, 'fraction_numerical': 0.02813852813852814, 'mean_word_length': 1.8681148176881304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '4461649', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1219, 'n_words': 275}