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

eliashaeussler / composer-update-check / 20746954799

06 Jan 2026 11:29AM UTC coverage: 21.406%. First build
20746954799

Pull #130

github

web-flow
Merge pull request #213 from eliashaeussler/task/process
Pull Request #130: [!!!][FEATURE] Modernize plugin

385 of 1870 new or added lines in 57 files covered. (20.59%)

405 of 1892 relevant lines covered (21.41%)

1.18 hits per line

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

0.0
/src/Reporter/SlackReporter.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-2026 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 EliasHaeussler\TaskRunner;
29
use GuzzleHttp\Client;
30
use GuzzleHttp\Exception;
31
use GuzzleHttp\Psr7;
32
use GuzzleHttp\RequestOptions;
33
use Symfony\Component\OptionsResolver;
34

35
use function assert;
36
use function is_string;
37

38
/**
39
 * SlackReporter.
40
 *
41
 * @author Elias Häußler <elias@haeussler.dev>
42
 * @license GPL-3.0-or-later
43
 */
44
final readonly class SlackReporter implements Reporter
45
{
46
    public const NAME = 'slack';
47

48
    private OptionsResolver\OptionsResolver $resolver;
49
    private TaskRunner\TaskRunner $taskRunner;
50

NEW
51
    public function __construct(
×
52
        private Client $client,
53
        private IO\IOInterface $io,
54
    ) {
NEW
55
        $this->resolver = $this->createOptionsResolver();
×
NEW
56
        $this->taskRunner = new TaskRunner\TaskRunner($this->io);
×
57
    }
58

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

NEW
65
            return true;
×
66
        }
67

68
        // Resolve configuration options
NEW
69
        ['url' => $url] = $this->resolver->resolve($options);
×
70

71
        // Make PHPStan happy
72
        assert(is_string($url));
73

74
        // Create report
NEW
75
        $report = Entity\Report\SlackReport::create($result);
×
76

77
        // Send report
NEW
78
        return $this->taskRunner->run(
×
NEW
79
            '📤 Sending report to Slack',
×
NEW
80
            function (TaskRunner\RunnerContext $context) use ($url, $report) {
×
81
                try {
NEW
82
                    $response = $this->client->post($url, [
×
NEW
83
                        RequestOptions::JSON => $report,
×
NEW
84
                    ]);
×
NEW
85
                    $context->successful = 200 === $response->getStatusCode();
×
NEW
86
                } catch (Exception\GuzzleException) {
×
NEW
87
                    $context->successful = false;
×
88
                }
89

NEW
90
                return $context->successful;
×
NEW
91
            },
×
NEW
92
        );
×
93
    }
94

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

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

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

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

NEW
120
        return $resolver;
×
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

© 2026 Coveralls, Inc