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
Push — master ( 0b0f67...ed286c )
by Carlos
02:29
created

MemoryFileDictLoader::mapSurname()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
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
 * Memory Dict File loader.
15
 */
16
class MemoryFileDictLoader implements DictLoaderInterface
17
{
18
    /**
19
     * Words segment name.
20
     *
21
     * @var string
22
     */
23
    protected $segmentName = 'words_%s';
24
25
    /**
26
     * Segment files.
27
     *
28
     * @var array
29
     */
30
    protected $segments = array();
31
32
    /**
33
     * Surname cache.
34
     *
35
     * @var array
36
     */
37
    protected $surnames = array();
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param string $path
43
     */
44 9
    public function __construct($path)
45
    {
46 9
        $this->path = $path;
0 ignored issues
show
Bug introduced by
The property path does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
47
48 9 View Code Duplication
        for ($i = 0; $i < 100; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49 9
            $segment = $path.'/'.sprintf($this->segmentName, $i);
50
51 9
            if (file_exists($segment)) {
52 9
                $this->segments[] = (array) include $segment;
53 9
            }
54 9
        }
55 9
    }
56
57
    /**
58
     * Load dict.
59
     *
60
     * @param Closure $callback
61
     */
62 9
    public function map(Closure $callback)
63
    {
64 9
        foreach ($this->segments as $dictionary) {
65 9
            $callback($dictionary);
66 9
        }
67 9
    }
68
69
    /**
70
     * Load surname dict.
71
     *
72
     * @param Closure $callback
73
     */
74 1
    public function mapSurname(Closure $callback)
75
    {
76 1
        if (empty($this->surnames)) {
77 1
            $surnames = $this->path.'/surnames';
78
79 1
            if (file_exists($surnames)) {
80 1
                $this->surnames = (array) include $surnames;
81 1
            }
82 1
        }
83
84 1
        $callback($this->surnames);
85 1
    }
86
}
87