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

The-oGlow / ya-corapi / 20730329328

05 Jan 2026 09:54PM UTC coverage: 50.144% (+3.8%) from 46.354%
20730329328

push

github

oglowa
#3: Update files / tested

522 of 537 new or added lines in 20 files covered. (97.21%)

153 existing lines in 8 files now uncovered.

1048 of 2090 relevant lines covered (50.14%)

8.43 hits per line

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

8.09
/src/Yacorapi/Client/RapiClient.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of ezlogging
7
 *
8
 * (c) 2024 Oliver Glowa, coding.glowa.com
9
 *
10
 * This source file is subject to the Apache-2.0 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace oglowa\tools\Yacorapi\Client;
15

16
use Ds\Map;
17
use Monolog\ConsoleLogger;
18
use oglowa\tools\Yacorapi\ConstData;
19
use oglowa\tools\Yacorapi\Data\RequestParameterData;
20
use oglowa\tools\Yacorapi\IRapiClient;
21
use oglowa\tools\Yacorapi\IResponse;
22
use oglowa\tools\Yacorapi\Macro\AllAddon;
23
use oglowa\tools\Yacorapi\Request\RequestType;
24
use oglowa\tools\Yacorapi\Response\ResponseAddonMacroDecorate;
25
use oglowa\tools\Yacorapi\Response\ResponseSpaceDataDecorate;
26
use oglowa\tools\Yacorapi\Statistic\IStatistic;
27
use oglowa\tools\Yacorapi\Statistic\PagetypeStatistic;
28
use oglowa\tools\Yacorapi\Statistic\ValueStatistic;
29
use Psr\Log\LoggerInterface;
30

31
/**
32
 * @SuppressWarnings("PHPMD.TooManyPublicMethods")
33
 * @SuppressWarnings("PHPMD.CouplingBetweenObjects")
34
 */
