public static function createForInvalidYaml(string $file, int $code = 0, \Throwable $previous = null) : UnparsableFileException { return new UnparsableFileException(sprintf('The file "%s" does not contain valid YAML.', $file), $code, $previous); }
/** * {@inheritDoc} * * @param string $file Local YAML file * * @throws ParseException */ public function parse(string $file) : array { if (false === file_exists($file)) { throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file); } try { $data = $this->yamlParser->parse(file_get_contents($file)); // $data is null only if the YAML file was empty; otherwise an exception is thrown return null === $data ? [] : $data; } catch (\Exception $exception) { if ($exception instanceof SymfonyParseException) { throw ParseExceptionFactory::createForInvalidYaml($file, 0, $exception); } throw ParseExceptionFactory::createForUnparsableFile($file, 0, $exception); } }