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

Pinyin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 4
Bugs 4 Features 2
Metric Value
eloc 10
c 4
b 4
f 2
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A setLoader() 0 4 2
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
}