VcrReplayFactory::createPlugin()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\HTTPlugModule\PluginFactory;
6
7
use Http\Client\Common\Plugin;
8
use Http\Client\Plugin\Vcr\ReplayPlugin;
9
use LogicException;
10
11
class VcrReplayFactory extends AbstractVcrFactory
12
{
13
    /**
14
     * @param array<string, mixed> $config
15
     */
16
    public function createPlugin(array $config = []): Plugin
17
    {
18
        if (! class_exists(ReplayPlugin::class)) {
19
            throw new LogicException('To use the vcr replay plugin you need to install the "php-http/vcr-plugin" package.');
20
        }
21
22
        $player = $this->getPlayer($config['player'] ?? 'filesystem', $config);
23
        $namingStrategy = $this->getNamingStrategy($config['naming_strategy'] ?? 'default', $config);
24
25
        return new ReplayPlugin($namingStrategy, $player, $config['throw'] ?? true);
26
    }
27
}
28