Auto version select and Get Max Data Bits

@param $codewordNumPlus
@param $dataBitsTotal

@return int
514230
private function autoVersionAndGetMaxDataBits($codewordNumPlus, $dataBitsTotal)
    {
        $i          = 1 + 40 * $this->getEccCharacter();
        $j          = $i + 39;
        $version    = 1;

        while ($i <= $j) {
            $maxDataBits = $this->getMaxDataBitsByIndexFormArray($i);

            if ( ($maxDataBits) >= ($dataBitsTotal + $codewordNumPlus[$version]) ) {
                $this->setVersion($version);

                return $maxDataBits;
            }

            $i++; $version++;
        }

        return 0;
    }
337522
public static function decodeVersionInformation(int $versionBits) : ?self
    {
        $bestDifference = PHP_INT_MAX;
        $bestVersion = 0;

        foreach (self::VERSION_DECODE_INFO as $i => $targetVersion) {
            if ($targetVersion === $versionBits) {
                return self::getVersionForNumber($i + 7);
            }

            $bitsDifference = FormatInformation::numBitsDiffering($versionBits, $targetVersion);

            if ($bitsDifference < $bestDifference) {
                $bestVersion = $i + 7;
                $bestDifference = $bitsDifference;
            }
        }

        if ($bestDifference <= 3) {
            return self::getVersionForNumber($bestVersion);
        }

        return null;
    }
163861
public function estimateVersion()
    {
        $version = 0;
        $prev = 0;
        do {
            $prev = $version;
            $bits = $this->estimateBitStreamSize($prev);
            $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
            if ($version < 0) {
                return -1;
            }
        } while ($version > $prev);

        return $version;
    }
1279890
private function getLastUseEndPos(int $lastUsePos): int
    {
        $file = $this->getFile();
        $tokens = $file->getTokens();

        $lastUseEndPos = TokenHelper::findNextLocal(
            $file,
            [T_SEMICOLON, T_OPEN_CURLY_BRACKET],
            $lastUsePos + 1
        );

        if ($tokens[$lastUseEndPos]['code'] === T_OPEN_CURLY_BRACKET) {
            $lastUseEndPos = $tokens[$lastUseEndPos]['bracket_closer'];
        }

        return $lastUseEndPos;
    }
826300
static void makeVersionInfoBits(Version version, BitArray bits) throws WriterException {
    bits.appendBits(version.getVersionNumber(), 6);
    int bchCode = calculateBCHCode(version.getVersionNumber(), VERSION_INFO_POLY);
    bits.appendBits(bchCode, 12);

    if (bits.getSize() != 18) {  // Just in case.
      throw new WriterException("should not happen but we got: " + bits.getSize());
    }
  }
824553
static function fetchLimited( $moduleName, $functionName, $connectType )
    {
        $workflowArray = eZWorkflow::fetchList();
        $returnArray = array();

        foreach ( array_keys( $workflowArray ) as $key )
        {
            if ( $workflowArray[$key]->isAllowed( $moduleName,
                                                  $functionName,
                                                  $connectType ) )
            {
                $returnArray[] = $workflowArray[$key];
            }
        }

        return $returnArray;
    }
631141
protected function augmentSQLVersionedVersion(SQLSelect $query, DataQuery $dataQuery)
    {
        $version = $dataQuery->getQueryParam('Versioned.version');
        if (!$version) {
            throw new InvalidArgumentException("Invalid version");
        }

        // Query against _Versions table first
        $this->augmentSQLVersioned($query);

        // Add filter on version field
        $baseTable = $this->baseTable();
        $query->addWhere([
            "\"{$baseTable}_Versions\".\"Version\"" => $version,
        ]);
    }
873452
private int getMaxPartCount()
	{
		int max = 0;
		for (Object k : super.fWords.keySet())
		{
			String key = k.toString();
			int count = key.split("\\s+?").length;
			if (count > max)
			{
				max = count;
			}
		}
		return max;
	}
973640
static final int get6Bit(final Memory mem, final int offsetBytes, final int slotNo) {
    final int startBit = slotNo * 6;
    final int shift = startBit & 0X7;
    final int byteIdx = (startBit >>> 3) + offsetBytes;
    return (byte) ((mem.getShort(byteIdx) >>> shift) & 0X3F);
  }
543872
public function getVersion($codeSerialize)
    {
        $codeMd5 = md5($codeSerialize);

        $strSplit = str_split($codeMd5, 4);
        foreach ($strSplit as $strPart) {
            $strInt[] = str_pad(hexdec($strPart), 5, '0', STR_PAD_LEFT);
        }

        $codeVersion = round(implode('', $strInt), 10);

        return substr_replace($codeVersion, '.', 3, strlen($codeVersion) - 5);
    }
1073744
public function &LastRow($DatasetType = FALSE) {
      $Result = &$this->Result($DatasetType);
      if (count($Result) == 0)
         return $this->_EOF;

      return $Result[count($Result) - 1];
   }
188361
public function convertData()
    {
        $ver = $this->estimateVersion();
        if($ver > $this->getVersion()) {
            $this->setVersion($ver);
        }

        for(;;) {
            $bits = $this->createBitStream();

            if($bits < 0)
                return -1;

            $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
            if($ver < 0) {
                throw new Exception('WRONG VERSION');
                return -1;
            } else if($ver > $this->getVersion()) {
                $this->setVersion($ver);
            } else {
                break;
            }
        }

        return 0;
    }
731390
private static long getMaxTTL(Map<byte[], Long> ttlByFamily) {
    long maxTTL = 0;
    for (Long familyTTL : ttlByFamily.values()) {
      maxTTL = Math.max(familyTTL <= 0 ? Long.MAX_VALUE : familyTTL, maxTTL);
    }
    return maxTTL == 0 ? Long.MAX_VALUE : maxTTL;
  }
599190
@Override
	protected int detectTotalCpuPercent() throws Exception {
		Double value = (Double) mxBean.getSystemLoadAverage();
		return (int) Math.max(value * 100d, 0d);
	}
202610
public function getCharacterCountBits(Version $version) : int
    {
        $number = $version->getVersionNumber();

        if ($number <= 9) {
            $offset = 0;
        } elseif ($number <= 26) {
            $offset = 1;
        } else {
            $offset = 2;
        }

        return $this->characterCountBitsForVersions[$offset];
    }
663416
private function doCountBin()
    {
        $count   = 0;
        $bitset  = $this->bitset;
        $byteLen = \strlen($bitset);
        for ($bytePos = 0; $bytePos < $byteLen; ++$bytePos) {
            if ($bitset[$bytePos] === "\0") {
                // fast skip null byte
                continue;
            }

            $ord = \ord($bitset[$bytePos]);
            if ($ord & 0b00000001) ++$count;
            if ($ord & 0b00000010) ++$count;
            if ($ord & 0b00000100) ++$count;
            if ($ord & 0b00001000) ++$count;
            if ($ord & 0b00010000) ++$count;
            if ($ord & 0b00100000) ++$count;
            if ($ord & 0b01000000) ++$count;
            if ($ord & 0b10000000) ++$count;
        }
        return $count;
    }
1189356
private function versionFromBits($bits)
    {
        $version = [];
        foreach (range(0, ($bits - 1)) as $bit) {
            $version[$bit] = $this->getVersionBits()[$bit];
        }
        return $version;
    }