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

marscoin / martianrepublic / 23749891416

30 Mar 2026 02:25PM UTC coverage: 8.467% (+3.2%) from 5.241%
23749891416

push

github

Martian Congress
fix: resolve all 10 PHPStan errors + add 37 new tests

Fixes:
- DashboardController: undefined $user/$citizen in showReports/showCamera
- AiHelperController: env() → config() for cached config safety
- BADS models: add return type hints so Larastan resolves relations
- Ballots model: add return type hints for proposal/user relations
- ErrorTriageMail: fix regex delimiter and add unicode flag
- services.php: add openrouter config block

New test suites (37 tests, 97 assertions):
- AcademyTest: 10 article page loads + 404 handling
- ForumTest: categories, threads, posts, ordering, proposal linkage
- CongressTest: ballot relations, pendingForUser, controller methods
- InstrumentTest: chain of trust, calibration, attestations, soft delete
- AiHelperTest: validation, error triage mail, severity extraction

Total: 79 tests, 161 assertions, 0 PHPStan errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

14 of 21 new or added lines in 8 files covered. (66.67%)

1257 existing lines in 18 files now uncovered.

445 of 5256 relevant lines covered (8.47%)

1.06 hits per line

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

0.0
/app/Includes/jsonRPCClient.php
1
<?php
2
namespace App\Includes;
3
use Exception;  
4
/*
5
                                  COPYRIGHT
6

7
Copyright 2007 Sergio Vaccaro <sergio@inservibile.org>
8

9
This file is part of JSON-RPC PHP.
10

11
JSON-RPC PHP is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 2 of the License, or
14
(at your option) any later version.
15

16
JSON-RPC PHP is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
GNU General Public License for more details.
20

21
You should have received a copy of the GNU General Public License
22
along with JSON-RPC PHP; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24
*/
25

26
/**
27
 * The object of this class are generic jsonRPC 1.0 clients
28
 * http://json-rpc.org/wiki/specification
29
 *
30
 * @author sergio <jsonrpcphp@inservibile.org>
31
 */
32
class jsonRPCClient {
33
    private $debug;
34
    private $url;
35
    private $id;
36
    private $notification = false;
37
    private $proxy = ''; // Add proxy property
38

39
    public function __construct($url, $debug = false) {
×
40
        $this->url = $url;
×
41
        $this->debug = empty($debug) ? false : true;
×
42
        $this->id = 1;
×
43
    }
44

45

46
        /**
47
         * Sets the notification state of the object. In this state, notifications are performed, instead of requests.
48
         *
49
         * @param boolean $notification
50
         */
51
        public function setRPCNotification($notification) {
×
52
                empty($notification) ?
×
53
                                                        $this->notification = false
×
54
                                                        :
×
55
                                                        $this->notification = true;
×
56
        }
57

58
        /**
59
         * Performs a jsonRCP request and gets the results as an array
60
         *
61
         * @param string $method
62
         * @param array $params
63
         * @return array
64
         */
65
        public function __call($method,$params) {
×
66

67
                // check
68
                if (!is_scalar($method)) {
×
69
                        throw new Exception('Method name has no scalar value');
×
70
                }
71

72
                // check
73
                if (is_array($params)) {
×
74
                        // no keys
75
                        $params = array_values($params);
×
76
                } else {
77
                        throw new Exception('Params must be given as array');
×
78
                }
79

80
                // sets notification or request task
81
                if ($this->notification) {
×
82
                        $currentId = NULL;
×
83
                } else {
84
                        $currentId = $this->id;
×
85
                }
86

87
                // prepares the request (method name must be lowercase for Marscoin v28+)
88
                $request = array(
×
89
                                                'jsonrpc' => '1.0',
×
90
                                                'method' => strtolower($method),
×
91
                                                'params' => $params,
×
92
                                                'id' => $currentId
×
93
                                                );
×
94
                $request = json_encode($request);
×
95
                $this->debug && $this->debug.='***** Request *****'."\n".$request."\n".'***** End Of request *****'."\n\n";
×
96

97
                // performs the HTTP POST using curl (compatible with Marscoin v28+)
98
                $ch = curl_init($this->url);
×
UNCOV
99
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
×
UNCOV
100
                curl_setopt($ch, CURLOPT_POST, true);
×
101
                curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
×
102
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
×
103
                        'Content-Type: application/json',
×
104
                        'Connection: close'
×
105
                ));
×
106
                curl_setopt($ch, CURLOPT_TIMEOUT, 30);
×
107
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
×
108

109
                // Extract credentials from URL for Basic Auth
110
                $urlParts = parse_url($this->url);
×
111
                if (isset($urlParts['user']) && isset($urlParts['pass'])) {
×
112
                        curl_setopt($ch, CURLOPT_USERPWD, $urlParts['user'] . ':' . $urlParts['pass']);
×
113
                }
114

115
                $responseRaw = curl_exec($ch);
×
UNCOV
116
                $curlError = curl_error($ch);
×
117
                curl_close($ch);
×
118

UNCOV
119
                if ($responseRaw === false || empty($responseRaw)) {
×
120
                        throw new Exception('Unable to connect to '.$this->url.($curlError ? ': '.$curlError : ''));
×
121
                }
122

UNCOV
123
                $this->debug && $this->debug.='***** Server response *****'."\n".$responseRaw.'***** End of server response *****'."\n";
×
124
                $response = json_decode($responseRaw, true);
×
125

UNCOV
126
                if (!is_array($response)) {
×
UNCOV
127
                        throw new Exception('Invalid JSON response from server');
×
128
                }
129

130
                // debug output
131
                if ($this->debug) {
×
132
                        echo nl2br($this->debug);
×
133
                }
134

135
                // final checks and return
UNCOV
136
                if (!$this->notification) {
×
137
                        // check
138
                        if (isset($response['id']) && $response['id'] != $currentId) {
×
UNCOV
139
                                throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
×
140
                        }
141
                        if (isset($response['error']) && !is_null($response['error'])) {
×
UNCOV
142
                                $errorMsg = is_array($response['error']) ? json_encode($response['error']) : $response['error'];
×
UNCOV
143
                                throw new Exception('Request error: '.$errorMsg);
×
144
                        }
145

UNCOV
146
                        return $response['result'];
×
147

148
                } else {
UNCOV
149
                        return true;
×
150
                }
151
        }
152
}
153
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc