Passed
Push — master ( 0bb595...f816a0 )
by herry
03:40
created

Pinyin::setLoader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 2
c 1
b 1
f 1
nc 2
nop 1
dl 0
loc 4
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 Illuminate\Support\Arr;
16
use MuCTS\Pinyin\Pinyin as Accessor;
17
18
/**
19
 * Class Pinyin
20
 * @package MuCTS\Laravel\Pinyin
21
 */
22
class Pinyin extends Accessor
23
{
24
    private array $config;
25
26
    public function __construct(?array $config = null)
27
    {
28
        $this->config = $config ?? Arr::wrap(config('pinyin'));
29
        $path = $loader = null;
30
        if (is_array($this->config)) {
0 ignored issues
show
introduced by
The condition is_array($this->config) is always true.
Loading history...
31
            $path = Arr::get($this->config, 'data');
32
            $loader = Arr::get($this->config, 'default');
33
        }
34
        parent::__construct($loader, $path);
35
    }
36
37
    /**
38
     * Loader setter
39
     *
40
     * @param null $loader
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $loader is correct as it would always require null to be passed?
Loading history...
41
     * @return $this
42
     */
43
    public function setLoader($loader = null): self
44
    {
45
        $loader = is_string($loader) ? Arr::get($this->config, 'loaders.' . $loader, $loader) : $loader;
0 ignored issues
show
introduced by
The condition is_string($loader) is always false.
Loading history...
46
        return parent::setLoader($loader);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setLoader($loader) returns the type MuCTS\Pinyin\Pinyin which includes types incompatible with the type-hinted return MuCTS\Laravel\Pinyin\Pinyin.
Loading history...
47
    }
48
}