• 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

94.79
/src/Commands/Convert.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\Commands;
18

19
use JBZoo\CIReportConverter\Converters\CheckStyleConverter;
20
use JBZoo\CIReportConverter\Converters\Map;
21
use JBZoo\CIReportConverter\Converters\TeamCityTestsConverter;
22
use JBZoo\Cli\Codes;
23
use JBZoo\Cli\OutLvl;
24
use Symfony\Component\Console\Input\InputOption;
25

26
/**
27
 * @psalm-suppress PropertyNotSetInConstructor
28
 */
29
final class Convert extends AbstractCommand
30
{
31
    protected function configure(): void
32
    {
33
        $this
18✔
34
            ->setName('convert')
36✔
35
            ->setDescription('Convert one report format to another one')
36✔
36
            ->addOption(
36✔
37
                'input-format',
18✔
38
                'S',
18✔
39
                InputOption::VALUE_REQUIRED,
18✔
40
                'Source format. Available options: <info>' . \implode(
36✔
41
                    ', ',
18✔
42
                    Map::getAvailableFormats(Map::INPUT),
36✔
43
                ) . '</info>',
18✔
44
                CheckStyleConverter::TYPE,
18✔
45
            )
18✔
46
            ->addOption(
36✔
47
                'input-file',
18✔
48
                'I',
18✔
49
                InputOption::VALUE_OPTIONAL,
18✔
50
                'File path with the original report format. If not set or empty, then the STDIN is used.',
18✔
51
            )
18✔
52
            ->addOption(
36✔
53
                'output-format',
18✔
54
                'T',
18✔
55
                InputOption::VALUE_REQUIRED,
18✔
56
                'Target format. Available options: <info>' . \implode(
36✔
57
                    ', ',
18✔
58
                    Map::getAvailableFormats(Map::OUTPUT),
36✔
59
                ) . '</info>',
18✔
60
                TeamCityTestsConverter::TYPE,
18✔
61
            )
18✔
62
            ->addOption(
36✔
63
                'output-file',
18✔
64
                'O',
18✔
65
                InputOption::VALUE_OPTIONAL,
18✔
66
                'File path with the result report format. If not set or empty, then the STDOUT is used.',
18✔
67
            )
18✔
68
            ->addOption(
36✔
69
                'root-path',
18✔
70
                'R',
18✔
71
                InputOption::VALUE_OPTIONAL,
18✔
72
                'If option is set, all absolute file paths will be converted to relative once.',
18✔
73
                '.',
18✔
74
            )
18✔
75
            ->addOption(
36✔
76
                'suite-name',
18✔
77
                'N',
18✔
78
                InputOption::VALUE_REQUIRED,
18✔
79
                "Set custom name of root group/suite (if it's possible).",
18✔
80
            )
18✔
81
            ->addOption(
36✔
82
                'tc-flow-id',
18✔
83
                'F',
18✔
84
                InputOption::VALUE_OPTIONAL,
18✔
85
                'Custom flowId in TeamCity output. Default value is PID of the tool.',
18✔
86
            )
18✔
87
            ->addOption(
36✔
88
                'non-zero-code',
18✔
89
                'Q',
18✔
90
                InputOption::VALUE_OPTIONAL,
18✔
91
                'Will exit with the code=1, if any violations are found.',
18✔
92
                'no',
18✔
93
            );
18✔
94

95
        parent::configure();
36✔
96
    }
97

98
    protected function executeAction(): int
99
    {
100
        $sourceReport = $this->getSourceCode();
24✔
101
        $rootPath     = $this->getOptString('root-path');
24✔
102
        $suiteName    = $this->getOptString('suite-name');
24✔
103
        $nonZeroCode  = $this->getOptBool('non-zero-code');
24✔
104

105
        $casesAreFound = false;
24✔
106

107
        if ($sourceReport !== null) {
24✔
108
            $internalReport = Map::getConverter($this->getFormat('input-format'), Map::INPUT)
20✔
109
                ->setRootPath($rootPath)
20✔
110
                ->setRootSuiteName($suiteName)
20✔
111
                ->toInternal($sourceReport);
20✔
112

113
            $errorsCount  = $internalReport->getErrorsCount();
20✔
114
            $warningCount = $internalReport->getWarningCount();
20✔
115
            $failureCount = $internalReport->getFailureCount();
20✔
116

117
            $casesAreFound = $errorsCount > 0 || $warningCount > 0 || $failureCount > 0;
20✔
118

119
            $targetReport = Map::getConverter($this->getFormat('output-format'), Map::OUTPUT)
20✔
120
                ->setRootPath($rootPath)
20✔
121
                ->setRootSuiteName($suiteName)
20✔
122
                ->setFlowId($this->getOptInt('tc-flow-id'))
20✔
123
                ->fromInternal($internalReport);
20✔
124

125
            if ($this->saveResult($targetReport)) {
20✔
126
                if ($errorsCount > 0) {
4✔
127
                    $this->_("Found errors: {$errorsCount}", OutLvl::E);
×
128
                }
129

130
                if ($warningCount > 0) {
4✔
131
                    $this->_("Found warnings: {$warningCount}", OutLvl::E);
×
132
                }
133

134
                if ($failureCount > 0) {
4✔
135
                    $this->_("Found failures: {$failureCount}", OutLvl::E);
4✔
136
                }
137
            }
138
        }
139

140
        return $nonZeroCode && $casesAreFound ? Codes::GENERAL_ERROR : Codes::OK;
24✔
141
    }
142

143
    private function getFormat(string $optionName): string
144
    {
145
        $format = \strtolower($this->getOptString($optionName));
20✔
146

147
        $validFormats = Map::getAvailableFormats();
20✔
148

149
        if (!\in_array($format, $validFormats, true)) {
20✔
150
            throw new Exception(
×
151
                "Format \"{$format}\" not found. See the option \"--{$optionName}\".\n" .
×
152
                'Available options: ' . \implode(',', $validFormats),
×
153
            );
154
        }
155

156
        return $format;
20✔
157
    }
158
}
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