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

eliashaeussler / composer-update-check / 10714566433

05 Sep 2024 05:40AM UTC coverage: 20.475%. First build
10714566433

Pull #130

github

web-flow
Merge pull request #142 from eliashaeussler/task/lookup-progress

[TASK] Improve output of package lookup progress
Pull Request #130: [!!!][FEATURE] Modernize plugin

345 of 1786 new or added lines in 56 files covered. (19.32%)

371 of 1812 relevant lines covered (20.47%)

1.09 hits per line

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

0.0
/src/Reporter/MattermostReporter.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-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\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
/**
35
 * MattermostReporter.
36
 *
37
 * @author Elias Häußler <elias@haeussler.dev>
38
 * @license GPL-3.0-or-later
39
 */
40
final class MattermostReporter implements Reporter
41
{
42
    public const NAME = 'mattermost';
43

44
    private readonly OptionsResolver\OptionsResolver $resolver;
45

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

NEW
53
    public function report(Entity\Result\UpdateCheckResult $result, array $options): bool
×
54
    {
NEW
55
        ['url' => $url, 'channel' => $channel, 'username' => $username] = $this->resolver->resolve($options);
×
56

57
        // Create report
NEW
58
        $report = Entity\Report\MattermostReport::create($channel, $username, $result);
×
59

60
        // Send report
61
        try {
NEW
62
            $this->io->writeError('📤 Sending report to Mattermost... ', false, IO\IOInterface::VERBOSE);
×
63

NEW
64
            $response = $this->client->post($url, [
×
NEW
65
                RequestOptions::JSON => $report,
×
NEW
66
            ]);
×
NEW
67
            $successful = 200 === $response->getStatusCode();
×
NEW
68
        } catch (Exception\GuzzleException) {
×
NEW
69
            $successful = false;
×
70
        }
71

NEW
72
        if ($successful) {
×
NEW
73
            $this->io->writeError('<info>Done</info>', true, IO\IOInterface::VERBOSE);
×
74
        } else {
NEW
75
            $this->io->writeError('<error>Failed</error>', true, IO\IOInterface::VERBOSE);
×
76
        }
77

NEW
78
        return $successful;
×
79
    }
80

81
    /**
82
     * @throws OptionsResolver\Exception\ExceptionInterface
83
     */
NEW
84
    public function validateOptions(array $options): void
×
85
    {
NEW
86
        $this->resolver->resolve($options);
×
87
    }
88

NEW
89
    public static function getName(): string
×
90
    {
NEW
91
        return self::NAME;
×
92
    }
93

NEW
94
    private function createOptionsResolver(): OptionsResolver\OptionsResolver
×
95
    {
NEW
96
        $resolver = new OptionsResolver\OptionsResolver();
×
97

NEW
98
        $resolver->define('channel')
×
NEW
99
            ->allowedTypes('string')
×
NEW
100
            ->required()
×
NEW
101
        ;
×
102

NEW
103
        $resolver->define('url')
×
NEW
104
            ->allowedTypes('string')
×
NEW
105
            ->required()
×
NEW
106
            ->normalize(
×
NEW
107
                static fn (OptionsResolver\OptionsResolver $resolver, string $url) => new Psr7\Uri($url),
×
NEW
108
            )
×
NEW
109
        ;
×
110

NEW
111
        $resolver->define('username')
×
NEW
112
            ->allowedTypes('string', 'null')
×
NEW
113
            ->default(null)
×
NEW
114
        ;
×
115

NEW
116
        return $resolver;
×
117
    }
118
}
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