GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Pinyin   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 4 Features 0
Metric Value
eloc 20
dl 0
loc 62
rs 10
c 11
b 4
f 0
ccs 9
cts 9
cp 1
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A sentence() 0 3 1
A polyphones() 0 3 1
A nameAbbr() 0 3 1
A permalink() 0 7 2
A __callStatic() 0 9 2
A abbr() 0 9 3
A phrase() 0 3 1
A chars() 0 3 1
1
<?php
2
3
namespace Overtrue\Pinyin;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @method static Converter polyphonic()
9
 * @method static Converter surname()
10
 * @method static Converter noWords()
11
 * @method static Converter onlyHans()
12
 * @method static Converter noAlpha()
13
 * @method static Converter noNumber()
14
 * @method static Converter noPunctuation()
15
 * @method static Converter noTone()
16
 * @method static Converter useNumberTone()
17
 * @method static Converter yuToV()
18
 * @method static Converter yuToU()
19
 * @method static Converter withToneStyle(string $toneStyle = 'symbol')
20
 * @method static Collection convert(string $string, callable $beforeSplit = null)
21
 */
22
class Pinyin
23 1
{
24 1
    public static function name(string $name, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
25 1
    {
26
        return self::surname()->withToneStyle($toneStyle)->convert($name);
27
    }
28
29
    public static function phrase(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
30
    {
31
        return self::noPunctuation()->withToneStyle($toneStyle)->convert($string);
32
    }
33
34
    public static function sentence(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
35
    {
36
        return self::withToneStyle($toneStyle)->convert($string);
37
    }
38
39
    public static function polyphones(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
40
    {
41
        return self::polyphonic()->withToneStyle($toneStyle)->convert($string);
42
    }
43
44
    public static function chars(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
45
    {
46
        return self::onlyHans()->noWords()->withToneStyle($toneStyle)->convert($string);
47
    }
48
49
    public static function permalink(string $string, string $delimiter = '-'): string
50
    {
51
        if (!in_array($delimiter, ['_', '-', '.', ''], true)) {
52
            throw new InvalidArgumentException("Delimiter must be one of: '_', '-', '', '.'.");
53
        }
54
55
        return self::noPunctuation()->noTone()->convert($string)->join($delimiter);
56
    }
57
58
    public static function nameAbbr(string $string): Collection
59
    {
60
        return self::abbr($string, true);
61
    }
62 21
63
    public static function abbr(string $string, bool $asName = false): Collection
64 21
    {
65 21
        return self::noTone()
66
            ->noPunctuation()
67
            ->when($asName, fn ($c) => $c->surname())
68
            ->convert($string)
69
            ->map(function ($pinyin) {
70
                // 常用于电影名称入库索引处理,例如:《晚娘2012》-> WN2012
71
                return \is_numeric($pinyin) || preg_match('/\d{2,}/', $pinyin) ? $pinyin : \mb_substr($pinyin, 0, 1);
72
            });
73
    }
74
75 10
    public static function __callStatic(string $name, array $arguments)
76
    {
77 10
        $converter = Converter::make();
78
79 10
        if (\method_exists($converter, $name)) {
80
            return $converter->$name(...$arguments);
81
        }
82
83
        throw new InvalidArgumentException("Method {$name} does not exist.");
84
    }
85
}
86