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

eliashaeussler / version-bumper / 11011333131

24 Sep 2024 09:50AM UTC coverage: 88.978% (+0.3%) from 88.685%
11011333131

push

github

web-flow
Merge pull request #4 from eliashaeussler/feature/report-unmatched

54 of 63 new or added lines in 9 files covered. (85.71%)

2 existing lines in 2 files now uncovered.

331 of 372 relevant lines covered (88.98%)

2.75 hits per line

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

60.0
/src/Result/WriteOperation.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/version-bumper".
7
 *
8
 * Copyright (C) 2024 Elias Häußler <elias@haeussler.dev>
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 EliasHaeussler\VersionBumper\Result;
25

26
use EliasHaeussler\VersionBumper\Config;
27
use EliasHaeussler\VersionBumper\Enum;
28
use EliasHaeussler\VersionBumper\Exception;
29
use EliasHaeussler\VersionBumper\Version;
30

31
/**
32
 * WriteOperation.
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-3.0-or-later
36
 */
37
final class WriteOperation
38
{
39
    /**
40
     * @throws Exception\SourceVersionIsMissing
41
     * @throws Exception\TargetVersionIsMissing
42
     * @throws Exception\VersionBumpResultIsMissing
43
     */
44
    public function __construct(
4✔
45
        private readonly ?Version\Version $source,
46
        private readonly ?Version\Version $target,
47
        private readonly ?string $result,
48
        private readonly Config\FilePattern $pattern,
49
        private readonly Enum\OperationState $state,
50
    ) {
51
        $this->validate();
4✔
52
    }
53

54
    public static function unmatched(Config\FilePattern $pattern): self
1✔
55
    {
56
        return new self(null, null, null, $pattern, Enum\OperationState::Unmatched);
1✔
57
    }
58

NEW
59
    public function source(): ?Version\Version
×
60
    {
61
        return $this->source;
×
62
    }
63

NEW
64
    public function target(): ?Version\Version
×
65
    {
66
        return $this->target;
×
67
    }
68

NEW
69
    public function result(): ?string
×
70
    {
71
        return $this->result;
×
72
    }
73

NEW
74
    public function pattern(): Config\FilePattern
×
75
    {
NEW
76
        return $this->pattern;
×
77
    }
78

79
    /**
80
     * @phpstan-assert-if-true !null $this->source()
81
     * @phpstan-assert-if-true !null $this->target()
82
     * @phpstan-assert-if-true !null $this->result()
83
     */
84
    public function matched(): bool
1✔
85
    {
86
        return Enum\OperationState::Unmatched !== $this->state;
1✔
87
    }
88

UNCOV
89
    public function state(): Enum\OperationState
×
90
    {
91
        return $this->state;
×
92
    }
93

94
    /**
95
     * @throws Exception\SourceVersionIsMissing
96
     * @throws Exception\TargetVersionIsMissing
97
     * @throws Exception\VersionBumpResultIsMissing
98
     */
99
    private function validate(): void
4✔
100
    {
101
        if (Enum\OperationState::Unmatched === $this->state) {
4✔
102
            return;
1✔
103
        }
104

105
        if (null === $this->source) {
4✔
106
            throw new Exception\SourceVersionIsMissing();
1✔
107
        }
108
        if (null === $this->target) {
4✔
109
            throw new Exception\TargetVersionIsMissing();
1✔
110
        }
111
        if (null === $this->result) {
4✔
112
            throw new Exception\VersionBumpResultIsMissing();
1✔
113
        }
114
    }
115
}
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