GlSpellCheckerError   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 97
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A merge() 0 15 4
A getSuggestions() 0 4 1
A getMessage() 0 4 1
A getOffset() 0 4 1
A getLength() 0 4 1
A getWord() 0 4 1
1
<?php
2
/**
3
 * Main Class
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  GLICER
8
 * @package   GlSpellChecker
9
 * @author    Emmanuel ROECKER
10
 * @author    Rym BOUCHAGOUR
11
 * @copyright 2015 GLICER
12
 * @license   MIT
13
 * @link      http://dev.glicer.com/
14
 *
15
 * Created : 04/05/15
16
 * File : GlSpellCheckerError.php
17
 *
18
 */
19
20
21
namespace GlSpellChecker;
22
23
/**
24
 * Class GlSpellCheckerError
25
 * @package GlSpellChecker
26
 */
27
class GlSpellCheckerError
28
{
29
    /**
30
     * @var array $suggs
31
     */
32
    private $suggs;
33
34
    /**
35
     * @var string
36
     */
37
    private $msg;
38
39
    /**
40
     * @var int
41
     */
42
    private $length;
43
44
    /**
45
     * @var int
46
     */
47
    private $offset;
48
49
    /**
50
     * @param string $msg
51
     * @param int    $offset
52
     * @param int    $length
53
     * @param string $word
54
     * @param array  $suggs
55
     */
56
    public function __construct($msg = '', $offset = null, $length = null, $word = '', $suggs = [])
57
    {
58
        $this->msg    = $msg;
59
        $this->offset = $offset;
60
        $this->length = $length;
61
        $this->word   = $word;
0 ignored issues
show
Bug introduced by
The property word 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...
62
        $this->suggs  = $suggs;
63
    }
64
65
    /**
66
     * @param GlSpellCheckerError $mergeerror
67
     */
68
    public function merge(GlSpellCheckerError $mergeerror) {
69
        $this->msg .= ' ' . $mergeerror->msg;
70
        $this->word .= ' ' . $mergeerror->word;
71
        if ($mergeerror->length > $this->length) {
72
            $this->length = $mergeerror->length;
73
        }
74
75
        if (isset($mergeerror->suggs)) {
76
            if (isset($this->suggs)) {
77
                $this->suggs = array_merge($this->suggs,$mergeerror->suggs);
78
            } else {
79
                $this->suggs = $mergeerror->suggs;
80
            }
81
        }
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function getSuggestions()
88
    {
89
        return $this->suggs;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getMessage()
96
    {
97
        return $this->msg;
98
    }
99
100
    /**
101
     * @return int
102
     */
103
    public function getOffset()
104
    {
105
        return $this->offset;
106
    }
107
108
    /**
109
     * @return int
110
     */
111
    public function getLength()
112
    {
113
        return $this->length;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getWord()
120
    {
121
        return $this->word;
122
    }
123
} 
124