Completed
Branch master (431168)
by Gennady
09:40
created

HandlerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.7462

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 3
cts 7
cp 0.4286
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2.7462
1
<?php
2
/**
3
 * PHP APNS.
4
 *
5
 * @author Gennady Telegin <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Apns\Handler;
12
13
/**
14
 * Class HandlerFactory.
15
 */
16
class HandlerFactory
17
{
18
    /**
19
     * Choose preferable handler according available libraries and their capabilities.
20
     *
21
     * @return callable
22
     *
23
     * @throws \LogicException
24
     */
25 5
    public static function create()
26
    {
27 5
        if (class_exists('\GuzzleHttp\Client')) {
28 5
            return new GuzzleHandler();
29
        }
30
31
        throw new \LogicException(
32
            'PHP APNS library requires one of network libraries be installed: %s',
33
            implode(',', ['guzzlehttp/guzzle'])
34
        );
35
    }
36
}
37