Passed
Push — master ( 73e18a...f2cad5 )
by Eugene
03:10
created

PackerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 15
ccs 7
cts 8
cp 0.875
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 4
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[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
declare(strict_types=1);
13
14
namespace Tarantool\Client\Packer;
15
16
use MessagePack\BufferUnpacker;
17
use Tarantool\Client\Packer\Extension\DecimalExtension;
18
19
final class PackerFactory
20
{
21 2
    public static function create() : Packer
22
    {
23 2
        if (\class_exists(BufferUnpacker::class)) {
24 1
            return \extension_loaded('decimal')
25 1
                ? PurePacker::fromExtensions(new DecimalExtension())
26 1
                : new PurePacker();
27
        }
28
29 1
        if (\extension_loaded('msgpack')) {
30 1
            return new PeclPacker();
31
        }
32
33
        throw new \Error('None of the supported msgpack packages were found. To install one, run "composer require rybakit/msgpack".');
34
    }
35
}
36