Passed
Branch master (203e41)
by Nate
02:00
created

AbstractProxy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 46
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __handleRetrofitRequest() 0 6 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Retrofit\Proxy;
10
11
use Tebru\Retrofit\HttpClient;
12
use Tebru\Retrofit\Internal\HttpClientCall;
13
use Tebru\Retrofit\Internal\ServiceMethod\ServiceMethodFactory;
14
use Tebru\Retrofit\Proxy;
15
16
/**
17
 * Class Proxy
18
 *
19
 * @author Nate Brunette <[email protected]>
20
 */
21
abstract class AbstractProxy implements Proxy
22
{
23
    /**
24
     * Creates a [@see DefaultServiceMethod]
25
     *
26
     * @var ServiceMethodFactory
27
     */
28
    private $serviceMethodFactory;
29
30
    /**
31
     * A retrofit http client
32
     *
33
     * @var HttpClient
34
     */
35
    private $client;
36
37
    /**
38
     * Constructor
39
     *
40
     * @param ServiceMethodFactory $serviceMethodFactory
41
     * @param HttpClient $client
42
     */
43 17
    public function __construct(ServiceMethodFactory $serviceMethodFactory, HttpClient $client)
44
    {
45 17
        $this->serviceMethodFactory = $serviceMethodFactory;
46 17
        $this->client = $client;
47 17
    }
48
49
    /**
50
     * Constructs a [@see Call] object based on an interface method and arguments, then passes it through a
51
     * [@see CallAdapter] before returning.
52
     *
53
     * @param string $interfaceName
54
     * @param string $methodName
55
     * @param array $args
56
     * @return mixed
57
     * @throws \ReflectionException
58
     * @throws \LogicException
59
     */
60 12
    public function __handleRetrofitRequest(string $interfaceName, string $methodName, array $args)
61
    {
62 12
        $serviceMethod = $this->serviceMethodFactory->create($interfaceName, $methodName);
63
64 11
        return $serviceMethod->adapt(new HttpClientCall($this->client, $serviceMethod, $args));
65
    }
66
}
67