• 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

37.37
/src/Yacorapi/Client/AbstractRapiClient.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 Ds\Vector;
18
use Monolog\ConsoleLogger;
19
use oglowa\tools\Addon\Atlassian\Extension\AdminExtension;
20
use oglowa\tools\Addon\Atlassian\Extension\AtlassianExtension;
21
use oglowa\tools\Addon\Projectdoc\Extension\ProjectdocExtension;
22
use oglowa\tools\Addon\ThirdParty\Extension\ThirdPartyExtension;
23
use oglowa\tools\Addon\UserMacro\Extension\UserMacroExtension;
24
use oglowa\tools\Yacorapi\ConstData;
25
use oglowa\tools\Yacorapi\Data\AddonMacroData;
26
use oglowa\tools\Yacorapi\Data\RequestParameterData;
27
use oglowa\tools\Yacorapi\Extension\RapiClientExtension;
28
use oglowa\tools\Yacorapi\IConnectionProvider;
29
use oglowa\tools\Yacorapi\IRapiClient;
30
use oglowa\tools\Yacorapi\IResponse;
31
use oglowa\tools\Yacorapi\Provider\CurlProvider;
32
use oglowa\tools\Yacorapi\Request\RequestType;
33
use oglowa\tools\Yacorapi\Response\DummyResponse;
34
use oglowa\tools\Yacorapi\Statistic\AddonStatistic;
35
use oglowa\tools\Yacorapi\Statistic\IStatistic;
36
use oglowa\tools\Yacorapi\Statistic\MacroStatistic;
37
use oglowa\tools\Yacorapi\Statistic\SpaceStatistic;
38
use oglowa\tools\Yacorapi\Statistic\ValueStatistic;
39
use oglowa\tools\Yacorapi\Traits\ExtensionTrait;
40
use Psr\Log\LoggerInterface;
41