35
class RapiClient extends AbstractRapiClient // NOSONAR: php:S1448
36
{
37
    /** @var LoggerInterface */
38
    private $logger;
39

40
    /**
41
     * @inheritdoc
42
     */
43
    public static function newClient(): IRapiClient
2✔
44
    {
45
        return new RapiClient();
2✔
46
    }
47

48
    /**
49
     * RapiClient constructor.
50
     *
51
     * @param int $modeExtension
52
     */
53
    protected function __construct(int $modeExtension = ConstData::EXTENSION_ALL)
2✔
54
    {
55
        // Init Logger
56
        $this->logger = new ConsoleLogger(RapiClient::class);
2✔
57
        $this->logger->debug('START');
2✔
58
        parent::__construct($modeExtension);
2✔
59

60
        $this->logger->debug('END');
2✔
61
    }
62

63
    // Public methods
64

65
    /**
66
     * @inheritdoc
67
     */
68
    public function readPageByPageId(int $pageId): IResponse
1✔
69
    {
70
        $this->logger->debug('START - pageId', [$pageId]);
1✔
71

72
        $prepareUrl = $this->commonExtension->prepareLoadUrl($pageId);
1✔
73

74
        return $this->exec($prepareUrl);
1✔
75
    }
76

77
    /**
78
     * @inheritdoc
79
     */
UNCOV
80
    public function readPagesWithFilter(string $filterTerm, string $spaceKey = ''): IResponse
×
81
    {
UNCOV
82
        $this->logger->debug('START - filterTerm,spaceKey', [$filterTerm, $spaceKey]);
×
83

UNCOV
84
        $prepareUrl = $this->commonExtension->prepareBrowseUrl($filterTerm, $spaceKey);
×
85

UNCOV
86
        return $this->exec($prepareUrl);
×
87
    }
88

89
    /**
90
     * @inheritdoc
91
     */
92
    public function scanPagesWithFilter(string $filterTerm, string $spaceKey = ''): IResponse
×
93
    {
94
        $this->logger->debug('START - filterTerm,spaceKey', [$filterTerm, $spaceKey]);
×
95

UNCOV
96
        $prepareUrl = $this->commonExtension->prepareScanUrl($filterTerm, $spaceKey);
×
97

UNCOV
98
        return $this->exec($prepareUrl);
×
99
    }
100

101
    /**
102
     * @inheritdoc
103
     */
104
    public function searchPagesWithFilter(
×
105
        string $filterTerm,
106
        string $spaceKey,
107
        int $searchFromPos = RequestParameterData::SEARCH_START,
108
        int $searchLimit = RequestParameterData::SEARCH_LIMIT_ZERO,
109
        string $itemType = RequestParameterData::ITEM_TYPE_PAGE
110
    ): IResponse {
UNCOV
111
        $this->logger->debug(
×
112
            'START - filterTerm,spaceKey,searchFromPos,searchLimit,itemType',
×
UNCOV
113
            [$filterTerm, $spaceKey, $searchFromPos, $searchLimit, $itemType]
×
UNCOV
114
        );
×
UNCOV
115
        $searchLimit = (int)($searchLimit < RequestParameterData::SEARCH_LIMIT_1ENTRY ? $this->constData->c(ConstData::KEY_SEARCH_LIMIT) : $searchLimit);
×
UNCOV
116
        $prepareUrl  = $this->commonExtension->prepareSearchUrlExt($filterTerm, $spaceKey, $searchFromPos, $searchLimit, $itemType);
×
117

UNCOV
118
        return $this->exec($prepareUrl);
×
119
    }
120

121
    /**
122
     * @inheritdoc
123
     */
124
    public function countItemsinSpace(string $spaceKey, string $itemType = RequestParameterData::ITEM_TYPE_PAGE): IStatistic
×
125
    {
126
        $this->logger->debug('START - spaceKey, itemType', [$spaceKey, $itemType]);
×
127

UNCOV
128
        $prepareUrl = $this->commonExtension->prepareCountItemsUrl($itemType, $spaceKey);
×
UNCOV
129
        $response   = $this->exec($prepareUrl);
×
130

UNCOV
131
        $itemCount      = $response->getValue(IResponse::KEY_TOTAL_SIZE, 0);
×
132
        $valueStatistic = new ValueStatistic(ValueStatistic::KEY_COUNT);
×
UNCOV
133
        $valueStatistic->addValue($itemCount);
×
134
        $singleStatistic = new PagetypeStatistic($itemType);
×
UNCOV
135
        $singleStatistic->addItem($itemType, $valueStatistic);
×
136

137
        $this->logger->debug('END');
×
138

139
        return $singleStatistic;
×
140
    }
141

142
    /**
143
     * @inheritdoc
144
     */
145
    public function readRestrictionsByPageId(int $pageId): IResponse
×
146
    {
147
        $this->logger->debug('START - pageId', [$pageId]);
×
148

UNCOV
149
        $prepareUrl = $this->adminExtension->prepareRestrictByOpUrl($pageId);
×
150

UNCOV
151
        return $this->exec($prepareUrl);
×
152
    }
153

154
    /**
155
     * REFACTOR: API-Function doesn't work or description is wrong.
156
     * {@inheritdoc}
157
     */
UNCOV
158
    public function writeRestrictionsByPageId(int $pageId, array $writeRestrictions = [], array $readRestrictions = []): bool // NOSONAR: php:S1172
×
159
    {
UNCOV
160
        throw new \BadMethodCallException('API-Function does not work or description is wrong');
×
161
    }
162

163
    /**
164
     * REFACTOR: Listing only 100 spaces, loop is missing.
165
     * {@inheritdoc}
166
     */
UNCOV
167
    public function listSpaces(string $spaceType = RequestParameterData::SPACE_TYPE_GLOBAL, int $limit = RequestParameterData::SPACE_LIMIT_DEFAULT): IResponse
×
168
    {
UNCOV
169
        $this->logger->debug('START - spaceType,limit', [$spaceType, $limit]);
×
170

UNCOV
171
        $prepareUrl = $this->commonExtension->prepareSpaceListUrl($spaceType, $limit);
×
172

UNCOV
173
        return new ResponseSpaceDataDecorate($this->exec($prepareUrl));
×
174
    }
175

176
    /**
177
     * @inheritdoc
178
     */
179
    public function countMacrosInSpace(string $spaceKey, ResponseAddonMacroDecorate $addonSet, IStatistic $outputMatrix): IStatistic
×
180
    {
181
        $this->logger->debug('START - spaceKey,addonSet', [$spaceKey, $addonSet]);
×
182

UNCOV
183
        $mapAddons = $addonSet->getResponse();
×
184

UNCOV
185
        $response = $this->loopAddons($spaceKey, $addonSet->getMode(), $mapAddons, $outputMatrix);
×
186

187
        $this->logger->debug('END');
×
188

189
        return $response;
×
190
    }
191

192
    /**
193
     * @inheritdoc
194
     */
195
    public function movePage(int $pageId, int $newParentId): IResponse
×
196
    {
197
        $this->logger->debug('START - pageId,newParentId', [$pageId, $newParentId]);
×
198

UNCOV
199
        $page = $this->readPageByPageId($pageId);
×
200

UNCOV
201
        $pageVersion = $page->getValue(RequestParameterData::PROP_VERSION, []);
×
UNCOV
202
        if (is_array($pageVersion) && array_key_exists(RequestParameterData::PROP_NUMBER, $pageVersion)) {
×
203
            $pageVersion = (int)$pageVersion[RequestParameterData::PROP_NUMBER];
×
204
        } else {
205
            $pageVersion = 1;
×
206
        }
207

UNCOV
208
        $parameters = new Map();
×
209
        $parameters->put(RequestParameterData::PROP_TITLE, $page->getValue(RequestParameterData::PROP_TITLE));
×
210
        $parameters->put(RequestParameterData::PROP_TYPE, $page->getValue(RequestParameterData::PROP_TYPE));
×
211
        $parameters->put(RequestParameterData::PROP_ANCESTORS, [[RequestParameterData::PROP_ID => $newParentId]]);
×
UNCOV
212
        $parameters->put(
×
213
            RequestParameterData::PROP_VERSION,
×
UNCOV
214
            [
×
UNCOV
215
                RequestParameterData::PROP_NUMBER  => ++$pageVersion, // NOSONAR php:S881
×
216
                RequestParameterData::PROP_MESSAGE => self::MSG_MOVED_TO_NEW_PARENT . $newParentId
×
217
            ]
×
218
        );
×
219

220
        $prepareUrl = $this->commonExtension->prepareUpdateURL($pageId);
×
221
        $response   = $this->execPost($prepareUrl, $parameters, RequestType::REQ_TYP_PUT);
×
222

223
        $this->logger->debug('END');
×
224

225
        return $response;
×
226
    }
227

228
    /**
229
     * @inheritdoc
230
     */
231
    public function createPage(
×
232
        string $spaceKey,
233
        string $pageTitle,
234
        string $pageBody,
235
        ?int $parentId = null,
236
        string $itemType = RequestParameterData::ITEM_TYPE_PAGE
237
    ): IResponse {
UNCOV
238
        $this->logger->debug('START - spaceKey,pageTitle,parentId,pageType,pageBody', [$spaceKey, $pageTitle, $parentId, $itemType, empty($pageBody)]);
×
239

240
        /** @var Map<mixed,mixed> */
UNCOV
241
        $parameters = new Map(
×
UNCOV
242
            [
×
UNCOV
243
                RequestParameterData::PROP_TYPE   => $itemType,
×
UNCOV
244
                RequestParameterData::PROP_TITLE  => $pageTitle,
×
UNCOV
245
                RequestParameterData::PROP_STATUS => RequestParameterData::STATUS_TYPE_CURRENT,
×
246
                RequestParameterData::PROP_BODY   => [
×
UNCOV
247
                    RequestParameterData::PROP_STORAGE => [
×
UNCOV
248
                        RequestParameterData::PROP_VALUE          => $pageBody,
×
249
                        RequestParameterData::PROP_REPRESENTATION => RequestParameterData::REPRESENTATION_TYPE_STORAGE,
×
250
                    ],
×
251
                ],
×
252
            ]
×
253
        );
×
254
        if (empty($spaceKey)) {
×
255
            throw new \InvalidArgumentException(self::MSG_SPACE_IS_EMPTY);
×
256
        } else {
257
            $parameters->put(RequestParameterData::PROP_SPACE, [RequestParameterData::PROP_KEY => $spaceKey]);
×
258
        }
259
        if (is_numeric($parentId)) {
×
260
            $parameters->put(RequestParameterData::PROP_ANCESTORS, [RequestParameterData::PROP_ID => $parentId]);
×
261
        } else {
262
            throw new \InvalidArgumentException(self::MSG_PARENT_ID_MUST_BE_NUMERIC);
×
263
        }
UNCOV
264
        $prepareUrl = $this->commonExtension->prepareCreatePage();
×
265
        $response   = $this->execPost($prepareUrl, $parameters, RequestType::REQ_TYP_POST);
×
266

267
        $this->logger->debug('END');
×
268

UNCOV
269
        return $response;
×
270
    }
271

272
    /**
273
     * @inheritdoc
274
     */
275
    public function updatePage(int $pageId, $pageBody, $pageTitle = '', $comment = '', $itemType = RequestParameterData::ITEM_TYPE_PAGE): bool
×
276
    {
277
        $this->logger->debug('START - pageId,pageTitle,pageType,bodySize,comment', [$pageId, $pageTitle, $itemType, strlen($pageBody), $comment]);
×
UNCOV
278
        $success = false;
×
279

UNCOV
280
        if (empty($pageId)) {
×
UNCOV
281
            $currentPage    = $this->readPageByPageId($pageId);
×
UNCOV
282
            $currentVersion = (int)$currentPage->getValue(RequestParameterData::PROP_VERSION, 1);
×
283
            $nextVersion    = $currentVersion + 1;
×
284

285
            if (empty($comment)) {
×
286
                $comment = self::MSG_UPDATE_PAGE_WITHOUT_CHANGES;
×
287
            }
288
            $prepareURL = $this->commonExtension->prepareUpdateURL($pageId);
×
289
            $parameters = new Map(
×
290
                [
×
291
                    RequestParameterData::PROP_ID      => $pageId,
×
UNCOV
292
                    RequestParameterData::PROP_TYPE    => $itemType,
×
293
                    RequestParameterData::PROP_TITLE   => $pageTitle,
×
294
                    RequestParameterData::PROP_BODY    => [
×
UNCOV
295
                        RequestParameterData::PROP_STORAGE => [
×
296
                            RequestParameterData::PROP_VALUE          => $pageBody,
×
297
                            RequestParameterData::PROP_REPRESENTATION => RequestParameterData::REPRESENTATION_TYPE_STORAGE
×
298
                        ]
×
299
                    ],
×
300
                    RequestParameterData::PROP_VERSION => [RequestParameterData::PROP_NUMBER => $nextVersion, RequestParameterData::PROP_MESSAGE => $comment],
×
301
                ]
×
302
            );
×
303

304
            $response = $this->execPost($prepareURL, $parameters, RequestType::REQ_TYP_PUT);
×
305
            $success  = $response->checkData();
×
306
            $this->logger->debug('Update page with title', [$pageId, $pageTitle, ($success ? 'successful' : 'failed')]);
×
307
        } else {
308
            $this->logger->error('No correct pageId', [$pageId]);
×
309
        }
310
        $this->logger->debug('END');
×
311

312
        return $success;
×
313
    }
314

315
    /**
316
     * @inheritdoc
317
     */
NEW
318
    public function prepareAddonSet($mode = AllAddon::ADDON_ALL): ResponseAddonMacroDecorate
×
319
    {
320
        $this->logger->debug('START - mode', [$mode]);
×
321

UNCOV
322
        $addonSet = new ResponseAddonMacroDecorate($mode, $this->addons->getDataByMode($mode));
×
323

UNCOV
324
        $this->logger->debug('END');
×
325

326
        return $addonSet;
×
327
    }
328
    // Private methods
329
}
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