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.
Completed
Pull Request — master (#68)
by
unknown
02:47
created

FileDictLoader::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.074

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 10
cts 12
cp 0.8333
rs 9.2
cc 4
eloc 8
nc 4
nop 2
crap 4.074
1
<?php
2
3
/*
4
 * This file is part of the overtrue/pinyin.
5
 *
6
 * (c) 2016 overtrue <[email protected]>
7
 */
8
9
namespace Overtrue\Pinyin;
10
11
use Closure;
12
13
/**
14
 * Dict File loader.
15
 */
16
class FileDictLoader implements DictLoaderInterface
17
{
18
    /**
19
     * Words segment name.
20
     *
21
     * @var string
22
     */
23
    protected $segmentName = 'words_%s';
24
25
    /**
26
     * Dict path.
27
     *
28
     * @var string
29
     */
30
    protected $path;
31
32
    /**
33
     * Segment files
34
     *
35
     * @var array
36
     */
37
    protected $segments = array();
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param string $path
43
     * @param boolean $preload
44
     */
45 9
    public function __construct($path, $preload = false)
46
    {
47 9
        $this->path = $path;
48 9
        for ($i = 0; $i < 100; ++$i) {
49 9
            $segment = $this->path . '/' . sprintf($this->segmentName, $i);
50 9
            if (file_exists($segment)) {
51 9
                $this->segments[$i] = array('segment' => $segment);
52 9
                if ($preload) {
53
                    $this->segments[$i]['dictionary'] = (array) include $segment;
54
                }
55 9
            }
56 9
        }
57 9
    }
58
59
    /**
60
     * Load dict.
61
     *
62
     * @param Closure $callback
63
     */
64 9
    public function map(Closure $callback)
65
    {
66 9
        foreach ($this->segments as $segment) {
67 9
            $dictionary = isset($segment['dictionary']) ? $segment['dictionary'] : (array) include $segment['segment'];
68 9
            $callback($dictionary);
69 9
        }
70
71 9
    }
72
73
    /**
74
     * Load surname dict.
75
     *
76
     * @param Closure $callback
77
     */
78 1
    public function mapSurname(Closure $callback)
79
    {
80 1
        $surnames = $this->path . '/surnames';
81
82 1
        if (file_exists($surnames)) {
83 1
            $dictionary = (array) include $surnames;
84 1
            $callback($dictionary);
85 1
        }
86 1
    }
87
}
88