Parses the specified coverage data in LCOV format.
@param string $coverage The coverage data.
@return static The resulting coverage report.
@throws \UnexpectedValueException A parsing error occurred.
199834
static function fromCoverage(string $coverage): self {
    $report = new static;
    $records = $report->getRecords();

    try {
      /** @var Record $record */
      $record = null;
      foreach (preg_split('/\r?\n/', $coverage) ?: [] as $line) {
        $line = trim($line);
        if (!mb_strlen($line)) continue;

        $parts = explode(':', $line);
        if (count($parts) < 2 && $parts[0] != Token::endOfRecord) throw new \DomainException('Invalid token format');

        $token = array_shift($parts);
        $data = explode(',', implode(':', $parts));
        $length = count($data);

        switch ($token) {
          case Token::testName:
            $report->setTestName($data[0]);
            break;

          case Token::sourceFile:
            $record = new Record($data[0], new FunctionCoverage, new BranchCoverage, new LineCoverage);
            break;

          case Token::functionName:
            if ($length < 2) throw new \DomainException('Invalid function name');
            if ($functions = $record->getFunctions()) $functions->getData()->append(new FunctionData($data[1], (int) $data[0]));
            break;

          case Token::functionData:
            if ($length < 2) throw new \DomainException('Invalid function data');
            if ($functions = $record->getFunctions()) foreach ($functions->getData() as $item) {
              if ($item->getFunctionName() == $data[1]) {
                $item->setExecutionCount((int) $data[0]);
                break;
              }
            }
            break;

          case Token::functionsFound:
            if ($functions = $record->getFunctions()) $functions->setFound((int) $data[0]);
            break;

          case Token::functionsHit:
            if ($functions = $record->getFunctions()) $functions->setHit((int) $data[0]);
            break;

          case Token::branchData:
            if ($length < 4) throw new \DomainException('Invalid branch data');
            if ($branches = $record->getBranches()) $branches->getData()->append(new BranchData(
              (int) $data[0],
              (int) $data[1],
              (int) $data[2],
              $data[3] == '-' ? 0 : (int) $data[3]
            ));
            break;

          case Token::branchesFound:
            if ($branches = $record->getBranches()) $branches->setFound((int) $data[0]);
            break;

          case Token::branchesHit:
            if ($branches = $record->getBranches()) $branches->setHit((int) $data[0]);
            break;

          case Token::lineData:
            if ($length < 2) throw new \DomainException('Invalid line data');
            if ($lines = $record->getLines()) $lines->getData()->append(new LineData(
              (int) $data[0],
              (int) $data[1],
              $length >= 3 ? $data[2] : ''
            ));
            break;

          case Token::linesFound:
            if ($lines = $record->getLines()) $lines->setFound((int) $data[0]);
            break;

          case Token::linesHit:
            if ($lines = $record->getLines()) $lines->setHit((int) $data[0]);
            break;

          case Token::endOfRecord:
            $records->append($record);
            break;
        }
      }
    }

    catch (\Throwable $e) {
      throw new LcovException('The coverage data has an invalid LCOV format', $coverage, -1, $e);
    }

    if (!count($records)) throw new LcovException('The coverage data is empty', $coverage);
    return $report;
  }
127380
public function between($coverage)
    {
        if ($coverage instanceof CoverageEntity) {
            $lineAt = $coverage->getLineNumber();
        } else {
            $lineAt = $coverage;
        }

        return $lineAt >= $this->getFirstLineNumber() && $lineAt <= $this->getLastLineNumber();
    }
