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

eliashaeussler / composer-update-check / 15127653356

19 May 2025 08:30PM UTC coverage: 20.538%. First build
15127653356

Pull #130

github

web-flow
[TASK] Update cuyz/valinor to v1.16.1

| datasource | package      | from   | to     |
| ---------- | ------------ | ------ | ------ |
| packagist  | cuyz/valinor | 1.15.0 | 1.16.1 |
Pull Request #130: [!!!][FEATURE] Modernize plugin

356 of 1832 new or added lines in 57 files covered. (19.43%)

382 of 1860 relevant lines covered (20.54%)

1.11 hits per line

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

0.0
/src/Reporter/TeamsReporter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-update-check".
7
 *
8
 * Copyright (C) 2020-2025 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\ComposerUpdateCheck\Reporter;
25

26
use Composer\IO;
27
use EliasHaeussler\ComposerUpdateCheck\Entity;
28
use GuzzleHttp\Client;
29
use GuzzleHttp\Exception;
30
use GuzzleHttp\Psr7;
31
use GuzzleHttp\RequestOptions;
32
use Symfony\Component\OptionsResolver;
33

34
use function assert;
35
use function is_string;
36

37
/**
38
 * TeamsReporter.
39
 *
40
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
41
 * @license GPL-3.0-or-later
42
 */
43
final class TeamsReporter implements Reporter
44
{
45
    public const NAME = 'teams';
46

47
    private readonly OptionsResolver\OptionsResolver $resolver;
48

NEW
49
    public function __construct(
×
50
        private readonly Client $client,
51
        private readonly IO\IOInterface $io,
52
    ) {
NEW
53
        $this->resolver = $this->createOptionsResolver();
×
54
    }
55

NEW
56
    public function report(Entity\Result\UpdateCheckResult $result, array $options): bool
×
57
    {
58
        // Early return if no packages are outdated
NEW
59
        if (!$result->hasOutdatedPackages()) {
×
NEW
60
            $this->io->writeError('🚫 Skipped Teams report', true, IO\IOInterface::VERBOSE);
×
61

NEW
62
            return true;
×
63
        }
64

65
        // Resolve configuration options
NEW
66
        ['url' => $url, 'additionalData' => $additionalData] = $this->resolver->resolve($options);
×
67

68
        // Make PHPStan happy
69
        assert(is_string($url));
70
        assert(is_string($additionalData));
71

72
        // Create report
NEW
73
        $report = Entity\Report\TeamsReport::create($result, $additionalData);
×
74

75
        // Send report
76
        try {
NEW
77
            $this->io->writeError('📤 Sending report to Teams... ', false, IO\IOInterface::VERBOSE);
×
78

NEW
79
            $response = $this->client->post($url, [
×
NEW
80
                RequestOptions::JSON => $report,
×
NEW
81
            ]);
×
NEW
82
            $successful = 202 === $response->getStatusCode();
×
NEW
83
        } catch (Exception\GuzzleException) {
×
NEW
84
            $successful = false;
×
85
        }
86

NEW
87
        if ($successful) {
×
NEW
88
            $this->io->writeError('<info>Done</info>', true, IO\IOInterface::VERBOSE);
×
89
        } else {
NEW
90
            $this->io->writeError('<error>Failed</error>', true, IO\IOInterface::VERBOSE);
×
91
        }
92

NEW
93
        return $successful;
×
94
    }
95

96
    /**
97
     * @throws OptionsResolver\Exception\ExceptionInterface
98
     */
NEW
99
    public function validateOptions(array $options): void
×
100
    {
NEW
101
        $this->resolver->resolve($options);
×
102
    }
103

NEW
104
    public static function getName(): string
×
105
    {
NEW
106
        return self::NAME;
×
107
    }
108

NEW
109
    private function createOptionsResolver(): OptionsResolver\OptionsResolver
×
110
    {
NEW
111
        $resolver = new OptionsResolver\OptionsResolver();
×
112

NEW
113
        $resolver->define('url')
×
NEW
114
            ->allowedTypes('string')
×
NEW
115
            ->required()
×
NEW
116
            ->normalize(
×
NEW
117
                static fn (OptionsResolver\OptionsResolver $resolver, string $url) => new Psr7\Uri($url),
×
NEW
118
            )
×
NEW
119
        ;
×
120

NEW
121
        $resolver->define('additionalData')
×
NEW
122
            ->allowedTypes('string')
×
NEW
123
            ->default('')
×
NEW
124
        ;
×
125

NEW
126
        return $resolver;
×
127
    }
128
}
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