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

The-oGlow / ya-corapi / 19987852443

06 Dec 2025 11:29AM UTC coverage: 36.484% (-1.3%) from 37.825%
19987852443

push

github

oglowa
#3: Update files / untested

687 of 1883 relevant lines covered (36.48%)

1.86 hits per line

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

45.71
/src/Yacorapi/Provider/AbstractProvider.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\Provider;
15

16
use Ds\Map;
17
use Monolog\ConsoleLogger;
18
use oglowa\tools\Yacorapi\ConstData;
19
use oglowa\tools\Yacorapi\IConnectionProvider;
20
use oglowa\tools\Yacorapi\IResponse;
21
use oglowa\tools\Yacorapi\Request\RequestType;
22
use oglowa\tools\Yacorapi\Response\Response;
23
use Psr\Log\LoggerInterface;
24

25
abstract class AbstractProvider implements IConnectionProvider
26
{
27
    /** @var LoggerInterface */
28
    protected $logger;
29

30
    /** @var ConstData */
31
    protected $constData;
32

33
    public function __construct()
6✔
34
    {
35
        // Init Dynamic Consts
36
        $this->constData = new ConstData(get_class($this));
6✔
37
        $this->logger = new ConsoleLogger(get_class($this));
6✔
38
    }
39

40
    /**
41
     * @param string $execUrl
42
     * @param int    $reqType
43
     *
44
     * @return IResponse
45
     */
46
    public function exec(string $execUrl, int $reqType = RequestType::REQ_TYP_GET): IResponse
1✔
47
    {
48
        $this->logger->debug('START - execUrl,reqType', [$execUrl, $reqType]);
1✔
49

50
        $rawData = $this->execInternal($execUrl, $reqType);
1✔
51
        $response     = $this->prepareResponse($rawData);
1✔
52

53
        $this->logger->debug('END');
1✔
54

55
        return $response;
1✔
56
    }
57

58
    /**
59
     * @param string            $execUrl
60
     * @param Map<mixed, mixed> $parameters
61
     * @param int               $reqType
62
     *
63
     * @return IResponse
64
     */
65
    public function execPost(string $execUrl, Map $parameters, int $reqType = RequestType::REQ_TYP_PUT): IResponse
×
66
    {
67
        $this->logger->debug('START - execUrl,parameters,reqType', [$execUrl, $parameters, $reqType]);
×
68

69
        $rawData = $this->execPostInternal($execUrl, $parameters, $reqType);
×
70
        $response = $this->prepareResponse($rawData);
×
71

72
        $this->logger->debug('END');
×
73

74
        return $response;
×
75
    }
76

77
    /**
78
     * @param mixed $data
79
     *
80
     * @return IResponse
81
     */
82
    public function prepareResponse($data): IResponse
4✔
83
    {
84
        $this->logger->debug('START');
4✔
85

86
        if (!empty($data) && is_array($data)) {
4✔
87
            $this->logger->debug('Prepare new response');
×
88
            $response = new Response($data);
×
89
        } else {
90
            $this->logger->info('Returning empty default response');
4✔
91
            $response = new Response();
4✔
92
        }
93

94
        $this->logger->debug('END');
4✔
95

96
        return $response;
4✔
97
    }
98

99
    /**
100
     * @param string $execUrl
101
     * @param int    $reqType
102
     *
103
     * @return mixed
104
     */
105
    abstract protected function execInternal(string $execUrl, int $reqType);
106

107
    /**
108
     * @param string           $execUrl
109
     * @param Map<mixed,mixed> $parameters
110
     * @param int              $reqType
111
     *
112
     * @return mixed
113
     */
114
    abstract protected function execPostInternal(string $execUrl, Map $parameters, int $reqType);
115

116
    /**
117
     * @return string
118
     */
119
    protected function getTokenValue(): string
×
120
    {
121
        $this->logger->debug('START');
×
122

123
        $tokenValue = getenv($this->constData->c(ConstData::KEY_AUTH_TOKEN_NAME));
×
124
        if (!is_string($tokenValue) || empty($tokenValue)) {
×
125
            $this->logger->warning('Token is NOT set!', [$this->constData->c(ConstData::KEY_AUTH_TOKEN_NAME)]);
×
126
            $tokenValue = '';
×
127
        }
128

129
        $this->logger->debug('END');
×
130

131
        return $tokenValue;
×
132
    }
133

134
    /**
135
     * @return string
136
     */
137
    protected function getAuthValue(): string
×
138
    {
139
        $this->logger->error(self::MSG_NOT_IMPLEMENTED);
×
140

141
        return '#username#:#password#';
×
142
    }
143
}
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