1026838
public static function fromASN1(UnspecifiedType $el): self
    {
        if (!$el->isTagged()) {
            throw new \UnexpectedValueException("v1Form issuer not supported.");
        }
        $tagged = $el->asTagged();
        switch ($tagged->tag()) {
            case 0:
                return V2Form::fromV2ASN1(
                    $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
        }
        throw new \UnexpectedValueException("Unsupported issuer type.");
    }
614666
private function detectRecord($record)
    {
        foreach ($this->recordTypes as $recordType) {
            $method = new ReflectionMethod($recordType, 'match');
            $arguments = [$record];

            if ($method->invokeArgs(null, $arguments) === false) {
                continue;
            }

            $class = $method->getDeclaringClass();

            return ($class->hasMethod('__construct'))
                ? $class->newInstanceArgs($arguments) : $class->newInstance();
        }

        throw new UnexpectedValueException();
    }
422491
public function set($fields = null)
    {
        if ($fields === null) {
            return $this->clause('set');
        }

        if (!in_array($this->action(), [self::ACTION_CREATE, self::ACTION_UPDATE])) {
            throw new \UnexpectedValueException(__('The action of this query needs to be either create update'));
        }

        $this->_parts['set'] = $fields;

        return $this;
    }
624626
public static function parseDate($string)
    {
        $string = (string) $string;

        $r = preg_match('/^\/Date\((\d{10})(\d{3})([+-]\d{4})\)\/$/', $string, $matches);
        if (!$r) {
            throw new \UnexpectedValueException('Preg Regex Pattern failed.');
        }
        $buffer = vsprintf(self::$dateMask, $matches);
        $result = \DateTime::createFromFormat(self::$dateFormat, $buffer);

        return $result;
    }
294889
public function getTemplate()
    {
        if(!$this->__template instanceof TemplateInterface)
        {
            $this->__template = $this->getObject($this->__template);

            if(!$this->__template instanceof TemplateInterface)
            {
                throw new \UnexpectedValueException(
                    'Template: '.get_class($this->_model).' does not implement TemplateInterface'
                );
            }
        }

        return $this->__template;
    }
827320
protected function byProperty()
    {
        $fields = $this->fieldIdentifiers();
        if (empty($fields)) {
            throw new UnexpectedValueException(
                'Property is required.'
            );
        }

        $dir = $this->direction();
        $dir = $dir === null ? '' : ' '.$dir;

        return implode($dir.', ', $fields).$dir;
    }
732288
public function get($key)
    {
        if (!$this->offsetExists($key)) {
            throw new UnexpectedValueException(sprintf('Unknown key %s.', $key));
        }

        return $this->offsetGet($key);
    }
1312359
public function generateReport(CodeCoverage $coverage)
    {
        $format = $this->config['report']['format'];
        $options = $this->config['report']['options'];

        $report = $this->factory->create($format, $options);
        $output = $report->process($coverage);

        if ('text' === $format) {
            print_r($output);
        }
    }
1069179
public function parseOutputLines(array $remoteDetails)
    {
        array_filter($remoteDetails);
        $name = array_shift($remoteDetails);
        $name = (is_string($name)) ? trim($name) : '';
        $name = $this->parseName($name);
        if (!$name) {
            throw new \UnexpectedValueException(sprintf('Invalid data provided for remote detail parsing'));
        }
        $this->name = $name;
        $fetchURLPattern = '/^Fetch\s+URL:\s*(.*)$/';
        $fetchURL = null;

        $pushURLPattern = '/^Push\s+URL:\s*(.*)$/';
        $pushURL = null;

        $remoteHEADPattern = '/^HEAD\s+branch:\s*(.*)$/';
        $remoteHEAD = null;

        $remoteBranchHeaderPattern = '/^Remote\s+branch(?:es)?:$/';
        $localBranchPullHeaderPattern = '/^Local\sbranch(?:es)?\sconfigured\sfor\s\'git\spull\'\:$/';
        $localRefPushHeaderPattern = '/^Local\sref(?:s)?\sconfigured\sfor\s\'git\spush\':$/';
        $groups = [
            'remoteBranches' => null,
            'localBranches'  => null,
            'localRefs'      => null,
        ];

        foreach ($remoteDetails as $lineno => $line) {
            $line = trim($line);
            $matches = [];
            if (is_null($fetchURL) && preg_match($fetchURLPattern, $line, $matches)) {
                $this->fetchURL = $fetchURL = $matches[1];
            } elseif (is_null($pushURL) && preg_match($pushURLPattern, $line, $matches)) {
                $this->pushURL = $pushURL = $matches[1];
            } elseif (is_null($remoteHEAD) && preg_match($remoteHEADPattern, $line, $matches)) {
                $this->remoteHEAD = $remoteHEAD = $matches[1];
            } elseif (is_null($groups['remoteBranches']) && preg_match($remoteBranchHeaderPattern, $line, $matches)) {
                $groups['remoteBranches'] = $lineno;
            } elseif (is_null($groups['localBranches']) && preg_match($localBranchPullHeaderPattern, $line, $matches)) {
                $groups['localBranches'] = $lineno;
            } elseif (is_null($groups['localRefs']) && preg_match($localRefPushHeaderPattern, $line, $matches)) {
                $groups['localRefs'] = $lineno;
            }
        }

        $this->setBranches($this->aggregateBranchDetails($groups, $remoteDetails));
    }
1006199
public function asVisibleString(): Primitive\VisibleString
    {
        if (!$this->_element instanceof Primitive\VisibleString) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
        }
        return $this->_element;
    }
