Pinyin::setLoader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
cc 1
eloc 3
c 3
b 2
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * This file is part of the mucts/laravel-pinyin.
4
 *
5
 * This source file is subject to the MIT license that is bundled
6
 * with this source code in the file LICENSE.
7
 *
8
 * @version 1.0
9
 * @author herry<[email protected]>
10
 * @copyright © 2020 MuCTS.com All Rights Reserved.
11
 */
12
13
namespace MuCTS\Laravel\Pinyin;
14
15
use Exception;
16
use Illuminate\Support\Arr;
17
use MuCTS\Pinyin\Interfaces\DictLoader;
18
use MuCTS\Pinyin\Pinyin as Accessor;
19
20
/**
21
 * Class Pinyin
22
 * @package MuCTS\Laravel\Pinyin
23
 */
24
class Pinyin extends Accessor
25
{
26
    private string $default;
27
28
    public function __construct(?array $config = null)
29
    {
30
        $this->default = Arr::get($config, 'default');
31
        $this->alias = Arr::wrap(Arr::get($config, 'alias')) + $this->alias;
32
        parent::__construct(Arr::get($config, 'default'), Arr::get($config, 'data'));
33
    }
34
35
    /**
36
     * Loader setter
37
     *
38
     * @param DictLoader|string|null $loader
39
     * @return $this
40
     * @throws Exception
41
     */
42
    public function setLoader($loader = null)
43
    {
44
        $loader = $loader ?? $this->default;
45
        parent::setLoader($loader);
46
        return $this;
47
    }
48
}