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

move-elevator / composer-translation-validator / 16588667316

29 Jul 2025 06:40AM UTC coverage: 96.242% (-0.4%) from 96.609%
16588667316

Pull #59

github

jackd248
refactor: streamline constructor syntax and improve property visibility in configuration classes
Pull Request #59: refactor: domain architecture

119 of 132 new or added lines in 10 files covered. (90.15%)

3 existing lines in 1 file now uncovered.

2356 of 2448 relevant lines covered (96.24%)

8.19 hits per line

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

75.0
/src/Validation/ValidationSummary.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer plugin "composer-translation-validator".
7
 *
8
 * Copyright (C) 2025 Konrad Michalik <km@move-elevator.de>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace MoveElevator\ComposerTranslationValidator\Validation;
25

26
use MoveElevator\ComposerTranslationValidator\Result\ValidationResult;
27
use MoveElevator\ComposerTranslationValidator\Validator\ResultType;
28
use RuntimeException;
29

30
/**
31
 * Immutable value object providing API-friendly validation summary.
32
 *
33
 * This wraps ValidationResult for cleaner external API usage.
34
 */
35
final class ValidationSummary
36
{
37
    /**
38
     * @param bool          $success       Whether validation passed
39
     * @param ResultType    $resultType    Overall result type
40
     * @param int           $issuesCount   Total number of issues found
41
     * @param int           $filesChecked  Number of files validated
42
     * @param int           $validatorsRun Number of validators executed
43
     * @param float         $executionTime Validation execution time in seconds
44
     * @param array<string> $issueMessages List of issue messages
45
     */
46
    public function __construct(
10✔
47
        public readonly bool $success,
48
        public readonly ResultType $resultType,
49
        public readonly int $issuesCount,
50
        public readonly int $filesChecked,
51
        public readonly int $validatorsRun,
52
        public readonly float $executionTime,
53
        public readonly array $issueMessages = [],
54
    ) {}
10✔
55

56
    /**
57
     * Create ValidationSummary from ValidationResult.
58
     *
59
     * @param ValidationResult $result Original validation result
60
     */
61
    public static function fromValidationResult(ValidationResult $result): self
2✔
62
    {
63
        $issues = $result->getValidatorFileSetPairs();
2✔
64
        $issuesCount = count($issues);
2✔
65
        $issueMessages = [];
2✔
66

67
        foreach ($issues as $pair) {
2✔
68
            $validator = $pair['validator'];
1✔
69
            $issues = $validator->getIssues();
1✔
70
            foreach ($issues as $issue) {
1✔
NEW
71
                $details = $issue->getDetails();
×
NEW
72
                $message = implode(', ', $details);
×
NEW
73
                $issueMessages[] = sprintf(
×
NEW
74
                    '[%s] %s: %s',
×
NEW
75
                    $validator::class,
×
NEW
76
                    $issue->getFile(),
×
NEW
77
                    $message,
×
NEW
78
                );
×
79
            }
80
        }
81

82
        $statistics = $result->getStatistics();
2✔
83

84
        if (null === $statistics) {
2✔
NEW
85
            throw new RuntimeException('ValidationResult statistics cannot be null');
×
86
        }
87

88
        return new self(
2✔
89
            success: ResultType::SUCCESS === $result->getOverallResult(),
2✔
90
            resultType: $result->getOverallResult(),
2✔
91
            issuesCount: $issuesCount,
2✔
92
            filesChecked: $statistics->getFilesChecked(),
2✔
93
            validatorsRun: $statistics->getValidatorsRun(),
2✔
94
            executionTime: $statistics->getExecutionTime(),
2✔
95
            issueMessages: $issueMessages,
2✔
96
        );
2✔
97
    }
98

99
    /**
100
     * Check if validation had any issues.
101
     */
102
    public function hasIssues(): bool
2✔
103
    {
104
        return $this->issuesCount > 0;
2✔
105
    }
106

107
    /**
108
     * Check if validation failed (errors found).
109
     */
110
    public function hasFailed(): bool
2✔
111
    {
112
        return ResultType::ERROR === $this->resultType;
2✔
113
    }
114

115
    /**
116
     * Check if validation has warnings.
117
     */
118
    public function hasWarnings(): bool
3✔
119
    {
120
        return ResultType::WARNING === $this->resultType;
3✔
121
    }
122
}
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

© 2025 Coveralls, Inc