• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jojo1981 / decoder-aggregate / 12712243989

10 Jan 2025 03:19PM UTC coverage: 100.0%. Remained the same
12712243989

push

github

jojo1981
Use GitHub actions workflow for CI instead of Travis CI.

112 of 112 relevant lines covered (100.0%)

4.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Decoder/YamlDecoder.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the jojo1981/decoder-aggregate package
4
 *
5
 * Copyright (c) 2021 Joost Nijhuis <jnijhuis81@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed in the root of the source code
9
 */
10
namespace Jojo1981\DecoderAggregate\Decoder;
11

12
use Jojo1981\DecoderAggregate\DecoderInterface;
13
use Jojo1981\DecoderAggregate\Exception\YamlDecodeException;
14
use Symfony\Component\Yaml\Yaml;
15
use Throwable;
16

17
/**
18
 * @package Jojo1981\DecoderAggregate\Decoder
19
 */
20
final class YamlDecoder implements DecoderInterface
21
{
22
    /** @var int */
23
    private int $flags;
24

25
    /**
26
     * @param int $flags
27
     */
28
    public function __construct(int $flags = 0)
29
    {
30
        $this->flags = $flags;
19✔
31
    }
32

33
    /**
34
     * @param string $encodedString
35
     * @param array $options
36
     * @return mixed
37
     * @throws YamlDecodeException
38
     */
39
    public function decode(string $encodedString, array $options = [])
40
    {
41
        $options['flags'] = $options['flags'] ?? $this->flags;
17✔
42

43
        if (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $options['flags']) {
17✔
44
            $options['flags'] -= Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE;
1✔
45
        }
46

47
        try {
48
            return Yaml::parse($encodedString, $options['flags'] + Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
17✔
49
        } catch (Throwable $exception) {
1✔
50
            throw new YamlDecodeException('Could not decode yaml string', 0, $exception);
1✔
51
        }
52
    }
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc