Completed
Push — PSR-11-2 ( a5ad88...7f5041 )
by Nikolaos
03:59
created

AdapterFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
rs 10
cc 1
nc 1
nop 1
crap 1.0156
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Phalcon\Logger;
15
16
use Phalcon\Factory\AbstractFactory;
17
use Phalcon\Factory\Exception as FactoryException;
18
use Phalcon\Logger\Adapter\AdapterInterface;
19
use Phalcon\Logger\Adapter\Noop;
20
use Phalcon\Logger\Adapter\Stream;
21
use Phalcon\Logger\Adapter\Syslog;
22
23
/**
24
 * Class AdapterFactory
25
 *
26
 * @package Phalcon\Logger
27
 */
28
class AdapterFactory extends AbstractFactory
29
{
30
    /**
31
     * AdapterFactory constructor.
32
     *
33
     * @param array $services
34
     */
35 2
    public function __construct(array $services = [])
36
    {
37 2
        $this->init($services);
38 2
    }
39
40
    /**
41
     * Create a new instance of the adapter
42
     *
43
     * @param string $name
44
     * @param string $fileName
45
     * @param array  $options
46
     *
47
     * @return AdapterInterface
48
     * @throws FactoryException
49
     */
50 2
    public function newInstance(
51
        string $name,
52
        string $fileName,
53
        array $options = []
54
    ): AdapterInterface {
55 2
        $this->checkService($name);
56
57 1
        $definition = $this->mapper[$name];
58
59 1
        return new $definition($fileName, $options);
60
    }
61
62
    /**
63
     * @return array
64
     */
65 2
    protected function getAdapters(): array
66
    {
67
        return [
68 2
            "noop"   => Noop::class,
69
            "stream" => Stream::class,
70
            "syslog" => Syslog::class,
71
        ];
72
    }
73
}
74