Completed
Push — master ( a7c0e3...a4c847 )
by
unknown
10s
created

ScriptApiVersionSetterDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 44
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isCompatible() 0 14 2
1
<?php
2
3
4
namespace eXpansion\Framework\GameManiaplanet\DataProviders;
5
6
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
7
use eXpansion\Framework\Core\Model\CompatibilityCheckDataProviderInterface;
8
use Maniaplanet\DedicatedServer\Connection;
9
use Maniaplanet\DedicatedServer\Structures\Map;
10
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
11
use Psr\Log\LoggerInterface;
12
13
14
/**
15
 * Class ScriptApiVersionSetterDataProvider
16
 *
17
 * @package eXpansion\Framework\GameManiaplanet\DataProviders;
18
 * @author  oliver de Cramer <[email protected]>
19
 */
20
class ScriptApiVersionSetterDataProvider extends AbstractDataProvider implements CompatibilityCheckDataProviderInterface
21
{
22
    /** @var Connection */
23
    protected $connection;
24
25
    /** @var LoggerInterface */
26
    protected $logger;
27
28
    /** @var string */
29
    protected $apiVersion;
30
31
    /**
32
     * ScriptApiVersionSetterDataProvider constructor.
33
     *
34
     * @param Connection      $connection
35
     * @param LoggerInterface $logger
36
     * @param string          $apiVersion
37
     */
38
    public function __construct(Connection $connection, LoggerInterface $logger, string $apiVersion = '2.4.0')
39
    {
40
        $this->connection = $connection;
41
        $this->logger = $logger;
42
        $this->apiVersion = $apiVersion;
43
    }
44
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function isCompatible(Map $map): bool
50
    {
51
        try {
52
            $this->connection->triggerModeScriptEvent("XmlRpc.SetApiVersion", [$this->apiVersion]);
53
            return true;
54
        } catch (FaultException $e) {
55
            $this->logger->warning(
56
                "Can't set script api version. This might be normal if you are using a custom script.",
57
                ['exception' => $e->getMessage(), 'trace' => $e->getTraceAsString()]
58
            );
59
        }
60
61
        return true;
62
    }
63
}