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

emgiezet / errbitPHP / #89

pending completion
#89

push

php-coveralls

web-flow
Merge pull request #29 from emgiezet/feature/php8.0-support

php8.0 - support removed some fancy stuff like readonly arguments

1 of 1 new or added line in 1 file covered. (100.0%)

337 of 421 relevant lines covered (80.05%)

2.49 hits per line

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

70.37
/src/Errbit/Writer/SocketWriter.php
1
<?php
2
declare(strict_types=1);
3
namespace Errbit\Writer;
4

5
use Errbit\Exception\Notice;
6

7
class SocketWriter extends AbstractWriter implements WriterInterface
8
{
9
  
10

11
    /**
12
     * @var false|int How many characters to read after request has been made
13
     */
14
    public $charactersToRead = false;
15

16
    /**
1✔
17
     * {@inheritdoc}
1✔
18
     *
1✔
19
     * @return void
1✔
20
     */
1✔
21
    public function write($exception, array $config)
1✔
22
    {
1✔
23
        $socket = fsockopen(
24
            $this->buildConnectionScheme($config),
1✔
25
            (integer) $config['port'],
1✔
26
            $errno,
1✔
27
            $errstr,
1✔
28
            $config['connect_timeout']
×
29
        );
×
30

×
31
        if ($socket) {
32
            stream_set_timeout($socket, $config['write_timeout']);
×
33
            $payLoad = $this->buildPayload($exception, $config);
34
            if (strlen((string) $payLoad) > 7000 && $config['async']) {
×
35
                $messageId = uniqid('', true);
×
36
                $chunks = str_split((string) $payLoad, 7000);
×
37
                foreach ($chunks as $idx => $chunk) {
×
38
                    $packet = ['messageid' => $messageId, 'data' => $chunk];
×
39
                    if ($idx == count($chunks)-1) {
×
40
                        $packet['last'] = true;
×
41
                    }
×
42
                    $fragment = json_encode($packet, JSON_THROW_ON_ERROR);
1✔
43
                    fwrite($socket, $fragment);
44
                }
1✔
45
            } else {
1✔
46
                fwrite($socket, (string) $payLoad);
1✔
47

48
                /**
49
                 * If errbit is behind a proxy, then we need read characters to make sure
50
                 * that request got to errbit successfully.
1✔
51
                 *
1✔
52
                 * Proxies usually do not make request to endpoints if client quits connection before
53
                 * proxy even gets the chance to create connection to endpoint
1✔
54
                 */
55
                if ($this->charactersToRead !== false) {
56
                    while (!feof($socket)) {
57
                        $character = fread($socket, $this->charactersToRead);
58
                        break;
1✔
59
                    }
1✔
60
                }
×
61
            }
1✔
62

×
63
            fclose($socket);
×
64
        }
1✔
65
    }
66

67
    protected function buildPayload($exception, array $config)
1✔
68
    {
69
        return $this->addHttpHeadersIfNeeded(
70
            $this->buildNoticeFor($exception, $config),
71
            $config
72
        );
1✔
73
    }
×
74
    
75
    protected function addHttpHeadersIfNeeded(string $body, $config)
1✔
76
    {
1✔
77
        if ($config['async']) {
1✔
78
            return $body;
1✔
79
        } else {
80
            return sprintf(
1✔
81
                "%s\r\n\r\n%s",
1✔
82
                implode(
1✔
83
                    "\r\n",
1✔
84
                    [sprintf('POST %s HTTP/1.1', self::NOTICES_PATH), sprintf('Host: %s', $config['host']), sprintf('User-Agent: %s', $config['agent']), sprintf('Content-Type: %s', 'text/xml'), sprintf('Accept: %s', 'text/xml, application/xml'), sprintf('Content-Length: %d', strlen((string) $body)), sprintf('Connection: %s', 'close')]
1✔
85
                ),
1✔
86
                $body
1✔
87
            );
1✔
88
        }
1✔
89
    }
90
    
1✔
91
}
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