42
abstract class AbstractRapiClient implements IRapiClient
43
{
44
    use ExtensionTrait;
45

46
    public const MSG_PARENT_ID_MUST_BE_NUMERIC = 'parentId must be numeric!';
47

48
    public const MSG_MOVED_TO_NEW_PARENT = 'Page moved to new parent ';
49

50
    public const MSG_SPACE_IS_EMPTY = 'spaceKey is empty!';
51

52
    public const MSG_UPDATE_PAGE_WITHOUT_CHANGES = 'Update page without changes';
53

54
    /** @var ConstData */
55
    protected $constData;
56

57
    /** @var AddonMacroData */
58
    protected $addons;
59

60
    /** @var RapiClientExtension
61
     * @psalm-suppress PropertyNotSetInConstructor
62
     */
63
    protected $commonExtension;
64

65
    /** @var AdminExtension
66
     * @psalm-suppress PropertyNotSetInConstructor
67
     */
68
    protected $adminExtension;
69

70
    /** @var AtlassianExtension
71
     * @psalm-suppress PropertyNotSetInConstructor
72
     */
73
    protected $atlassianExtension;
74

75
    /** @var UserMacroExtension
76
     * @psalm-suppress PropertyNotSetInConstructor
77
     */
78
    protected $userMacroExtension;
79

80
    /** @var ThirdPartyExtension
81
     * @psalm-suppress PropertyNotSetInConstructor
82
     */
83
    protected $thirdPartyExtension;
84

85
    /** @var ProjectdocExtension
86
     * @psalm-suppress PropertyNotSetInConstructor
87
     */
88
    protected $projectdocExtension;
89

90
    /** @var IConnectionProvider */
91
    protected $connectionProvider;
92

93
    /** @var LoggerInterface */
94
    private $logger;
95

96
    /**
97
     * Create new RapiClient.
98
     *
99
     * @return IRapiClient
100
     */
101
    abstract public static function newClient(): IRapiClient;
102

103
    /**
104
     * RapiClient constructor.
105
     *
106
     * @param int $modeExtension
107
     */
108
    protected function __construct(
2✔
109
        int $modeExtension = ConstData::EXTENSION_ALL
110
    ) {
111
        // Init Logger
112
        $this->logger = new ConsoleLogger(AbstractRapiClient::class);
2✔
113
        $this->logger->debug('START');
2✔
114

115
        // Init Dynamic Consts
116
        $this->constData = new ConstData(get_class($this));
2✔
117
        // Init Modules
118
        $this->addons             = new AddonMacroData();
2✔
119
        $this->connectionProvider = new CurlProvider(new DummyResponse());
2✔
120
        // Init Extensions
121
        $this->loadExtensions($modeExtension);
2✔
122

123
        $this->logger->debug('END');
2✔
124
    }
125

126
    /**
127
     * @param string $prepareUrl
128
     * @param int    $reqType
129
     *
130
     * @return IResponse
131
     */
132
    protected function exec(string $prepareUrl, int $reqType = RequestType::REQ_TYP_GET): IResponse
1✔
133
    {
134
        $this->logger->debug('START', [$prepareUrl, $reqType]);
1✔
135

136
        $response = $this->connectionProvider->exec($prepareUrl, $reqType);
1✔
137

138
        $this->logger->debug('END');
1✔
139

140
        return $response;
1✔
141
    }
142

143
    /**
144
     * @param string            $prepareUrl
145
     * @param Map <mixed,mixed> $parameters
146
     * @param int               $reqType
147
     *
148
     * @return IResponse
149
     */
UNCOV
150
    protected function execPost(string $prepareUrl, Map $parameters, int $reqType): IResponse
×
151
    {
UNCOV
152
        $this->logger->debug('START - prepareUrl,parameters,reqType', [$prepareUrl, $parameters, $reqType]);
×
153

UNCOV
154
        $response = $this->connectionProvider->execPost($prepareUrl, $parameters, $reqType);
×
155

156
        $this->logger->debug('END');
×
157

UNCOV
158
        return $response;
×
159
    }
160

161
    /**
162
     * @param mixed[] $page
163
     *
164
     * @return string
165
     */
UNCOV
166
    protected function getSpaceKeyFromResult(array $page = []): string
×
167
    {
UNCOV
168
        return isset($page[RequestParameterData::PROP_CONTENT][RequestParameterData::PROP_SPACE][RequestParameterData::PROP_KEY]) ?
×
169
            $page[RequestParameterData::PROP_CONTENT][RequestParameterData::PROP_SPACE][RequestParameterData::PROP_KEY] :
×
UNCOV
170
            $page[RequestParameterData::PROP_SPACE][RequestParameterData::PROP_KEY];
×
171
    }
172

173
    /**
174
     * @param null|IStatistic $spaceResult
175
     * @param string          $spaceKey
176
     * @param string          $addon
177
     * @param string          $macroName
178
     * @param int             $macroCount
179
     *
180
     * @return IStatistic
181
     */
182
    protected function prepareMatrix(?IStatistic $spaceResult, string $spaceKey, string $addon, string $macroName, int $macroCount): IStatistic
×
183
    {
184
        $this->logger->debug('START - spaceResult,spaceKey,addon,macroName,macroCount', [$spaceResult, $spaceKey, $addon, $macroName, $macroCount]);
×
185

UNCOV
186
        if (empty($spaceResult)) {
×
UNCOV
187
            $spaceResult = new SpaceStatistic($spaceKey);
×
188
        }
189

190
        $addonResult = $spaceResult->getItem($addon);
×
UNCOV
191
        if (empty($addonResult)) {
×
192
            $addonResult = new AddonStatistic($addon);
×
193
        }
194

195
        $macroResult = $addonResult->getItem($macroName);
×
196
        if (empty($macroResult)) {
×
UNCOV
197
            $macroResult = new MacroStatistic($macroName);
×
198
        }
199

200
        /** @var null|ValueStatistic $valueResult */
UNCOV
201
        $valueResult = $macroResult->getItem(IResponse::KEY_COUNT);
×
UNCOV
202
        if (empty($valueResult)) {
×
UNCOV
203
            $valueResult = new ValueStatistic(IResponse::KEY_COUNT);
×
204
        }
UNCOV
205
        $valueResult->addValue($macroCount + (int)$valueResult->getValue());
×
206

UNCOV
207
        $macroResult->addItem(IResponse::KEY_COUNT, $valueResult);
×
UNCOV
208
        $addonResult->addItem($macroName, $macroResult);
×
UNCOV
209
        $spaceResult->addItem($addon, $addonResult);
×
210

211
        $this->logger->debug('END');
×
212

213
        return $spaceResult;
×
214
    }
215

216
    /**
217
     * @param string          $spaceKey
218
     * @param string          $addOn
219
     * @param Vector <string> $macroNames
220
     * @param IStatistic      $outputMatrix
221
     *
222
     * @return IStatistic
223
     */
224
    protected function loopAddonMacros(string $spaceKey, string $addOn, Vector $macroNames, IStatistic $outputMatrix): IStatistic
×
225
    {
226
        $this->logger->debug('START - spaceKey,addOn,macroNames', [$spaceKey, $addOn, $macroNames]);
×
227

228
        foreach ($macroNames as $macroName) {
×
229
            $this->logger->debug('Checking Space with Macro - START', [$spaceKey, $addOn, $macroName]);
×
230

231
            $searchTerm  = "macroName:$macroName";
×
UNCOV
232
            $prepareUrl  = $this->commonExtension->prepareSearchUrlExt(
×
UNCOV
233
                $searchTerm,
×
234
                $spaceKey,
×
UNCOV
235
                RequestParameterData::SEARCH_START,
×
236
                RequestParameterData::SEARCH_LIMIT_1ENTRY
×
UNCOV
237
            );
×
UNCOV
238
            $response    = $this->exec($prepareUrl);
×
UNCOV
239
            $countMacros = $this->commonExtension->analyzeResponse($response);
×
240

UNCOV
241
            $outputMatrix = $this->prepareMatrix($outputMatrix, $spaceKey, $addOn, $macroName, $countMacros);
×
UNCOV
242
            $this->logger->debug('Found', [$spaceKey, $addOn, $macroName, $countMacros]);
×
243

UNCOV
244
            $this->logger->debug('Checking Space with Macro - END');
×
245
        }
246

247
        $this->logger->debug('END');
×
248

249
        return $outputMatrix;
×
250
    }
251

252
    /**
253
     * @param string             $spaceKey
254
     * @param int                $mode
255
     * @param Map <mixed, mixed> $mapAddons
256
     * @param IStatistic         $outputMatrix
257
     *
258
     * @return IStatistic
259
     */
260
    protected function loopAddons(string $spaceKey, int $mode, Map $mapAddons, IStatistic $outputMatrix): IStatistic
×
261
    {
262
        $this->logger->debug('START - spaceKey,mode,addons', [$spaceKey, $mode, $mapAddons]);
×
263

264
        foreach ($mapAddons as $addOnKey => $addonValue) {
×
UNCOV
265
            $this->logger->debug('Checking Addon - START', [$spaceKey, $addOnKey]);
×
266
            if (!is_array($addonValue)) {
×
UNCOV
267
                $macroNames = $this->addons->getMacroNamesByAddon($mode, $addOnKey);
×
268
                $addonName  = $addOnKey;
×
269
            } else {
UNCOV
270
                $macroNames = $addonValue;
×
UNCOV
271
                $addonName  = $addOnKey;
×
272
            }
UNCOV
273
            $this->logger->debug('Found :', [$addonName, $macroNames]);
×
274

UNCOV
275
            $outputMatrix = $this->loopAddonMacros($spaceKey, $addonName, new Vector($macroNames), $outputMatrix);
×
276

UNCOV
277
            $this->logger->debug('Checking Addon - END');
×
278
        }
279
        $this->logger->debug('END');
×
280

UNCOV
281
        return $outputMatrix;
×
282
    }
283

284
    /**
285
     * @param int $modeExtension
286
     *
287
     * @psalm-suppress PropertyTypeCoercion
288
     *
289
     * @SuppressWarnings("PHPMD.ExitExpression")
290
     */
291
    protected function loadExtensions(int $modeExtension): void
2✔
292
    {
293
        $this->logger->debug('START', [$modeExtension]);
2✔
294

295
        $extensions = $this->initExtensions($modeExtension, $this->constData, $this->logger);
2✔
296

297
        foreach ($extensions as $key => $extension) {
2✔
298
            $this->logger->debug('Key,Ext', [$key]);
2✔
299

300
            switch (true) {
301
                case (ConstData::EXTENSION_RAPI_CLIENT == $key):
2✔
302
                    $this->commonExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
303
                    break;
2✔
304
                case (ConstData::EXTENSION_ATLASSIAN == $key):
2✔
305
                    $this->atlassianExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
306
                    break;
2✔
307
                case (ConstData::EXTENSION_ATLASSIAN_ADMIN == $key):
2✔
308
                    $this->adminExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
309
                    break;
2✔
310
                case (ConstData::EXTENSION_ATLASSIAN_USER_MACRO == $key):
2✔
311
                    $this->userMacroExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
312
                    break;
2✔
313
                case (ConstData::EXTENSION_THIRD_PARTY == $key):
2✔
314
                    $this->thirdPartyExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
315
                    break;
2✔
316
                case (ConstData::EXTENSION_PROJECTDOC_TOOLBOX == $key):
2✔
317
                    $this->projectdocExtension = $extension; // @phpstan-ignore assign.propertyType
2✔
318
                    break;
2✔
319
                default:
UNCOV
320
                    $this->logger->emergency('Extension not loaded', [$key,$extension]);
×
321

UNCOV
322
                    exit(13);
×
323
            }
324
        }
325
        $this->logger->debug('END');
2✔
326
    }
327
}
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