76015
public function pop($path)
    {
        $node = $this->get($path);

        if (\is_object($node)) {
            $node = get_object_vars($node);
        }

        if (!\is_array($node)) {
            throw new \UnexpectedValueException(
                sprintf(
                    'The value at path: %s should be object or array but is %s.',
                    $path,
                    \gettype($node)
                )
            );
        }

        $value = array_pop($node);

        $this->set($path, $node);

        return $value;
    }
802060
protected function preProcessCoverage($coverage)
    {
        //Only Process If Work Directory Set
        if ($this->settings['work_dir'] === null) {
            return $this;
        }

        $workDir    = rtrim($this->settings['work_dir'], '/\\') . DIRECTORY_SEPARATOR;
        $projectDir = Configuration::projectDir();
        $data       = $coverage->getData(true); //We only want covered files, not all whitelisted ones.

        codecept_debug("Replacing all instances of {$workDir} with {$projectDir}");

        foreach ($data as $path => $datum) {
            unset($data[$path]);

            $path = str_replace($workDir, $projectDir, $path);

            $data[$path] = $datum;
        }

        $coverage->setData($data);

        return $this;
    }
1110999
protected function applyLocalizationsConfig($config)
    {
        if (isset($config['localizations'])) {
            $localizations = $config['localizations'];
            if (!is_array($localizations)) {
                throw new UnexpectedValueException($this->translate(
                    'Localization configuration for localizable field should be an array.'
                ));
            }
            $this->localizations = $localizations;
        }
    }
873590
public function getVersionedContent($version)
    {
        $versions = $this->getVersions();
        if (!in_array($version, $versions, true)) {
            throw new \UnexpectedValueException("Invalid log entry $version for {$this->path}.");
        }

        if (($content = \Arbit\VCSWrapper\Cache\Manager::get($this->path, $version, 'content')) === false) {
            // Refetch the basic content information, and cache it.
            $process = new \Arbit\VCSWrapper\CvsCli\Process();
            $process
                ->workingDirectory($this->root)
                ->redirect(\Arbit\VCSWrapper\CvsCli\Process::STDERR, \Arbit\VCSWrapper\CvsCli\Process::STDOUT)
                ->argument('update')
                ->argument('-p')
                ->argument('-r')
                ->argument($version)
                ->argument('.' . $this->path)
                ->execute();

            $output  = $process->stdoutOutput;
            $content = ltrim(substr($output, strpos($output, '***************') + 15));
            \Arbit\VCSWrapper\Cache\Manager::cache($this->path, $version, 'content', $content);
        }

        return $content;
    }
697293
public function unserialize($serialized)
    {
        $data = unserialize($serialized);
        if (!is_array($data)) {
            throw new \UnexpectedValueException('Unserialized data is not an array');
        }

        // TODO: check existence
        $this->message      = CustomAmqpMessage::fromProperties($data['message']);
        $this->tag          = (string) $data['tag'];
        $this->exchange     = (string) $data['exchange'];
        $this->queue        = (string) $data['queue'];
        $this->routingKey   = (string) $data['routingKey'];
        $this->redelivered  = (bool) $data['routingKey'];
    }