Completed
Pull Request — master (#12)
by Christian
08:34 queued 05:41
created

XApiClient::getAgentProfileApiClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Client;
13
14
use Xabbuh\XApi\Client\Api\ActivityProfileApiClient;
15
use Xabbuh\XApi\Client\Api\AgentProfileApiClient;
16
use Xabbuh\XApi\Client\Api\ApiClient;
17
use Xabbuh\XApi\Client\Api\StateApiClient;
18
use Xabbuh\XApi\Client\Api\StatementsApiClient;
19
use Xabbuh\XApi\Client\Request\HandlerInterface;
20
use Xabbuh\XApi\Serializer\SerializerRegistryInterface;
21
22
/**
23
 * An Experience API client.
24
 *
25
 * @author Christian Flothmann <[email protected]>
26
 */
27
final class XApiClient implements XApiClientInterface
28
{
29
    /**
30
     * @var SerializerRegistryInterface
31
     */
32
    private $serializerRegistry;
33
34
    /**
35
     * @param HandlerInterface            $requestHandler     The HTTP request handler
36
     * @param SerializerRegistryInterface $serializerRegistry The serializer registry
37
     * @param string                      $version            The xAPI version
38
     */
39
    public function __construct(HandlerInterface $requestHandler, SerializerRegistryInterface $serializerRegistry, $version)
40
    {
41
        $this->requestHandler = $requestHandler;
0 ignored issues
show
Bug introduced by
The property requestHandler does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
        $this->serializerRegistry = $serializerRegistry;
43
        $this->version = $version;
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function getStatementsApiClient()
50
    {
51
        return new StatementsApiClient(
52
            $this->requestHandler,
53
            $this->version,
54
            $this->serializerRegistry->getStatementSerializer(),
55
            $this->serializerRegistry->getStatementResultSerializer(),
56
            $this->serializerRegistry->getActorSerializer()
57
        );
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function getStateApiClient()
64
    {
65
        return new StateApiClient(
66
            $this->requestHandler,
67
            $this->version,
68
            $this->serializerRegistry->getDocumentDataSerializer(),
69
            $this->serializerRegistry->getActorSerializer()
70
        );
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function getActivityProfileApiClient()
77
    {
78
        return new ActivityProfileApiClient(
79
            $this->requestHandler,
80
            $this->version,
81
            $this->serializerRegistry->getDocumentDataSerializer()
82
        );
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public function getAgentProfileApiClient()
89
    {
90
        return new AgentProfileApiClient(
91
            $this->requestHandler,
92
            $this->version,
93
            $this->serializerRegistry->getDocumentDataSerializer(),
94
            $this->serializerRegistry->getActorSerializer()
95
        );
96
    }
97
}
98