Returns tracing links for all calls of the runtime class.
@param \FeaturePhp\File\File[] $files
@param \FeaturePhp\ProductLine\ProductLine $productLine
@return \FeaturePhp\Artifact\TracingLink[]
15633
public function traceRuntimeCalls($files, $productLine) {
        $runtimeCalls = array();
        
        foreach ($files as $file) {            
            $content = $file->getContent();
            if ($content instanceof fphp\File\StoredFileContent) {
                $fileSource = $content->getFileSource();
                $content = file_get_contents($fileSource);
            } else {
                $fileSource = "(text file)";
                $content = $content->getSummary();
            }
            
            foreach (explode("\n", $content) as $idx => $line)
                if (strstr($line, "$this->class::$this->getter")) {
                    preg_match("/$this->class::$this->getter\(.*?[\"'](.*?)[\"'].*?\)/", $line, $matches);
                    try {
                        $feature = $productLine->getFeature($matches[1]);
                    } catch (fphp\Model\ModelException $e) {
                        throw new RuntimeGeneratorException("invalid runtime feature \"$matches[1]\"");
                    }
                    $runtimeCalls[] = new fphp\Artifact\TracingLink(
                        "runtime",
                        $productLine->getArtifact($feature),
                        new fphp\Artifact\LinePlace($fileSource, $idx + 1),
                        new fphp\Artifact\LinePlace($file->getTarget(), $idx + 1));
                }
        }
        
        return $runtimeCalls;
    }
863758
public static function traceToString($trace)
    {
        if (!is_array($trace)) {
            return '';
        }

        $result = array();
        foreach ($trace as $index => $line) {
            if (isset($line['args']) && is_array($line['args'])) {
                $params = static::paramsToString($line['args']);
            } else {
                $params = '';
            }

            if (isset($line['file'])) {
                $result[] = sprintf(
                    "#%d %s:%d - %s(%s)", $index, $line['file'], $line['line'], $line['function'], $params
                );
            } else {
                $result[] = sprintf("#%d - %s(%s)", $index, $line['function'], $params);
            }
        }

        return implode(PHP_EOL, $result);
    }
1140434
public function getLineItemForProduct(Product $product)
    {
        foreach ($this->getLineItems() as $lineItem)
        {
            if ($lineItem->getProduct()->getId() == $product->getId())
            {
                return $lineItem;
            }
        }

        return $this->createLineItemForProduct($product);
    }
1352143
protected function getDocBlockReturnTypes(File $phpCsFile, int $stackPointer): array
    {
        $docBlock = DocCommentHelper::getDocComment($phpCsFile, $stackPointer);

        if ($docBlock === null) {
            return [];
        }

        preg_match('/(@return\s+)(\S+)/', $docBlock, $matches);

        if (!$matches) {
            return [];
        }

        $returnTypes = array_pop($matches);
        $returnTypes = trim($returnTypes);
        $returnTypes = explode('|', $returnTypes);

        return $returnTypes;
    }
617971
protected function load(array $files = null)
    {
        $defaults = [
            'bindings' => null,
            'providers' => null,
            'minimal' => null,
            'config' => null,
            'subscribers' => null,
            'routes' => null,
            'modules' => null
        ];

        is_array($files) ? extract($files) : extract($defaults);

        $bindings = isset($bindings) ? $bindings : null;
        ArrayLoader::bindings(Config::paths('system') . $bindings);

        $providers = isset($providers) ? $providers : null;
        ArrayLoader::providers(Config::paths('system') . $providers);

        $minimal = isset($minimal) ? $minimal : null;
        ArrayLoader::config(Config::paths('system') . $minimal);

        $config = isset($config) ? $config : null;
        ArrayLoader::config(Config::paths('system') . $config);

        $subscribers = isset($subscribers) ? $subscribers : null;
        ArrayLoader::subscribers(Config::paths('system') . $subscribers);

        $routes = isset($routes) ? $routes : null;
        ArrayLoader::routes(Config::paths('system') . $routes);

        $modules = isset($modules) ? $modules : null;
        ArrayLoader::modules(Config::paths('system') . $modules);

    }
