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

JBZoo / CI-Report-Converter / 7665742520

14 Oct 2023 08:18PM UTC coverage: 94.375%. Remained the same
7665742520

push

github

web-flow
PHP CS Fixer - `ordered_types` (#40)

1426 of 1511 relevant lines covered (94.37%)

28.38 hits per line

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

91.43
/src/Converters/Map.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - CI-Report-Converter.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/CI-Report-Converter
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\CIReportConverter\Converters;
18

19
final class Map
20
{
21
    public const INPUT  = 'input';
22
    public const OUTPUT = 'output';
23

24
    public const MAP_TESTS = [
25
        JUnitConverter::class               => [self::INPUT => true, self::OUTPUT => true],
26
        TeamCityTestsConverter::class       => [self::INPUT => false, self::OUTPUT => true],
27
        PhpMdJsonConverter::class           => [self::INPUT => true, self::OUTPUT => false],
28
        CheckStyleConverter::class          => [self::INPUT => true, self::OUTPUT => false],
29
        PsalmJsonConverter::class           => [self::INPUT => true, self::OUTPUT => false],
30
        TeamCityInspectionsConverter::class => [self::INPUT => false, self::OUTPUT => true],
31
        PhpMndConverter::class              => [self::INPUT => true, self::OUTPUT => false],
32
        GithubCliConverter::class           => [self::INPUT => false, self::OUTPUT => true],
33
        PmdCpdConverter::class              => [self::INPUT => true, self::OUTPUT => false],
34
        GitLabJsonConverter::class          => [self::INPUT => false, self::OUTPUT => true],
35
        PlainTextConverter::class           => [self::INPUT => false, self::OUTPUT => true],
36
    ];
37

38
    public const MAP_METRICS = [
39
        PhpLocStatsTcConverter::class,
40
        PhpDependStatsTcConverter::class,
41
        PhpMetricsStatsTcConverter::class,
42
        PhpUnitCloverStatsTcConverter::class,
43
        JUnitStatsTcConverter::class,
44
    ];
45

46
    public static function getTable(): array
47
    {
48
        $result = [];
4✔
49

50
        $drivers = \array_keys(self::MAP_TESTS);
4✔
51
        \sort($drivers);
4✔
52

53
        foreach ($drivers as $source) {
4✔
54
            foreach ($drivers as $target) {
4✔
55
                $sourceName = $source::NAME;
4✔
56
                $targetName = $target::TYPE;
4✔
57

58
                $result[$sourceName][$targetName] = self::isAvailable($source, $target);
4✔
59
            }
60
        }
61

62
        return $result;
4✔
63
    }
64

65
    public static function getAvailableFormats(?string $direction = null): array
66
    {
67
        $drivers = \array_keys(self::MAP_TESTS);
36✔
68
        \sort($drivers);
36✔
69

70
        if ($direction !== null) {
36✔
71
            return \array_filter(
36✔
72
                // @phpstan-ignore-next-line
73
                \array_map(static function (string $converterClass) use ($direction): ?string {
36✔
74
                    if (self::MAP_TESTS[$converterClass][$direction]) {
36✔
75
                        // @phpstan-ignore-next-line
76
                        return $converterClass::TYPE;
36✔
77
                    }
78

79
                    return null;
36✔
80
                }, $drivers),
18✔
81
            );
18✔
82
        }
83

84
        return \array_map(static fn (string $converterClass): string => $converterClass::TYPE, $drivers);
20✔
85
    }
86

87
    public static function getAvailableMetrics(): array
88
    {
89
        $result = [];
36✔
90

91
        foreach (self::MAP_METRICS as $driver) {
36✔
92
            $result[] = $driver::TYPE;
36✔
93
        }
94

95
        \sort($result);
36✔
96

97
        return $result;
36✔
98
    }
99

100
    public static function isAvailable(string $source, string $target): bool
101
    {
102
        return self::MAP_TESTS[$source][self::INPUT] && self::MAP_TESTS[$target][self::OUTPUT];
4✔
103
    }
104

105
    public static function getConverter(string $format, string $direction): AbstractConverter
106
    {
107
        /** @var AbstractConverter $class */
108
        /** @var array $options */
109
        foreach (self::MAP_TESTS as $class => $options) {
20✔
110
            if ($class::TYPE === $format && $options[$direction]) {
20✔
111
                return new $class();
20✔
112
            }
113
        }
114

115
        throw new Exception(
×
116
            "The format \"{$format}\" is not available as \"{$direction}\" direction. " .
×
117
            'See `ci-report-converter convert:map`',
118
        );
119
    }
120

121
    public static function getMetric(string $sourceFormat, int $flowId = 0): AbstractStatsTcConverter
122
    {
123
        foreach (self::MAP_METRICS as $class) {
4✔
124
            if ($class::TYPE === $sourceFormat) {
4✔
125
                return new $class([], $flowId);
4✔
126
            }
127
        }
128

129
        throw new Exception("The format \"{$sourceFormat}\" is not available. See `ci-report-converter convert:map`");
×
130
    }
131
}
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