1021844
private function traceCLI(array $trace, $label) {
            foreach ($trace as $k => $v) {
                $func = $loc = $line = '';
                $argsPresent = isset($v['args']) && !empty($v['args']);

                self::formatTraceLine($v, $func, $loc, $line);

                $this->console->write('<' . $label . 'b>#' . $k . ': </>')
                              ->write('<' . $label . '>' . ($loc ? $loc : '<<unknown file>>') . '</> ')
                              ->write('<' . $label . '>(' . ($line ? 'line ' . $line : 'unknown line') . ')</>')
                              ->write('<' . $label . '> | </>')
                              ->write('<' . $label . '>' . $func . '</>', true);

                if ($argsPresent) {
                    $this->console->write('<' . $label . 'b>Arguments:</>', true);
                    VarDumper::dump($v['args']);
                }

                $this->console->writeln('');
            }
        }
835169
public function getStackTraceFrames(array $trace): array
    {
        return \Raven_Stacktrace::get_stack_info(
            $trace,
            $this->client->trace,
            [],
            $this->client->message_limit,
            $this->client->getPrefixes(),
            $this->client->getAppPath(),
            $this->client->getExcludedAppPaths(),
            $this->serializer,
            $this->reprSerializer
        );
    }
1315233
public static function getCalledFromTrace($trace)
    {
        // Get file and line number
        $calledFromFile = '';
        if (isset($trace['file'])) {
            $calledFromFile .= $trace['file'] . ' line ' . $trace['line'];
            $calledFromFile = str_replace('\\', '/', $calledFromFile);
            $calledFromFile = (!empty(self::$documentRoot) ? substr($calledFromFile, strlen(self::$documentRoot)) : $calledFromFile);
            $calledFromFile = trim($calledFromFile, '/');
        }

        // Get function call
        $calledFromFunction = '';
        if (isset($trace['function'])) {
            $calledFromFunction .= (isset($trace['class']) ? $trace['class'] : '');
            $calledFromFunction .= (isset($trace['type']) ? $trace['type'] : '');
            $calledFromFunction .= $trace['function'] . '()';
        }

        // Return called from
        if ($calledFromFile) {
            return $calledFromFile;
        } elseif ($calledFromFunction) {
            return $calledFromFunction;
        } else {
            return 'Unable to get called from trace';
        }
    }
1114881
protected function linkFiles($lines, $test)
    {
        $matches = $this->findSourceCodeReferences($lines, $test);

        if (count($matches) != 0) {
            $lines = $this->createLinks($lines, $matches, $test);
        }

        return $this->CRToBr($lines);
    }
128282
private static function retrieveFilesFromPaths(array $paths): iterable
    {
        if ([] === $paths) {
            return [];
        }

        $pathsToSearch = [];
        $filesToAppend = [];

        foreach ($paths as $path) {
            if (false === file_exists($path)) {
                throw new RuntimeException(
                    sprintf(
                        'Could not find the file "%s".',
                        $path
                    )
                );
            }

            if (is_dir($path)) {
                $pathsToSearch[] = $path;
            } else {
                $filesToAppend[] = $path;
            }
        }

        $finder = new Finder();

        $finder->files()
            ->in($pathsToSearch)
            ->append($filesToAppend)
            ->filter(static function (SplFileInfo $fileInfo): ?bool {
                if ($fileInfo->isLink()) {
                    return false;
                }

                return null;
            })
            ->sortByName()
        ;

        return $finder;
    }
507105
private function getRelatedFiles(FileInterface $file)
    {
        // Match foo(_local).*(.dist)
        $base = $file->getFilename();
        $ext = Path::getExtension($base);
        $base = Path::getFilenameWithoutExtension($base);
        $base = Str::replaceLast($base, '_local', '');

        $dir = $file->getParent();
        $related = [];
        foreach ([".$ext", "_local.$ext"] as $tail) {
            $f = $dir->getFile($base . $tail);
            if ($f->getFilename() !== $file->getFilename() && $f->exists()) {
                $related[] = $f;
            }
        }

        return $related;
    }
1356432
private function getFileMap(PackageInterface $package, $directory)
    {
        $files = [];
        $root  = $this->getInstallPath($package);

        if (!file_exists($root . '/' . $directory)) {
            return [];
        }

        $iterator = new RecursiveDirectoryIterator($root . '/' . $directory, RecursiveDirectoryIterator::SKIP_DOTS);

        /** @var SplFileInfo $file */
        foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            if ($file->isFile()) {
                $path = str_replace($root . '/' . $directory . '/', '', $file->getPathname());

                $files[$directory . '/' . $path] = $path;
            }
        }

        return $files;
    }
37362
static public function traceFiles()
    {
        $backtrace = debug_backtrace();
        array_shift($backtrace);
        $message = 'load files:' . PHP_EOL;
        if ($backtrace) foreach ($backtrace as $v) {
            $message .= sprintf('[%s] %s: %s', filesize($v['file']), $v['file'], $v['function']) . PHP_EOL;
        }
        Ioc::logger('trace')->debug(sprintf('[%s]%s', 'file', $message));
    }
996946
public static function filtered($classes = array(), $files = array(), &$stack = null)
    {
        $skip_self_trace = 0;
        if ($stack === null) {
            $stack = debug_backtrace();
        }

        $classes = array_merge((array) $classes, array(__CLASS__));
        // Note: in a php backtrace, the class refers to the target of
        // invocation, whereas the file and line indicate where the invocation
        // happened.
        // E.g.
        //     [file] => /mover/backend/test/Belt/Support/TracePrinter.php
        //     [line] => 18
        //     [function] => debug
        //     [class] => Belt\Trace
        // Here, one might expect class to be 'Belt\Trace'
        $files = array_merge((array) $files, array(__FILE__));

        $filtered_stack = array();
        foreach ($stack as $index => $item) {
            $file = Arrays::get($item, 'file', null);
            // So given the long comment above, we cheat by looking
            // at our caller's class.
            $class = Arrays::get($stack, ($index).'.class', null);
            if (
                (in_array($file, $files))
                // ||
                // ($index != 0 && in_array($class, $classes))
            ) {
                $skip_self_trace++;
                continue;
            } else {
                $filtered_stack[] = $item;
            }
        }
        return $filtered_stack;
    }
235472
public function getReferencedFiles(array $fieldIds, $versionNo)
    {
        if (empty($fieldIds)) {
            return [];
        }

        $selectQuery = $this->connection->createQueryBuilder();
        $selectQuery
            ->select(
                $this->connection->quoteIdentifier('filename'),
                $this->connection->quoteIdentifier('mime_type')
            )
            ->from($this->connection->quoteIdentifier($this->getStorageTable()))
            ->where(
                $selectQuery->expr()->andX(
                    $selectQuery->expr()->in(
                        $this->connection->quoteIdentifier('contentobject_attribute_id'),
                        ':fieldIds'
                    ),
                    $selectQuery->expr()->eq(
                        $this->connection->quoteIdentifier('version'),
                        ':versionNo'
                    )
                )
            )
            ->setParameter(':fieldIds', $fieldIds, Connection::PARAM_INT_ARRAY)
            ->setParameter(':versionNo', $versionNo, PDO::PARAM_INT)
        ;

        $statement = $selectQuery->execute();

        return array_map(
            function ($row) {
                return $this->prependMimeToPath($row['filename'], $row['mime_type']);
            },
            $statement->fetchAll(PDO::FETCH_ASSOC)
        );
    }
106618
protected function getTwigInfo($trace)
    {
        $file = $trace['object']->getTemplateName();

        if (isset($trace['line'])) {
            foreach ($trace['object']->getDebugInfo() as $codeLine => $templateLine) {
                if ($codeLine <= $trace['line']) {
                    return [$file, $templateLine];
                }
            }
        }

        return [$file, -1];
    }
684751
public function files(FileCollection $files)
    {
        foreach ($files as $key => $file) {
            $this->getReporter()->progress($key + 1, count($files));

            foreach ($this->getReviews()->forFile($file) as $review) {
                $review->review($this->getReporter(), $file);
            }
        }

        return $this;
    }